changeset 0:113050de7f69

hg init
author shoshi <shoshi@cr.ie.u-ryukyu.ac.jp>
date Mon, 11 Jun 2012 20:10:00 +0900
parents
children b1fa4c494416
files pom.xml src/main/java/jungle/core/App.java src/main/java/jungle/core/Attributes.java src/main/java/jungle/core/Children.java src/main/java/jungle/core/Editor.java src/main/java/jungle/core/Jungle.java src/main/java/jungle/core/Link.java src/main/java/jungle/core/Links.java src/main/java/jungle/core/Node.java src/main/java/jungle/core/OrderedNodeSet.java src/main/java/jungle/core/Path.java src/main/java/jungle/core/Tree.java src/main/java/jungle/core/TreeGroup.java src/main/java/jungle/core/TreeNode.java src/main/java/jungle/impl/SimpleAttributes.java src/main/java/jungle/impl/SimpleChildren.java src/main/java/jungle/impl/SimpleEditor.java src/main/java/jungle/impl/SimpleLinks.java src/main/java/jungle/impl/SimpleOrderedNodeSet.java src/main/java/jungle/impl/SimpleTree.java src/main/java/jungle/impl/SimpleTreeGroup.java src/main/java/jungle/impl/SimpleTreeNode.java src/main/java/jungle/impl/Simples.java src/main/java/jungle/parsist/NodeProvider.java src/test/java/jungle/core/AppTest.java
diffstat 25 files changed, 658 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>jungle</groupId>
+  <artifactId>jungle-core</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>jungle-core</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+    	<groupId>com.google.guava</groupId>
+    	<artifactId>guava</artifactId>
+    	<version>12.0</version>
+    </dependency>
+    <dependency>
+    	<groupId>commons-collections</groupId>
+    	<artifactId>commons-collections</artifactId>
+    	<version>3.2.1</version>
+    </dependency>
+  </dependencies>
+</project>
--- /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!" );
+    }
+}
--- /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);
+}
--- /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<TreeNode>
+{
+	public TreeNode getAt(int _pos);
+}
--- /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);
+}
--- /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<TreeGroup> treeGroups();
+	Editor newEditor(Tree _t);
+}
--- /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();
+}
--- /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<Link>
+{
+	public Link getAt(int _pos);
+}
--- /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);
+}
--- /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<T extends Node> extends Iterable<T>
+{
+	public boolean contains(T n);
+	public T getAt(int pos);
+	public int size();
+}
--- /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<Node>
+{
+	public Path removeAt(int _pos);
+	public Path removeTail();
+	public Path add(Node _tail);
+	public Node getAt(int _pos);
+}
--- /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();
+}
--- /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();
+}
--- /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();
+}
--- /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<String,String> attrs;
+	
+	public SimpleAttributes()
+	{
+		this(new ConcurrentHashMap<String,String>());
+	}
+	
+	private SimpleAttributes(ConcurrentHashMap<String,String> _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<String,String> copy = copy();
+		copy.remove(_key);
+		return new SimpleAttributes(copy);
+	}
+
+	public Attributes put(String _key, String _value)
+	{
+		ConcurrentHashMap<String,String> copy = copy();
+		copy.put(_key,_value);
+		return new SimpleAttributes(copy);
+	}
+	
+	private ConcurrentHashMap<String,String> copy()
+	{
+		return new ConcurrentHashMap<String,String>(attrs);
+	}
+
+}
--- /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<TreeNode> sets;
+	
+	public SimpleChildren()
+	{
+		this(new SimpleOrderedNodeSet<TreeNode>());
+	}
+	
+	private SimpleChildren(OrderedNodeSet<TreeNode> _set)
+	{
+		sets = _set;
+	}
+
+	public Iterator<TreeNode> 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();
+	}
+}
--- /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;
+	}
+
+}
--- /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<Link> set;
+	
+	public SimpleLinks()
+	{
+		this(new SimpleOrderedNodeSet<Link>());
+	}
+	
+	private SimpleLinks(SimpleOrderedNodeSet<Link> _set)
+	{
+		set = _set;
+	}
+
+	public boolean contains(Link n)
+	{
+		return set.contains(n);
+	}
+
+	public int size()
+	{
+		return set.size();
+	}
+
+	public Iterator<Link> iterator()
+	{
+		return set.iterator();
+	}
+
+	public Link getAt(int _pos)
+	{
+		if(_pos > size()){
+			return null;
+		}
+		
+		return set.getAt(_pos);
+	}
+
+}
--- /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<T extends Node> implements OrderedNodeSet<T>
+{
+	private LinkedList<T> list;
+	private HashSet<T> set;
+	private Collection<T> listGuard;
+	
+	public SimpleOrderedNodeSet()
+	{
+		this(new LinkedList<T>(),new HashSet<T>());
+	}
+	
+	private SimpleOrderedNodeSet(LinkedList<T> _list,HashSet<T> _set)
+	{
+		list = _list;
+		set = _set;
+		listGuard = Collections.unmodifiableList(list);
+	}
+
+	public Iterator<T> 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<T> remove(int _pos)
+	{
+		if(_pos > size()){
+			return null;
+		}
+		
+		LinkedList<T> copyOfList = new LinkedList<T>(list);
+		HashSet<T> copyOfSet = new HashSet<T>(set);
+		
+		T obj = copyOfList.remove(_pos);
+		copyOfSet.remove(obj);
+		
+		return new SimpleOrderedNodeSet<T>(copyOfList,copyOfSet);
+	}
+
+	public OrderedNodeSet<T> add(T _n)
+	{
+		if(_n == null){
+			throw new NullPointerException("the add target is null.");
+		}
+		
+		LinkedList<T> copyOfList = new LinkedList<T>(list);
+		HashSet<T> copyOfSet = new HashSet<T>(set);
+		
+		copyOfList.add(_n);
+		copyOfSet.add(_n);
+		
+		return new SimpleOrderedNodeSet<T>(copyOfList,copyOfSet);
+	}
+
+	public int size()
+	{
+		return list.size();
+	}
+}
--- /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;
+	}
+}
--- /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<Tree> latestTree;
+	
+	public SimpleTreeGroup(String _id)
+	{
+		latestTree = new AtomicReference<Tree>();
+		id = _id;
+	}
+
+	public String getID()
+	{
+		return id;
+	}
+
+	public Tree latestTree()
+	{
+		return latestTree.get();
+	}
+}
--- /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;
+	}
+
+}
--- /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();
+}
--- /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);
+}
--- /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 );
+    }
+}