Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 249:803ab4479b7e Implementation_of_communication
add filtering key iterator
line wrap: on
line diff
--- a/build.gradle Wed Jul 06 01:48:13 2016 +0900 +++ b/build.gradle Mon Nov 07 03:40:57 2016 +0900 @@ -6,43 +6,40 @@ version = '1.0' repositories { - mavenCentral() + mavenCentral() maven { url "http://eaio.com/maven2" } - maven { url "http://repo.maven.apache.org/maven2" } + maven { url "http://repo.maven.apache.org/maven2" } } dependencies { - compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.0.0' + compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.0.0' compile "commons-collections:commons-collections:3.2.1" compile "org.apache.maven.surefire:surefire-junit4:2.13" compile "com.google.guava:guava:12.0" compile fileTree(dir: 'lib', include: '*.jar') - compile "junit:junit:4.7" - compile group: 'org.eclipse.jetty', name: 'jetty-server', version:'9.1.1.v20140108' + compile group: 'junit', name: 'junit', version: '4.11' + compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.2.1.v20140609' compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version:'9.2.1.v20140609' compile group: 'org.hectorclient', name: 'hector-core', version:'1.1-2' compile group: 'com.github.stephenc.eaio-uuid', name: 'uuid', version:'3.3.0' - compile(group: 'org.apache.cassandra', name: 'cassandra-all', version:'1.2.1') { - exclude(module: 'slf4j-log4j12') - exclude(module: 'log4j') - } + compile group: 'org.apache.cassandra', name: 'cassandra-all', version: '3.9' } jar { - manifest { - attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version - } - from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } - archiveName = 'jungle-core.jar' + manifest { + attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version + } + from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } + archiveName = 'jungle-core.jar' } uploadArchives { - repositories { - flatDir { - dirs '.' - } + repositories { + flatDir { + dirs '.' } + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/DefaultJungle.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/DefaultJungle.java Mon Nov 07 03:40:57 2016 +0900 @@ -9,6 +9,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; @@ -58,6 +59,12 @@ @Override public JungleTree createNewTree(final String name) { + return createNewTree(name,new DefaultTreeNode()); + } + + @Override + public JungleTree createNewTree(final String name, TreeNode rootNode) { + ChangeList list = new ChangeList() { @Override public Iterator<TreeOperation> iterator() { @@ -81,9 +88,8 @@ } }; - DefaultTreeNode root = new DefaultTreeNode(); - InterfaceTraverser traverser = new InterfaceTraverser(root, true); - TreeContext tc = new DefaultTreeContext(root, null, list, uuid, name, 0, traverser); + InterfaceTraverser traverser = new InterfaceTraverser(rootNode, true); + TreeContext tc = new DefaultTreeContext(rootNode, null, list, uuid, name, 0, traverser); JungleTree newTree = new DefaultJungleTree(tc, uuid, journal.getWriter(), editor); if (trees.putIfAbsent(name, newTree) != null) { return null;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/Jungle.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/Jungle.java Mon Nov 07 03:40:57 2016 +0900 @@ -1,11 +1,14 @@ package jp.ac.u_ryukyu.ie.cr.jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; + import java.util.Iterator; public interface Jungle { public JungleTree getTreeByName(String name); public JungleTree createNewTree(String name); - public Iterator<String> getTreeNames(); + public JungleTree createNewTree(String name , TreeNode rootNode); + public Iterator<String> getTreeNames(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/JungleTreeEditor.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/JungleTreeEditor.java Mon Nov 07 03:40:57 2016 +0900 @@ -1,23 +1,30 @@ package jp.ac.u_ryukyu.ie.cr.jungle; import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; import java.nio.ByteBuffer; -public interface JungleTreeEditor -{ - - public Either<Error,JungleTreeEditor> addNewChildAt(NodePath path,int pos); - public Either<Error,JungleTreeEditor> deleteChildAt(NodePath path,int pos); - public Either<Error,JungleTreeEditor> putAttribute(NodePath path,String key,ByteBuffer value); - public Either<Error,JungleTreeEditor> deleteAttribute(NodePath path,String key); +public interface JungleTreeEditor { + + public Either<Error, JungleTreeEditor> addNewChildAt(NodePath path, int pos); + + public Either<Error, JungleTreeEditor> deleteChildAt(NodePath path, int pos); + + public Either<Error, JungleTreeEditor> putAttribute(NodePath path, String key, ByteBuffer value); + + public Either<Error, JungleTreeEditor> deleteAttribute(NodePath path, String key); + public Either<Error, JungleTreeEditor> replaceNewRootNode(); - public Either<Error,JungleTreeEditor> edit(NodePath path,NodeEditor editor); - public Either<Error,JungleTreeEditor> success(); - public Either<Error,JungleTreeEditor> flushSuccess(); + + public Either<Error, JungleTreeEditor> edit(NodePath path, NodeEditor editor); + + public Either<Error, JungleTreeEditor> success(); + public Either<Error, JungleTreeEditor> flushSuccess(); + public Either<Error, JungleTreeEditor> moveChild(DefaultNodePath path,int childNum ,String move); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/benchMark/Data/ListBenchMark.java Mon Nov 07 03:40:57 2016 +0900 @@ -0,0 +1,27 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.benchMark.Data; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.differentialList.DifferentialList; +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; + + +public class ListBenchMark { + public static void main(String args[]) { + List<Integer> list = new List<>(); + DifferentialList<Integer> dfList = new DifferentialList<>(); + + Long t1 = System.currentTimeMillis(); + for (int i = 0; i < 10000; i++) { + list = list.addLast(i); + } + Long t2 = System.currentTimeMillis(); + + System.out.println("list add time = " + (t2 - t1)); + + t1 = System.currentTimeMillis(); + for (int i = 0; i < 10000; i++) { + dfList = dfList.addLast(i); + } + t2 = System.currentTimeMillis(); + System.out.println("dflist add time = " + (t2 - t1)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/differentialList/DifferentialHeadNode.java Mon Nov 07 03:40:57 2016 +0900 @@ -0,0 +1,36 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.data.differentialList; + + + +public class DifferentialHeadNode<T> implements Node<T> { + private final Node<T> next; + private final Node<T> last; + + public DifferentialHeadNode() { + this.next = new DifferentialNode<T>(); + this.last = this.next; + } + + public DifferentialHeadNode(Node<T> next, Node<T> last) { + this.next = next; + this.last = last; + } + + @Override + public Node<T> addLast(T attribute) { + return last.addLast(attribute); + } + + @Override + public T index(int index, Node<T> last, int nodeCount) { + if (next == this.last) + return null; + return next.index(index,this.last, nodeCount); + } + + @Override + public Node<T> getNext() { + return next; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/differentialList/DifferentialList.java Mon Nov 07 03:40:57 2016 +0900 @@ -0,0 +1,39 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.data.differentialList; + + +public class DifferentialList<T> { + + final Node<T> head; + private final int revision; + + public DifferentialList() { + head = new DifferentialHeadNode<T>(); + this.revision = 0; + } + + + @SafeVarargs + public DifferentialList(T... attributes) { + head = new DifferentialHeadNode<>(); + for (T attribute : attributes) { + head.addLast(attribute); + } + this.revision = 0; + } + + private DifferentialList(Node<T> headNode, int revision) { + this.head = headNode; + this.revision = revision + 1; + } + + public DifferentialList<T> addLast(T attribute) { + Node<T> newLastNode = head.addLast(attribute); + Node<T> newNext = head.getNext(); + Node<T> newHead = new DifferentialHeadNode<T>(newNext, newLastNode); + return new DifferentialList<T>(newHead, revision); + } + + public T index(int index) { + return head.index(index,null, 0); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/differentialList/DifferentialNode.java Mon Nov 07 03:40:57 2016 +0900 @@ -0,0 +1,50 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.data.differentialList; + + +public class DifferentialNode<T> implements Node<T> { + + private Node<T> next; + private T attribute; + + public DifferentialNode() { + + } + + public DifferentialNode(T attribute) { + this.attribute = attribute; + } + + public DifferentialNode(T attribute, Node<T> next) { + this.next = next; + this.attribute = attribute; + } + + public Node<T> addLast(T attribute) { + if (!hasNext()) return next.addLast(attribute); + else { + this.attribute = attribute; + this.next = new DifferentialNode<>(); + return this.next; + } + } + + private boolean hasNext() { + return this.next == null; + } + + @Override + public Node<T> getNext() { + return this.next; + } + + @Override + public T index(int index, Node<T> last, int nodeCount) { + if (index == nodeCount) + return attribute; + if (next == last) + return null; + nodeCount++; + return next.index(index,last,nodeCount); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/differentialList/Node.java Mon Nov 07 03:40:57 2016 +0900 @@ -0,0 +1,7 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.data.differentialList; + +public interface Node<T> { + Node<T> addLast(T attribute); + Node<T> getNext(); + T index(int index, Node<T> last, int nodeCount); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/list/List.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/list/List.java Mon Nov 07 03:40:57 2016 +0900 @@ -4,15 +4,13 @@ import java.util.Stack; - public class List<T> implements Iterable<T> { - final private Node<T> head; + final protected Node<T> head; public List() { this.head = new headNode<>(); } - @SafeVarargs public List(T... attributes) { List<T> list = new List<>(); @@ -20,20 +18,21 @@ list = list.addLast(attribute); } this.head = list.getHead(); + } - private List(Node<T> head) { + protected List(Node<T> head) { this.head = head; } + public Node<T> getHead() { return head; } public List<T> add(int num, T attribute) { Node<T> newHead = head.add(0, num, attribute); - if (newHead == null) - return this; + if (newHead == null) return this; return new List<>(newHead); } @@ -47,8 +46,7 @@ int count = 0; Node<T> currentNode = head.getNext(); while (currentNode != null) { - if (count == num) - return currentNode.getAttribute(); + if (count == num) return currentNode.getAttribute(); currentNode = currentNode.getNext(); count++; } @@ -97,15 +95,13 @@ public List<T> delete(int num) { Node<T> newNode = head.delete(0, num); - if (newNode == null) - return this; + if (newNode == null) return this; return new List<>(newNode); } public List<T> replace(int num, T attribute) { Node<T> newHead = head.replaceNode(0, num, attribute); - if (newHead == null) - return this; + if (newHead == null) return this; return new List<>(newHead); } @@ -135,10 +131,8 @@ Iterator<T> iterator = iterator(); while (true) { pathString += iterator.next(); - if (iterator.hasNext()) - pathString += ","; - else - break; + if (iterator.hasNext()) pathString += ","; + else break; } pathString += ">"; return pathString;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/list/headNode.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/list/headNode.java Mon Nov 07 03:40:57 2016 +0900 @@ -8,7 +8,7 @@ this.next = new TailNode<>(); } - public headNode(Node<T> next) { + private headNode(Node<T> next) { this.next = next; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/Query.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/Query.java Mon Nov 07 03:40:57 2016 +0900 @@ -3,5 +3,5 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; public interface Query { - boolean condition(TreeNode _node); + boolean condition(TreeNode node); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/Command.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/Command.java Mon Nov 07 03:40:57 2016 +0900 @@ -6,5 +6,6 @@ DELETE_CHILD, PUT_ATTRIBUTE, DELETE_ATTRIBUTE, - REPLACE_ROOT; + REPLACE_ROOT, + MOVE_CHILD; } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/DefaultNodePath.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/DefaultNodePath.java Mon Nov 07 03:40:57 2016 +0900 @@ -20,6 +20,17 @@ path = new List<Integer>().addLast(-1); } + public DefaultNodePath (String nodePath) { + List<Integer> _path = new List<>(-1); + String[] nums = nodePath.split(","); + for (String num : nums) { + if (num.equals("-1")) + continue; + _path = _path.addLast(Integer.parseInt(num)); + } + this.path = _path; + } + private DefaultNodePath(List<Integer> path) { this.path = path; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/TreeNodeAttributes.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/TreeNodeAttributes.java Mon Nov 07 03:40:57 2016 +0900 @@ -14,4 +14,6 @@ public Either<jp.ac.u_ryukyu.ie.cr.jungle.util.Error,TreeNode> put(String key,ByteBuffer value); public TreeMap<String,ByteBuffer> getAttributesAsRawMap(); public Iterator<String> getKeys(); + public boolean contain(String key); + public Iterator<String> getFilteringKey(java.util.List<String> filter); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/TreeNodeChildren.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/TreeNodeChildren.java Mon Nov 07 03:40:57 2016 +0900 @@ -11,5 +11,6 @@ public Either<jp.ac.u_ryukyu.ie.cr.jungle.util.Error,TreeNode> deleteChildAt(int pos); public Either<Error,TreeNode> addNewChildAt(int pos,TreeNode newChild); public Either<Error,TreeNode> replaceNode(int pos,TreeNode replacement); + Either<Error,TreeNode> moveChild(int pos, String move); public List<TreeNode> getChildrenAsRawList(); } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/logger/DefaultTreeOperationLog.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/logger/DefaultTreeOperationLog.java Mon Nov 07 03:40:57 2016 +0900 @@ -1,11 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger; + import com.google.common.collect.Iterables; +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DefaultTreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import java.util.Iterator;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/logger/LoggingChildren.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/logger/LoggingChildren.java Mon Nov 07 03:40:57 2016 +0900 @@ -2,13 +2,14 @@ import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.AppendChildAtOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.ChildMoveOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DeleteChildAtOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; public class LoggingChildren { @@ -52,6 +53,12 @@ return edit(deleteChildAt); } + + public Either<Error,LoggingNode> moveChild(String move, int childNum) { + NodeOperation moveChild = new ChildMoveOperation(move,childNum); + return edit(moveChild); + } + public Either<Error,LoggingNode> at(int _pos) { Children children = wrap.getChildren();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/NodePoint.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/NodePoint.java Mon Nov 07 03:40:57 2016 +0900 @@ -6,6 +6,7 @@ private int y = 0; private int width = 200; private int height = 200; + private int headerSize = 50; public int getX() { @@ -39,4 +40,8 @@ public void setHeight(int height) { this.height = height; } + + public int getHeaderSize() { + return headerSize; + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/OmniGraffleCreater.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/OmniGraffleCreater.java Mon Nov 07 03:40:57 2016 +0900 @@ -143,11 +143,8 @@ int graphicsId = 1; for (TreeNode node : treeMap.keySet()) { - Pair<Element, Integer> squarePair = createSquare(node, treeMap, graphicsId); - graphicsId = squarePair.right(); - graphicsArray.appendChild(squarePair.left()); - - Pair<LinkedList<Element>, Integer> linePair = createLine(node, treeMap, graphicsId); + graphicsId = drawingSquare(graphicsArray,node, treeMap, graphicsId); + Pair<LinkedList<Element>, Integer> linePair = drawingLine(node, treeMap, graphicsId); graphicsId = linePair.right(); for (Element lineDict : linePair.left()) { @@ -158,7 +155,27 @@ } - private Pair<LinkedList<Element>, Integer> createLine(TreeNode node, TreeMap<TreeNode, NodePoint> treeMap, int graphicsId) { + private Integer drawingSquare(Element graphicsArray, TreeNode node, TreeMap<TreeNode, NodePoint> treeMap, int graphicsId) throws UnsupportedEncodingException { + NodePoint np = treeMap.get(node); + int x = np.getX(); + int y = np.getY(); + int headerSize = np.getHeaderSize(); + int width = np.getWidth(); + int height = np.getHeight(); + + String text = getText(node); + graphicsId = drawingNode(graphicsArray,node, x, y + headerSize, height - headerSize, width, graphicsId,text);//ノードの本体を描画する + + text = "{\\rtf1\\ansi\\ansicpg932\\cocoartf1343\\cocoasubrtf140\n" + + "\\cocoascreenfonts1{\\fonttbl\\f0\\fnil\\fcharset128 HiraKakuProN-W3;}\n" + + "{\\colortbl;\\red255\\green255\\blue255;}\n" + + "\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\pardirnatural\\qc\n" + + "\n" + "\\f0\\fs24" + " \\cf0 " + convertSjis("TreeNode") + "}"; + graphicsId = drawingNode(graphicsArray,node, x, y, headerSize, width, graphicsId,text);//ノードのheader部分の描画 + return graphicsId; + } + + private Pair<LinkedList<Element>, Integer> drawingLine(TreeNode node, TreeMap<TreeNode, NodePoint> treeMap, int graphicsId) { TreeNodeChildren children = node.getChildren(); NodePoint currentNodePoint = treeMap.get(node); int startLineX = currentNodePoint.getX() + (currentNodePoint.getWidth() / 2); @@ -212,23 +229,18 @@ return new Pair<>(lineGraphicsList,graphicsId); } - private Pair<Element, Integer> createSquare(TreeNode node, TreeMap<TreeNode, NodePoint> treeMap, int graphicsId) throws UnsupportedEncodingException { + private Integer drawingNode(Element graphicsArray, TreeNode node, int x, int y, int height, int width, int graphicsId,String text) throws UnsupportedEncodingException { - NodePoint np = treeMap.get(node); Element graphicsDict = createElement("dict"); + graphicsArray.appendChild(graphicsDict); graphicsDict.appendChild(createElement("key", "Bounds")); - int x = np.getX(); - int y = np.getY(); - //キャンパスサイズを設定する、一番大きいX,Yの値を探す if (x > CanvasSize_X) CanvasSize_X = x; if (x > CanvasSize_Y) CanvasSize_Y = y; - int height = np.getHeight(); - int width = np.getWidth(); String squareCoordinate = "{{" + x + "," + y + "},{" + width + "," + height + "}}"; graphicsDict.appendChild(createElement("string", squareCoordinate)); graphicsDict.appendChild(createElement("key", "Class")); @@ -270,11 +282,10 @@ Element textDict = createElement("dict"); graphicsDict.appendChild(textDict); textDict.appendChild(createElement("key", "Text")); - String text = getText(node); textDict.appendChild(createElement("string", text)); textDict.appendChild(createElement("key", "VerticalPad")); textDict.appendChild(createElement("integer", "0")); - return new Pair<>(graphicsDict, graphicsId + 1); + return graphicsId + 1; } private String getText(TreeNode node) throws UnsupportedEncodingException {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/operations/ChildMoveOperation.java Mon Nov 07 03:40:57 2016 +0900 @@ -0,0 +1,50 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.store.operations; + +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; + +import java.nio.ByteBuffer; + +public class ChildMoveOperation implements NodeOperation +{ + private final int pos; + private final String move; //上下どっちに移動するか 現状getKeyで取得可能 + + public ChildMoveOperation(String move, int pos) + { + this.move = move; + this.pos = pos; + } + + @Override + public Command getCommand() + { + return Command.MOVE_CHILD; + } + + @Override + public Either<Error, TreeNode> invoke(TreeNode _target) + { + return _target.getChildren().moveChild(pos,move); + } + + @Override + public int getPosition() + { + return pos; + } + + @Override + public String getKey() + { + return move; + } + + @Override + public ByteBuffer getValue() + { + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/trasnformer/MoveChild.java Mon Nov 07 03:40:57 2016 +0900 @@ -0,0 +1,45 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; + +public class MoveChild implements NodeEditor +{ + private final String move; + private final int childNum; + public MoveChild(String move, int childNum) + { + this.childNum = childNum; + this.move = move; + } + + public Either<Error,LoggingNode> _edit(LoggingNode logNode) + { + Either<Error,LoggingNode> either = logNode.getChildren().moveChild(move, childNum); + if(either.isA()){ + // error + return either; + } + return DefaultEither.newB(either.b()); + } + + @Override + public Either<Error, LoggingNode> edit(TreeNode _e) { + LoggingNode logNode = wrap(_e); + return _edit(logNode); + } + + public LoggingNode wrap(TreeNode node) { + return new LoggingNode(node); + } + + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/DefaultJungleTreeEditor.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/DefaultJungleTreeEditor.java Mon Nov 07 03:40:57 2016 +0900 @@ -26,7 +26,6 @@ private final TreeNode root; private final TreeEditor editor; private final TreeOperationLog log; - public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor) { @@ -105,6 +104,13 @@ } @Override + public Either<Error, JungleTreeEditor> moveChild(DefaultNodePath path,int childNum, String move) { + MoveChild movechild = new MoveChild(move, childNum); + return _edit(path,movechild); + } + + + @Override public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) { return _edit(_path,_editor); @@ -129,5 +135,4 @@ return success(); } - }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/DefaultTreeNodeAttribute.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/DefaultTreeNodeAttribute.java Mon Nov 07 03:40:57 2016 +0900 @@ -60,8 +60,11 @@ return null; } Optional<ByteBuffer> op = attrs.get(_key); - if (op.isPresent()) - return op.get(); + if (op.isPresent()) { + ByteBuffer b = op.get(); + b.position(0); + return b; + } return null; } @@ -77,4 +80,41 @@ public Iterator<String> getKeys() { return attrs.keys(); } + + @Override + public Iterator<String> getFilteringKey(java.util.List<String> filter) { + + return new Iterator<String>() { + private Iterator<String> keys = attrs.keys(); + private String next = init(); + + private String init() { + while (keys.hasNext()) { + String key = keys.next(); + if (filter.contains(key)) + continue; + return key; + } + return null; + } + + @Override + public boolean hasNext() { + return next != null; + } + + @Override + public String next() { + String tmp = next; + next = init(); + return tmp; + } + }; + } + + + @Override + public boolean contain(String key) { + return attrs.get(key) != null; + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/DefaultTreeNodeChildren.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/DefaultTreeNodeChildren.java Mon Nov 07 03:40:57 2016 +0900 @@ -2,6 +2,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditorError; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultError; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; @@ -84,6 +85,24 @@ } @Override + public Either<Error, TreeNode> moveChild(int pos, String move) { + int size = children.length(); + TreeNode child = children.index(pos); + List<TreeNode> newChildren; + if (move.equals("up") && pos != 0) { + children = children.delete(pos); + newChildren = children.add((pos - 1), child); + } else if (move.equals("down") && pos < size - 1) { //sizeは0から始まるため -1する + children = children.delete(pos); + newChildren = children.add((pos + 1), child); + } else { + return DefaultEither.newA(new DefaultError()); + } + TreeNode newNode = new DefaultTreeNode(newChildren, attrs); + return DefaultEither.newB(newNode); + } + + @Override public Either<Error, TreeNode> at(int _pos) { if (children.length() < _pos + 1) { return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/core/NetworkDefaultJungle.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/core/NetworkDefaultJungle.java Mon Nov 07 03:40:57 2016 +0900 @@ -41,6 +41,11 @@ @Override public JungleTree createNewTree(final String name) { + return createNewTree(name,new DefaultTreeNode()); + } + + @Override + public JungleTree createNewTree(final String name, TreeNode rootNode) { ChangeList list = new ChangeList() { @Override public Iterator<TreeOperation> iterator() {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungle.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungle.java Mon Nov 07 03:40:57 2016 +0900 @@ -36,8 +36,14 @@ return trees.get(_name); } + @Override public JungleTree createNewTree(final String name) { + return createNewTree(name,new DefaultTreeNode()); + } + + @Override + public JungleTree createNewTree(final String name, TreeNode rootNode) { ChangeList list = new ChangeList() { @Override public Iterator<TreeOperation> iterator() {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTreeEditor.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTreeEditor.java Mon Nov 07 03:40:57 2016 +0900 @@ -84,6 +84,12 @@ } @Override + public Either<Error, JungleTreeEditor> moveChild(DefaultNodePath path,int childNum, String move) { + MoveChild movechild = new MoveChild(move, childNum); + return _edit(path,movechild); + } + + @Override public Either<Error, JungleTreeEditor> putAttribute(NodePath _path, String _key, ByteBuffer _value) { PutAttribute putAttribute = new PutAttribute(_key, _value); return _edit(_path, putAttribute);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTreeEditor.java Wed Jul 06 01:48:13 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTreeEditor.java Mon Nov 07 03:40:57 2016 +0900 @@ -5,6 +5,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.LoggingNode; @@ -121,6 +122,12 @@ } @Override + public Either<Error, JungleTreeEditor> moveChild(DefaultNodePath path, int childNum, String move) { + MoveChild movechild = new MoveChild(move, childNum); + return _edit(path,movechild); + } + + @Override public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) { return _edit(_path,_editor);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/differentialList/AddTest.java Mon Nov 07 03:40:57 2016 +0900 @@ -0,0 +1,22 @@ +package jp.ac.u_ryukyu.ie.cr.data.differentialList; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.differentialList.DifferentialList; +import org.junit.Assert; +import org.junit.Test; + +public class AddTest { + @Test + public void AddTest() { + DifferentialList<Integer> list = new DifferentialList<>(); + list = list.addLast(1); + DifferentialList<Integer> newList = list.addLast(2); + Assert.assertNotNull(list.index(0)); + Assert.assertNull(list.index(1)); + Assert.assertNotNull(newList.index(0)); + Assert.assertNotNull(newList.index(1)); + Assert.assertNull(newList.index(2)); + + + } +} +