Mercurial > hg > Members > shoshi > jungle > bulletinboard
changeset 17:d253ca4d92ca
fit jungle core
author | one |
---|---|
date | Sun, 31 Aug 2014 07:33:35 +0900 |
parents | 6f744149f030 |
children | 1515eeb54784 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java |
diffstat | 1 files changed, 45 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java Sun Aug 31 02:53:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java Sun Aug 31 07:33:35 2014 +0900 @@ -8,22 +8,21 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; -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.transaction.DefaultTreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; 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<T extends Node> implements +public class JungleBulletinBoard<T extends TreeNode> implements BulletinBoard { private final Jungle jungle; @@ -35,17 +34,17 @@ public Iterable<String> getBoards() { JungleTree tree = jungle.getTreeByName("boards"); - Node node = tree.getRootNode(); - Children<Node> chs = node.getChildren(); + TreeNode node = tree.getRootNode(); + Children<TreeNode> chs = node.getChildren(); - IterableConverter.Converter<String, Node> converter = new IterableConverter.Converter<String, Node>() { - public String conv(Node _b) { + IterableConverter.Converter<String, TreeNode> converter = new IterableConverter.Converter<String, TreeNode>() { + public String conv(TreeNode _b) { ByteBuffer e = _b.getAttributes().get("name"); return new String(e.array()); } }; - return new IterableConverter<String, Node>(chs, converter); + return new IterableConverter<String, TreeNode>(chs, converter); } public void createBoards(final String _name, final String _author, @@ -84,30 +83,23 @@ NodeEditor e = new NodeEditor() { - public <T extends TreeNode<T>> Either<Error,T> 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 <T extends EditableNode<T>> Either<Error, T> edit(T _e) { - // TODO Auto-generated method stub - return null; + public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { + TreeNode node = new DefaultTreeNode(); + node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + node = node.getAttributes().put("mes", ByteBuffer.wrap(_initMessage.getBytes())).b(); + node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + System.out.println(node.getAttributes().get("mes")); + return DefaultEither.newB(node); } 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()))); + op = op.add( new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); + op = op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_initMessage.getBytes()))); + op = op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); return op; } - + }; either = editor.edit(root.add(0), e); @@ -127,7 +119,7 @@ JungleTreeEditor editor; do { - Node node = tree.getRootNode(); + TreeNode node = tree.getRootNode(); int size = node.getChildren().size(); DefaultNodePath path = new DefaultNodePath(); @@ -140,29 +132,19 @@ editor = either.b(); NodeEditor e = new NodeEditor() { - public <T extends TreeNode<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); - } - - public <T extends EditableNode<T>> Either<Error, T> edit(T _e) { - // TODO Auto-generated method stub - return null; + public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { + TreeNode node = new DefaultTreeNode(); + node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + node = node.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + return DefaultEither.newB(node); } 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()))); + op = op.add( new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); + op = op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_message.getBytes()))); + op = op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); return op; } @@ -187,31 +169,24 @@ JungleTree tree = jungle.getTreeByName(_board); editor = tree.getTreeEditor(); NodeEditor e = new NodeEditor() { - public <T extends TreeNode<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); + + public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { + TreeNode node = new DefaultTreeNode(); + node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + node = node.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + return DefaultEither.newB(node); } - public <T extends EditableNode<T>> Either<Error, T> 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()))); + op = op.add( new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); + op = op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_message.getBytes()))); + op = op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); return op; } + + }; Either<Error, JungleTreeEditor> either = editor.edit(path, e); @@ -224,12 +199,12 @@ public Iterable<BoardMessage> getMessages(String _boardName) { JungleTree tree = jungle.getTreeByName(_boardName); - Node node = tree.getRootNode(); - Children<Node> chs = node.getChildren(); + TreeNode node = tree.getRootNode(); + Children<TreeNode> chs = node.getChildren(); final AtomicInteger counter = new AtomicInteger(0); - IterableConverter.Converter<BoardMessage, Node> converter = new IterableConverter.Converter<BoardMessage, Node>() { - public BoardMessage conv(Node _b) { + IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() { + public BoardMessage conv(TreeNode _b) { String uuid = Integer.toString(counter.get()); String author = new String(_b.getAttributes().get("author") .array()); @@ -240,7 +215,7 @@ } }; - return new IterableConverter<BoardMessage, Node>(chs, converter); + return new IterableConverter<BoardMessage, TreeNode>(chs, converter); } private static class BoardMessageImpl implements BoardMessage {