Mercurial > hg > Database > jungle-network
view src/jungle/test/alice/DoubleJungleManager.java @ 58:4851344e120e
fix bug LogUpdateCodeSegment and ChildLogCheckCodeSegment
author | one |
---|---|
date | Mon, 15 Jul 2013 10:13:34 +0900 |
parents | src/test/alice/jungle/codesegment/DoubleJungleManager.java@686057add8a4 |
children |
line wrap: on
line source
package jungle.test.alice; import java.nio.ByteBuffer; import alice.jungle.core.NetworkDefaultJungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; 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.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; public class DoubleJungleManager { static Jungle jungle1 = new NetworkDefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()), ""); static Jungle jungle2 = new NetworkDefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()), ""); public DoubleJungleManager() { } public Jungle getJungle1() { return jungle1; } public Jungle getJungle2() { return jungle2; } public Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,TreeOperationLog _log) { JungleTreeEditor editor = _editor; Either<Error, JungleTreeEditor> either = null; for (TreeOperation op : _log) { either = _edit(editor, op); if(either.isA()) { return either; } editor = either.b(); } return either; } private Either<Error, JungleTreeEditor> _edit(JungleTreeEditor editor, TreeOperation op) { NodePath path = op.getNodePath(); NodeOperation nodeOp = op.getNodeOperation(); Command c = nodeOp.getCommand(); String key = ""; switch (c) { case PUT_ATTRIBUTE: key = nodeOp.getKey(); ByteBuffer value = nodeOp.getValue(); return editor.putAttribute(path, key, value); case DELETE_ATTRIBUTE: key = nodeOp.getKey(); return editor.deleteAttribute(path, key); case APPEND_CHILD: return editor.addNewChildAt(path, 0); case DELETE_CHILD: return editor.deleteChildAt(path, 0); } return null; } }