# HG changeset patch # User shoshi # Date 1339413000 -32400 # Node ID 113050de7f69c420c82b8a08d728e7ea058aad11 hg init diff -r 000000000000 -r 113050de7f69 pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,35 @@ + + 4.0.0 + + jungle + jungle-core + 0.0.1-SNAPSHOT + jar + + jungle-core + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + com.google.guava + guava + 12.0 + + + commons-collections + commons-collections + 3.2.1 + + + diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/App.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/App.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,13 @@ +package jungle.core; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Attributes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Attributes.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,11 @@ +package jungle.core; + +public interface Attributes +{ + public String get(String _key); + public boolean contains(String _key); + public int size(); + + public Attributes remove(String _key); + public Attributes put(String _key,String _value); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Children.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Children.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,6 @@ +package jungle.core; + +public interface Children extends OrderedNodeSet +{ + public TreeNode getAt(int _pos); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Editor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Editor.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,16 @@ +package jungle.core; + +public interface Editor +{ + public Tree commit(); + public Tree rollback(); + + public Link createLinkAt(TreeNode _target,Tree _linkTarget); + public void removeLinkAt(TreeNode _target,Link _removeTarget); + + public TreeNode createChildAt(TreeNode _target); + public void removeChildAt(TreeNode _target,TreeNode _removeTarget); + + public String putPropertyAt(TreeNode _target,String _key,String _value); + public String removePropertyAt(TreeNode _target,String _key); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Jungle.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Jungle.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,8 @@ +package jungle.core; + +public interface Jungle +{ + TreeGroup createTreeGroup(); + Iterable treeGroups(); + Editor newEditor(Tree _t); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Link.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Link.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,6 @@ +package jungle.core; + +public interface Link extends Node +{ + TreeGroup destination(); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Links.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Links.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,6 @@ +package jungle.core; + +public interface Links extends OrderedNodeSet +{ + public Link getAt(int _pos); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Node.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Node.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,6 @@ +package jungle.core; + +public interface Node +{ + String get(String _key); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/OrderedNodeSet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/OrderedNodeSet.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,8 @@ +package jungle.core; + +public interface OrderedNodeSet extends Iterable +{ + public boolean contains(T n); + public T getAt(int pos); + public int size(); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Path.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Path.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,9 @@ +package jungle.core; + +public interface Path extends Iterable +{ + public Path removeAt(int _pos); + public Path removeTail(); + public Path add(Node _tail); + public Node getAt(int _pos); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/Tree.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/Tree.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,8 @@ +package jungle.core; + +public interface Tree extends TreeNode +{ + Editor newEditor(); + TreeGroup getGroup(); + String treeID(); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/TreeGroup.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/TreeGroup.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,7 @@ +package jungle.core; + +public interface TreeGroup +{ + String getID(); + Tree latestTree(); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/core/TreeNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/core/TreeNode.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,8 @@ +package jungle.core; + +public interface TreeNode extends Node +{ + Children children(); + Links links(); + String cid(); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/SimpleAttributes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleAttributes.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,55 @@ +package jungle.impl; + +import java.util.concurrent.ConcurrentHashMap; + +import jungle.core.Attributes; + +public class SimpleAttributes implements Attributes +{ + private final ConcurrentHashMap attrs; + + public SimpleAttributes() + { + this(new ConcurrentHashMap()); + } + + private SimpleAttributes(ConcurrentHashMap _attrs) + { + attrs = _attrs; + } + + public String get(String _key) + { + return attrs.get(_key); + } + + public boolean contains(String _key) + { + return attrs.contains(_key); + } + + public int size() + { + return attrs.size(); + } + + public Attributes remove(String _key) + { + ConcurrentHashMap copy = copy(); + copy.remove(_key); + return new SimpleAttributes(copy); + } + + public Attributes put(String _key, String _value) + { + ConcurrentHashMap copy = copy(); + copy.put(_key,_value); + return new SimpleAttributes(copy); + } + + private ConcurrentHashMap copy() + { + return new ConcurrentHashMap(attrs); + } + +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/SimpleChildren.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleChildren.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,43 @@ +package jungle.impl; + + +import java.util.Iterator; + +import jungle.core.Children; +import jungle.core.OrderedNodeSet; +import jungle.core.TreeNode; + +public class SimpleChildren implements Children +{ + private final OrderedNodeSet sets; + + public SimpleChildren() + { + this(new SimpleOrderedNodeSet()); + } + + private SimpleChildren(OrderedNodeSet _set) + { + sets = _set; + } + + public Iterator iterator() + { + return sets.iterator(); + } + + public boolean contains(TreeNode n) + { + return sets.contains(n); + } + + public TreeNode getAt(int pos) + { + return sets.getAt(pos); + } + + public int size() + { + return sets.size(); + } +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/SimpleEditor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleEditor.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,56 @@ +package jungle.impl; + +import jungle.core.Editor; +import jungle.core.Link; +import jungle.core.Tree; +import jungle.core.TreeNode; + +public class SimpleEditor implements Editor +{ + private final Tree tree; + + public SimpleEditor(Tree _tree) + { + tree = _tree; + } + + public Tree commit() + { + return null; + } + + public Tree rollback() + { + return null; + } + + public Link createLinkAt(TreeNode _target, Tree _linkTarget) + { + + return null; + } + + public void removeLinkAt(TreeNode _target, Link _removeTarget) + { + } + + public TreeNode createChildAt(TreeNode _target) + { + return null; + } + + public void removeChildAt(TreeNode _target, TreeNode _removeTarget) + { + } + + public String putPropertyAt(TreeNode _target, String _key, String _value) + { + return null; + } + + public String removePropertyAt(TreeNode _target, String _key) + { + return null; + } + +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/SimpleLinks.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleLinks.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,46 @@ +package jungle.impl; + +import java.util.Iterator; +import jungle.core.Link; +import jungle.core.Links; +import jungle.core.OrderedNodeSet; + +public class SimpleLinks implements Links +{ + private final OrderedNodeSet set; + + public SimpleLinks() + { + this(new SimpleOrderedNodeSet()); + } + + private SimpleLinks(SimpleOrderedNodeSet _set) + { + set = _set; + } + + public boolean contains(Link n) + { + return set.contains(n); + } + + public int size() + { + return set.size(); + } + + public Iterator iterator() + { + return set.iterator(); + } + + public Link getAt(int _pos) + { + if(_pos > size()){ + return null; + } + + return set.getAt(_pos); + } + +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/SimpleOrderedNodeSet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleOrderedNodeSet.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,83 @@ +package jungle.impl; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; + +import jungle.core.Node; +import jungle.core.OrderedNodeSet; + +public class SimpleOrderedNodeSet implements OrderedNodeSet +{ + private LinkedList list; + private HashSet set; + private Collection listGuard; + + public SimpleOrderedNodeSet() + { + this(new LinkedList(),new HashSet()); + } + + private SimpleOrderedNodeSet(LinkedList _list,HashSet _set) + { + list = _list; + set = _set; + listGuard = Collections.unmodifiableList(list); + } + + public Iterator iterator() + { + return listGuard.iterator(); + } + + public boolean contains(T _n) + { + return set.contains(_n); + } + + public T getAt(int _pos) + { + if(_pos > size()){ + return null; + } + + return list.get(_pos); + } + + public OrderedNodeSet remove(int _pos) + { + if(_pos > size()){ + return null; + } + + LinkedList copyOfList = new LinkedList(list); + HashSet copyOfSet = new HashSet(set); + + T obj = copyOfList.remove(_pos); + copyOfSet.remove(obj); + + return new SimpleOrderedNodeSet(copyOfList,copyOfSet); + } + + public OrderedNodeSet add(T _n) + { + if(_n == null){ + throw new NullPointerException("the add target is null."); + } + + LinkedList copyOfList = new LinkedList(list); + HashSet copyOfSet = new HashSet(set); + + copyOfList.add(_n); + copyOfSet.add(_n); + + return new SimpleOrderedNodeSet(copyOfList,copyOfSet); + } + + public int size() + { + return list.size(); + } +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/SimpleTree.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleTree.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,66 @@ +package jungle.impl; + +import jungle.core.Attributes; +import jungle.core.Children; +import jungle.core.Editor; +import jungle.core.Links; +import jungle.core.Tree; +import jungle.core.TreeGroup; + +public class SimpleTree implements Tree +{ + private final String tid; + private final Attributes attrs; + private final Children children; + private final Links links; + private final TreeGroup group; + + public SimpleTree(String _tid,TreeGroup _group) + { + this(_tid,_group,Simples.EMPTY_ATTRIBUTES,Simples.EMPTY_CHILDREN,Simples.EMPTY_LINKS); + } + + public SimpleTree(String _tid,TreeGroup _group,Attributes _attrs,Children _children,Links _links) + { + tid = _tid; + attrs = _attrs; + children = _children; + links = _links; + group = _group; + } + + public TreeGroup getGroup() + { + return group; + } + + public String get(String _key) + { + return attrs.get(_key); + } + + public Editor newEditor() + { + return new SimpleEditor(this); + } + + public String treeID() + { + return tid; + } + + public Children children() + { + return children; + } + + public Links links() + { + return links; + } + + public String cid() + { + return tid; + } +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/SimpleTreeGroup.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleTreeGroup.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,29 @@ +package jungle.impl; + +import java.util.concurrent.atomic.AtomicReference; + +import jungle.core.Editor; +import jungle.core.Tree; +import jungle.core.TreeGroup; + +public class SimpleTreeGroup implements TreeGroup +{ + private String id; + private AtomicReference latestTree; + + public SimpleTreeGroup(String _id) + { + latestTree = new AtomicReference(); + id = _id; + } + + public String getID() + { + return id; + } + + public Tree latestTree() + { + return latestTree.get(); + } +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/SimpleTreeNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/SimpleTreeNode.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,72 @@ +package jungle.impl; + +import jungle.core.Attributes; +import jungle.core.Children; +import jungle.core.Links; +import jungle.core.TreeNode; + +public class SimpleTreeNode implements TreeNode +{ + private final Children children; + private final Links links; + private final Attributes attrs; + private final String id; + + public SimpleTreeNode(String _id) + { + this(_id,new SimpleAttributes(),new SimpleChildren(),new SimpleLinks()); + } + + private SimpleTreeNode(String _id,Attributes _attrs,Children _children,Links _links) + { + if(_id == null || _id.length() == 0){ + throw new NullPointerException("_id is null or empty."); + } + + id = _id; + attrs = _attrs; + children = _children; + links = _links; + } + + public String get(String _key) + { + if(_key == null){ + throw new NullPointerException("_key is null"); + } + + return attrs.get(_key); + } + + public Children children() + { + return children; + } + + public Links links() + { + return links; + } + + public String cid() + { + return id; + } + + @Override + public int hashCode() + { + return id.hashCode(); + } + + @Override + public boolean equals(Object _obj) + { + if(_obj instanceof SimpleTreeNode){ + SimpleTreeNode node = (SimpleTreeNode)_obj; + return id.equals(node.id); + } + return false; + } + +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/impl/Simples.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/impl/Simples.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,12 @@ +package jungle.impl; + +import jungle.core.Attributes; +import jungle.core.Children; +import jungle.core.Links; + +public class Simples +{ + public static final Attributes EMPTY_ATTRIBUTES = new SimpleAttributes(); + public static final Children EMPTY_CHILDREN = new SimpleChildren(); + public static final Links EMPTY_LINKS = new SimpleLinks(); +} diff -r 000000000000 -r 113050de7f69 src/main/java/jungle/parsist/NodeProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jungle/parsist/NodeProvider.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,11 @@ +package jungle.parsist; + +import jungle.core.Node; + +public interface NodeProvider +{ + public void onInitialize(); + public void onCreateNode(Node _n); + public void onUpdateNode(Node _n); + public void onRemoveNode(Node _n); +} diff -r 000000000000 -r 113050de7f69 src/test/java/jungle/core/AppTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jungle/core/AppTest.java Mon Jun 11 20:10:00 2012 +0900 @@ -0,0 +1,38 @@ +package jungle.core; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}