Mercurial > hg > Members > shoshi > jungle > bulletinboard
changeset 2:5f80e6019970
modified junglebulletinboard
author | Shoshi TAMAKI |
---|---|
date | Thu, 28 Feb 2013 16:15:40 +0900 |
parents | babb46537b8a |
children | e82fef2df8d6 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java |
diffstat | 2 files changed, 48 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java Sat Feb 09 19:43:46 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java Thu Feb 28 16:15:40 2013 +0900 @@ -15,10 +15,10 @@ public static void main( String[] args ) throws Exception { BulletinBoard cassaBBS = null; - if(args[0].equals("cassandra")){ + if(args.length == 0){ + cassaBBS = new JungleBulletinBoard(); + }else{ cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2"); - }else if(args[0].equals("jungle")){ - cassaBBS = new JungleBulletinBoard(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java Sat Feb 09 19:43:46 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java Thu Feb 28 16:15:40 2013 +0900 @@ -101,57 +101,61 @@ throw new IllegalStateException(); } - Node node = tree.getRootNode(); - int size = node.getChildren().size(); - DefaultNodePath path = new DefaultNodePath(); + JungleTreeEditor editor; + do{ + Node node = tree.getRootNode(); + int size = node.getChildren().size(); + DefaultNodePath path = new DefaultNodePath(); - JungleTreeEditor editor = tree.getTreeEditor(); - Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path,size); - if(either.isA()){ - throw new IllegalStateException(); - } - editor = either.b(); + editor = tree.getTreeEditor(); + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path,size); + if(either.isA()){ + throw new IllegalStateException(); + } + editor = either.b(); - NodeEditor e = new NodeEditor(){ - public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ - _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); - _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b(); - _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); - return DefaultEither.newB(_e); + NodeEditor e = new NodeEditor(){ + public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ + _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); + _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b(); + _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); + return DefaultEither.newB(_e); + } + }; + + path = path.add(size); + either = editor.edit(path,e); + if(either.isA()){ + throw new IllegalStateException(); } - }; - - path = path.add(size); - either = editor.edit(path,e); - if(either.isA()){ - throw new IllegalStateException(); - } - editor = either.b(); - editor.success(); + editor = either.b(); + }while(editor.success().isA()); } public void editMessage(String _board,String _uuid,final String _author,final String _message,final String _editKey) { - DefaultNodePath path = new DefaultNodePath(); - path = path.add(Integer.parseInt(_uuid)); + JungleTreeEditor editor = null; + do{ + DefaultNodePath path = new DefaultNodePath(); + path = path.add(Integer.parseInt(_uuid)); - JungleTree tree = jungle.getTreeByName(_board); - JungleTreeEditor editor = tree.getTreeEditor(); - NodeEditor e = new NodeEditor(){ - public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ - _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); - _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b(); - _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); + JungleTree tree = jungle.getTreeByName(_board); + editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor(){ + public <T extends EditableNode<T>> Either<Error, T> edit(T _e){ + _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); + _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b(); + _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); return DefaultEither.newB(_e); + } + }; + + Either<Error,JungleTreeEditor> either = editor.edit(path,e); + if(either.isA()){ + throw new IllegalStateException(); } - }; - - Either<Error,JungleTreeEditor> either = editor.edit(path,e); - if(either.isA()){ - throw new IllegalStateException(); - } - editor = either.b(); - editor.success(); + editor = either.b(); + }while(editor.success().isA()); } public Iterable<BoardMessage> getMessages(String _boardName)