# HG changeset patch # User one # Date 1409421223 -32400 # Node ID 6f744149f030791daabd4fc2644f98deaf222639 # Parent 1905f2eb6f3b0dabff2ee4a04dabf45fa931c49d NodeEditor add getLog but edit is mystery bug diff -r 1905f2eb6f3b -r 6f744149f030 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java Wed Jul 30 22:09:33 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java Sun Aug 31 02:53:43 2014 +0900 @@ -11,6 +11,10 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; @@ -19,204 +23,259 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; -public class JungleBulletinBoard implements BulletinBoard -{ +public class JungleBulletinBoard implements + BulletinBoard { private final Jungle jungle; - - public JungleBulletinBoard() - { - jungle = new DefaultJungle(null,"hoge",new DefaultTreeEditor(new DefaultTraverser())); + + public JungleBulletinBoard() { + jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor( + new DefaultTraverser())); jungle.createNewTree("boards"); } - public Iterable getBoards() - { + public Iterable getBoards() { JungleTree tree = jungle.getTreeByName("boards"); Node node = tree.getRootNode(); Children chs = node.getChildren(); - - IterableConverter.Converter converter = new IterableConverter.Converter(){ + + IterableConverter.Converter converter = new IterableConverter.Converter() { public String conv(Node _b) { ByteBuffer e = _b.getAttributes().get("name"); return new String(e.array()); } }; - - return new IterableConverter(chs,converter); + + return new IterableConverter(chs, converter); } - public void createBoards(final String _name,final String _author,final String _initMessage,final String _editKey) - { - if(null == jungle.createNewTree(_name)){ + public void createBoards(final String _name, final String _author, + final String _initMessage, final String _editKey) { + if (null == jungle.createNewTree(_name)) { throw new IllegalStateException(); } - + JungleTree tree = jungle.getTreeByName("boards"); JungleTreeEditor editor = tree.getTreeEditor(); DefaultNodePath root = new DefaultNodePath(); - Either either = editor.addNewChildAt(root,0); - if(either.isA()){ + Either either = editor.addNewChildAt(root, 0); + if (either.isA()) { throw new IllegalStateException(); } editor = either.b(); - - either = editor.putAttribute(root.add(0),"name",ByteBuffer.wrap(_name.getBytes())); - if(either.isA()){ + + either = editor.putAttribute(root.add(0), "name", + ByteBuffer.wrap(_name.getBytes())); + if (either.isA()) { throw new IllegalStateException(); } editor = either.b(); - Either result = editor.success(); - if(result.isA()){ + Either result = editor.success(); + if (result.isA()) { throw new IllegalStateException(); } - + tree = jungle.getTreeByName(_name); editor = tree.getTreeEditor(); - either = editor.addNewChildAt(root,0); - if(either.isA()){ + either = editor.addNewChildAt(root, 0); + if (either.isA()) { throw new IllegalStateException(); } editor = either.b(); - - NodeEditor e = new NodeEditor(){ - public > Either edit(T _e){ - _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b(); - _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_initMessage.getBytes())).b(); - _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b(); + + NodeEditor e = new NodeEditor() { + + public > Either edit(T _e){ + _e = _e.getAttributes() + .put("author", ByteBuffer.wrap(_author.getBytes())).b(); + _e = _e.getAttributes() + .put("mes", ByteBuffer.wrap(_initMessage.getBytes())) + .b(); + _e = _e.getAttributes() + .put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); return DefaultEither.newB(_e); } + + public > Either edit(T _e) { + // TODO Auto-generated method stub + return null; + } + + public OperationLog getLog(){ + OperationLog op = new DefaultOperationLog(); + op.add( new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); + op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_initMessage.getBytes()))); + op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); + return op; + } + }; - - either = editor.edit(root.add(0),e); - if(either.isA()){ + + either = editor.edit(root.add(0), e); + if (either.isA()) { throw new IllegalStateException(); } editor = either.b(); editor.success(); } - public void createBoardMessage(final String _board,final String _author,final String _message,final String _editKey) - { + public void createBoardMessage(final String _board, final String _author, + final String _message, final String _editKey) { JungleTree tree = jungle.getTreeByName(_board); - if(tree == null){ + if (tree == null) { throw new IllegalStateException(); } - + JungleTreeEditor editor; - do{ + do { Node node = tree.getRootNode(); int size = node.getChildren().size(); DefaultNodePath path = new DefaultNodePath(); - + editor = tree.getTreeEditor(); - Either either = editor.addNewChildAt(path,size); - if(either.isA()){ + Either either = editor.addNewChildAt(path, + size); + if (either.isA()) { throw new IllegalStateException(); } editor = either.b(); - - NodeEditor e = new NodeEditor(){ - public > Either 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(); + + NodeEditor e = new NodeEditor() { + public > Either 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); } + + public > Either edit(T _e) { + // TODO Auto-generated method stub + return null; + } + + public OperationLog getLog(){ + OperationLog op = new DefaultOperationLog(); + op.add( new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); + op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_message.getBytes()))); + op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); + return op; + } + }; - + path = path.add(size); - either = editor.edit(path,e); - if(either.isA()){ + either = editor.edit(path, e); + if (either.isA()) { throw new IllegalStateException(); } editor = either.b(); - }while(editor.success().isA()); + } while (editor.success().isA()); } - public void editMessage(String _board,String _uuid,final String _author,final String _message,final String _editKey) - { + public void editMessage(String _board, String _uuid, final String _author, + final String _message, final String _editKey) { JungleTreeEditor editor = null; - do{ + do { DefaultNodePath path = new DefaultNodePath(); path = path.add(Integer.parseInt(_uuid)); - + JungleTree tree = jungle.getTreeByName(_board); editor = tree.getTreeEditor(); - NodeEditor e = new NodeEditor(){ - public > Either 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 > Either 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); + } + + public > Either edit(T _e) { + // TODO Auto-generated method stub + return null; + } + + public OperationLog getLog(){ + OperationLog op = new DefaultOperationLog(); + op.add( new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); + op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_message.getBytes()))); + op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); + return op; } }; - - Either either = editor.edit(path,e); - if(either.isA()){ + + Either either = editor.edit(path, e); + if (either.isA()) { throw new IllegalStateException(); } editor = either.b(); - }while(editor.success().isA()); + } while (editor.success().isA()); } - public Iterable getMessages(String _boardName) - { + public Iterable getMessages(String _boardName) { JungleTree tree = jungle.getTreeByName(_boardName); Node node = tree.getRootNode(); Children chs = node.getChildren(); - + final AtomicInteger counter = new AtomicInteger(0); - IterableConverter.Converter converter = new IterableConverter.Converter(){ + IterableConverter.Converter converter = new IterableConverter.Converter() { public BoardMessage conv(Node _b) { String uuid = Integer.toString(counter.get()); - String author = new String(_b.getAttributes().get("author").array()); - String message = new String(_b.getAttributes().get("mes").array()); + String author = new String(_b.getAttributes().get("author") + .array()); + String message = new String(_b.getAttributes().get("mes") + .array()); counter.incrementAndGet(); - return new BoardMessageImpl(author,message,uuid); + return new BoardMessageImpl(author, message, uuid); } }; - - return new IterableConverter(chs,converter); + + return new IterableConverter(chs, converter); } - - private static class BoardMessageImpl implements BoardMessage - { + + private static class BoardMessageImpl implements BoardMessage { private final String author; private final String message; private final String uuid; - - public BoardMessageImpl(String _author,String _message,String _uuid) - { + + public BoardMessageImpl(String _author, String _message, String _uuid) { author = _author; message = _message; uuid = _uuid; } - public String getAuthor() - { + public String getAuthor() { return author; } - public String getMessage() - { + public String getMessage() { return message; } - public String getUUID() - { + public String getUUID() { return uuid; } } - - public String sanitize( String str ) { - if(str==null) { - return str; - } - str = str.replaceAll("&" , "&" ); - str = str.replaceAll("<" , "<" ); - str = str.replaceAll(">" , ">" ); - str = str.replaceAll("\"", """); - str = str.replaceAll("'" , "'" ); - return str; - } + + public String sanitize(String str) { + if (str == null) { + return str; + } + str = str.replaceAll("&", "&"); + str = str.replaceAll("<", "<"); + str = str.replaceAll(">", ">"); + str = str.replaceAll("\"", """); + str = str.replaceAll("'", "'"); + return str; + } }