# HG changeset patch
# User Shoshi TAMAKI
# Date 1360406626 -32400
# Node ID babb46537b8a4146c4dff24f124f5c13ffbf8317
# Parent e7a9b10dd84436ce194a9b564082d9720646736e
added junglebulletinboard
diff -r e7a9b10dd844 -r babb46537b8a pom.xml
--- a/pom.xml Thu Feb 07 00:26:21 2013 +0900
+++ b/pom.xml Sat Feb 09 19:43:46 2013 +0900
@@ -41,6 +41,11 @@
uuid
3.3
+
+ jungle
+ jungle-core
+ 0.0.1-SNAPSHOT
+
diff -r e7a9b10dd844 -r babb46537b8a src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java Thu Feb 07 00:26:21 2013 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java Sat Feb 09 19:43:46 2013 +0900
@@ -14,7 +14,13 @@
{
public static void main( String[] args ) throws Exception
{
- BulletinBoard cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2");
+ BulletinBoard cassaBBS = null;
+ if(args[0].equals("cassandra")){
+ cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2");
+ }else if(args[0].equals("jungle")){
+ cassaBBS = new JungleBulletinBoard();
+ }
+
String createBoardMessagePath = "/createBoardMessage";
String createBoardPath = "/createBoard";
diff -r e7a9b10dd844 -r babb46537b8a src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java Sat Feb 09 19:43:46 2013 +0900
@@ -0,0 +1,205 @@
+package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.atomic.AtomicInteger;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
+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.trasnformer.EditableNode;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor;
+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 implements BulletinBoard
+{
+ private final Jungle jungle;
+
+ public JungleBulletinBoard()
+ {
+ jungle = new DefaultJungle(null,"hoge",new DefaultTreeEditor(new DefaultTraverser()));
+ jungle.createNewTree("boards");
+ }
+
+ public Iterable getBoards()
+ {
+ JungleTree tree = jungle.getTreeByName("boards");
+ Node node = tree.getRootNode();
+ Children chs = node.getChildren();
+
+ IterableConverter.Converter converter = new IterableConverter.Converter(){
+ public String conv(Node _b) {
+ ByteBuffer e = _b.getAttributes().get("name");
+ return new String(e.array());
+ }
+ };
+
+ return new IterableConverter(chs,converter);
+ }
+
+ public void createBoards(final String _name,final String _author,final String _initMessage,final String _editKey)
+ {
+ if(null == jungle.createNewTree(_name)){
+ throw new IllegalStateException();
+ }
+
+ JungleTree tree = jungle.getTreeByName("boards");
+ JungleTreeEditor editor = tree.getTreeEditor();
+ DefaultNodePath root = new DefaultNodePath();
+ Either either = editor.addNewChildAt(root,0);
+ if(either.isA()){
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+
+ either = editor.putAttribute(root.add(0),"name",ByteBuffer.wrap(_name.getBytes()));
+ if(either.isA()){
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+ Either result = editor.success();
+ if(result.isA()){
+ throw new IllegalStateException();
+ }
+
+ tree = jungle.getTreeByName(_name);
+ editor = tree.getTreeEditor();
+ either = editor.addNewChildAt(root,0);
+ if(either.isA()){
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+
+ NodeEditor e = new NodeEditor(){
+ public > Either 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);
+ }
+ };
+
+ either = editor.edit(root.add(0),e);
+ if(either.isA()){
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+ editor.success();
+ }
+
+ public void createBoardMessage(final String _board,final String _author,final String _message,final String _editKey)
+ {
+ JungleTree tree = jungle.getTreeByName(_board);
+ if(tree == null){
+ throw new IllegalStateException();
+ }
+
+ Node node = tree.getRootNode();
+ int size = node.getChildren().size();
+ DefaultNodePath path = new DefaultNodePath();
+
+ JungleTreeEditor editor = tree.getTreeEditor();
+ Either either = editor.addNewChildAt(path,size);
+ if(either.isA()){
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+
+ NodeEditor e = new NodeEditor(){
+ public > Either 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);
+ }
+ };
+
+ path = path.add(size);
+ either = editor.edit(path,e);
+ if(either.isA()){
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+ editor.success();
+ }
+
+ public void editMessage(String _board,String _uuid,final String _author,final String _message,final String _editKey)
+ {
+ DefaultNodePath path = new DefaultNodePath();
+ path = path.add(Integer.parseInt(_uuid));
+
+ JungleTree tree = jungle.getTreeByName(_board);
+ JungleTreeEditor editor = tree.getTreeEditor();
+ NodeEditor e = new NodeEditor(){
+ public > Either 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);
+ }
+ };
+
+ Either either = editor.edit(path,e);
+ if(either.isA()){
+ throw new IllegalStateException();
+ }
+ editor = either.b();
+ editor.success();
+ }
+
+ public Iterable getMessages(String _boardName)
+ {
+ JungleTree tree = jungle.getTreeByName(_boardName);
+ Node node = tree.getRootNode();
+ Children chs = node.getChildren();
+
+ final AtomicInteger counter = new AtomicInteger(0);
+ IterableConverter.Converter converter = new IterableConverter.Converter(){
+ public BoardMessage conv(Node _b) {
+ String uuid = Integer.toString(counter.get());
+ String author = new String(_b.getAttributes().get("author").array());
+ String message = new String(_b.getAttributes().get("mes").array());
+ counter.incrementAndGet();
+ return new BoardMessageImpl(author,message,uuid);
+ }
+ };
+
+ return new IterableConverter(chs,converter);
+ }
+
+ private static class BoardMessageImpl implements BoardMessage
+ {
+ private final String author;
+ private final String message;
+ private final String uuid;
+
+ public BoardMessageImpl(String _author,String _message,String _uuid)
+ {
+ author = _author;
+ message = _message;
+ uuid = _uuid;
+ }
+
+ public String getAuthor()
+ {
+ return author;
+ }
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public String getUUID()
+ {
+ return uuid;
+ }
+ }
+}
diff -r e7a9b10dd844 -r babb46537b8a src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/AppTest.java
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/AppTest.java Thu Feb 07 00:26:21 2013 +0900
+++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/AppTest.java Sat Feb 09 19:43:46 2013 +0900
@@ -1,5 +1,7 @@
package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs;
+import fj.P2;
+import fj.data.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -10,6 +12,16 @@
public class AppTest
extends TestCase
{
+ public static void main(String _args[])
+ {
+ List list = List.range(0,5);
+ P2, List> split = list.splitAt(3);
+ System.out.println(list);
+ System.out.println(list.init());
+ System.out.println(split._1());
+ System.out.println(split._2());
+ }
+
/**
* Create the test case
*
diff -r e7a9b10dd844 -r babb46537b8a target/classes/META-INF/MANIFEST.MF
--- a/target/classes/META-INF/MANIFEST.MF Thu Feb 07 00:26:21 2013 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-Manifest-Version: 1.0
-Built-By: shoshi
-Build-Jdk: 1.6.0_37
-Created-By: Maven Integration for Eclipse
-
diff -r e7a9b10dd844 -r babb46537b8a target/classes/META-INF/maven/jp.ac.u_ryukyu.ie.cr.shoshi.jungle/bulletinboard/pom.properties
--- a/target/classes/META-INF/maven/jp.ac.u_ryukyu.ie.cr.shoshi.jungle/bulletinboard/pom.properties Thu Feb 07 00:26:21 2013 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-#Generated by Maven Integration for Eclipse
-#Thu Feb 07 00:25:48 JST 2013
-version=0.0.1-SNAPSHOT
-groupId=jp.ac.u_ryukyu.ie.cr.shoshi.jungle
-m2e.projectName=bulletinboard
-m2e.projectLocation=/Users/shoshi/Documents/eclipse/jungle/bulletinboard
-artifactId=bulletinboard
diff -r e7a9b10dd844 -r babb46537b8a target/classes/META-INF/maven/jp.ac.u_ryukyu.ie.cr.shoshi.jungle/bulletinboard/pom.xml
--- a/target/classes/META-INF/maven/jp.ac.u_ryukyu.ie.cr.shoshi.jungle/bulletinboard/pom.xml Thu Feb 07 00:26:21 2013 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-
- 4.0.0
-
- jp.ac.u_ryukyu.ie.cr.shoshi.jungle
- bulletinboard
- 0.0.1-SNAPSHOT
- jar
-
- bulletinboard
- http://maven.apache.org
-
-
- UTF-8
-
-
-
-
- junit
- junit
- 3.8.1
- test
-
-
- org.mortbay.jetty
- jetty
- 6.1.26
-
-
- org.hectorclient
- hector-core
- 1.1-2
-
-
- org.apache.cassandra
- cassandra-all
- 1.2.1
-
-
- com.eaio.uuid
- uuid
- 3.3
-
-
-
-
- eaio.com
- http://eaio.com/maven2
-
-
-