Mercurial > hg > Members > nobuyasu > jungle-network
changeset 168:91f6dd655a01
refactoring
author | tatsuki |
---|---|
date | Tue, 29 Jul 2014 10:58:11 +0900 |
parents | 564f683b7aef |
children | 54d68cda84c4 |
files | src/main/java/app/bbs/NetworkJungleBulletinBoard.java src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java src/main/java/app/bbs/thinks/ShowMatrix.java src/main/java/app/bbs/thinks/getAttributeImp.java |
diffstat | 4 files changed, 67 insertions(+), 154 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Mon Jul 28 17:02:31 2014 +0900 +++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Tue Jul 29 10:58:11 2014 +0900 @@ -43,8 +43,7 @@ private NetworkJungleBulletinBoard(String _uuid, NetworkJournal _journal) { journal = _journal; - jungle = new NetworkDefaultJungle(journal, _uuid, - new DefaultTreeEditor(new DefaultTraverser())); + jungle = new NetworkDefaultJungle(journal, _uuid, new DefaultTreeEditor(new DefaultTraverser())); BulletinBoardJungleManager.setJungle(jungle); persistentFlag = false; requestCounter = BulletinBoardJungleManager.getRequestCounter(); @@ -58,8 +57,7 @@ } public static NetworkBulletinBoard NewPersistentJungle(String _uuid) { - NetworkJungleBulletinBoard board = new NetworkJungleBulletinBoard( - _uuid, new PersistentJournal()); + NetworkJungleBulletinBoard board = new NetworkJungleBulletinBoard( _uuid, new PersistentJournal()); board.persistentFlag = true; return board; } @@ -111,8 +109,7 @@ tree = jungle.createNewTree(treeName); } JungleTreeEditor editor = tree.getLocalTreeEditor(); - Either<Error, JungleTreeEditor> either = JungleUpdater.edit(editor, - chList); + Either<Error, JungleTreeEditor> either = JungleUpdater.edit(editor, chList); editor = either.b(); if (either.isA()) { throw new IOException("Failed commit log recovery"); @@ -140,8 +137,7 @@ return renewTime; } - public void createBoards(final String _name, final String _author, - final String _initMessage, final String _editKey) { + public void createBoards(final String _name, final String _author, final String _initMessage, final String _editKey) { requestCounter.incrementAndGet(); if (null == jungle.createNewTree(_name)) { throw new IllegalStateException(); @@ -156,8 +152,7 @@ } editor = either.b(); - either = editor.putAttribute(root.add(0), "name", - ByteBuffer.wrap(_name.getBytes())); + either = editor.putAttribute(root.add(0), "name",ByteBuffer.wrap(_name.getBytes())); if (either.isA()) { throw new IllegalStateException(); } @@ -184,13 +179,9 @@ NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> 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(); + _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(); ByteBuffer tBuffer2 = ByteBuffer.allocate(16); tBuffer2.putLong(timestamp); _e = _e.getAttributes().put("timestamp", tBuffer2).b(); @@ -206,8 +197,7 @@ } - public void createFolder(final String _board, final String _author, - final String _message, final String _editKey, String _nodeNum) { + public void createFolder(final String _board, final String _author, final String _message, final String _editKey, String _nodeNum) { JungleTree tree = jungle.getTreeByName(_board); if (tree == null) { throw new IllegalStateException(); @@ -217,8 +207,7 @@ try { for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count, - count + 1))); + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); } } catch (Exception _e) { } @@ -227,15 +216,13 @@ final long timestamp = System.currentTimeMillis(); final ByteBuffer tBuffer = ByteBuffer.allocate(16); tBuffer.putLong(timestamp); + do { Node node = tree.getRootNode(); - DefaultTraverser traverser = new DefaultTraverser(); - TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>( - node); + TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>(node); DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser - .traverse(traversable, evaluator); + Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser.traverse(traversable, evaluator); if (ret.isA()) { Assert.fail(); } @@ -252,15 +239,7 @@ NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> 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(); + _e = _e.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); _e = _e.getAttributes().put("timestamp", tBuffer).b(); return DefaultEither.newB(_e); } @@ -276,8 +255,7 @@ } - public void createBoardMessage(final String _board, final String _author, - final String _message, final String _editKey) { + public void createBoardMessage(final String _board, final String _author, final String _message, final String _editKey) { requestCounter.incrementAndGet(); JungleTree tree = jungle.getTreeByName(_board); if (tree == null) { @@ -289,6 +267,7 @@ final ByteBuffer tBuffer = ByteBuffer.allocate(16); tBuffer.putLong(timestamp); do { + Node node = tree.getRootNode(); int size = node.getChildren().size(); DefaultNodePath path = new DefaultNodePath(); @@ -302,15 +281,9 @@ NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> 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(); + _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(); _e = _e.getAttributes().put("timestamp", tBuffer).b(); return DefaultEither.newB(_e); } @@ -326,14 +299,14 @@ } - public void editMessage(String _board, String _uuid, final String _author, - final String _message, final String _editKey) { + public void editMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) { requestCounter.incrementAndGet(); final long timestamp = System.currentTimeMillis(); final ByteBuffer tBuffer = ByteBuffer.allocate(16); tBuffer.putLong(timestamp); JungleTree tree = jungle.getTreeByName(_board); Either<Error, JungleTreeEditor> either = null; + do { DefaultNodePath path = new DefaultNodePath(); path = path.add(Integer.parseInt(_uuid)); @@ -341,15 +314,9 @@ JungleTreeEditor editor = tree.getTreeEditor(); NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> 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(); + _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(); _e = _e.getAttributes().put("timestamp", tBuffer).b(); return DefaultEither.newB(_e); } @@ -364,8 +331,7 @@ renewTime = timestamp; } - public void createAttribute(String _board, String _uuid, - final String _author, final String _message, final String _editKey) { + public void createAttribute(String _board, String _uuid, final String _author, final String _message, final String _editKey) { requestCounter.incrementAndGet(); final long timestamp = System.currentTimeMillis(); final ByteBuffer tBuffer = ByteBuffer.allocate(16); @@ -377,40 +343,21 @@ try { for (int count = 0; _uuid.substring(count, count + 1) != null; count++) { if (!_uuid.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_uuid.substring(count, - count + 1))); + path = path.add(Integer.parseInt(_uuid.substring(count, count + 1))); } } catch (Exception _e) { } - Node node = tree.getRootNode(); - - DefaultTraverser traverser = new DefaultTraverser(); - TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>( - node); - DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser - .traverse(traversable, evaluator); - if (ret.isA()) { - Assert.fail(); - } - - Traversal<TraversableNodeWrapper<Node>> traversal = ret.b(); - TraversableNodeWrapper<Node> target = traversal.destination(); - final Node cheakNode = target.getWrapped(); - System.out.println(cheakNode.getAttributes().get("attribute")); - + JungleTreeEditor editor = tree.getTreeEditor(); NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> edit(T _e) { // EnableNodeWrapper<T> node = _e.getWrap(); String str = "0"; int count = 0; - for (; _e.getAttributes().get("author" + String.valueOf(count)) != null; count++) { + for (; _e.getAttributes().get("mes" + String.valueOf(count)) != null; count++) { } str = String.valueOf(count); - _e = _e.getAttributes().put("author" + str, ByteBuffer.wrap(_author.getBytes())).b(); _e = _e.getAttributes().put("mes" + str, ByteBuffer.wrap(_message.getBytes())).b(); - _e = _e.getAttributes().put("key" + str, ByteBuffer.wrap(_editKey.getBytes())).b(); _e = _e.getAttributes().put("timestamp" + str, tBuffer).b(); return DefaultEither.newB(_e); } @@ -424,8 +371,7 @@ } while (either.isA()); } - public void editMatrixMessage(String _board, String _uuid, - final String _author, final String _message, final String _editKey) { + public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) { requestCounter.incrementAndGet(); final long timestamp = System.currentTimeMillis(); final ByteBuffer tBuffer = ByteBuffer.allocate(16); @@ -439,15 +385,9 @@ JungleTreeEditor editor = tree.getTreeEditor(); NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> 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(); + _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(); _e = _e.getAttributes().put("timestamp", tBuffer).b(); return DefaultEither.newB(_e); } @@ -471,10 +411,8 @@ IterableConverter.Converter<BoardMessage, Node> converter = new IterableConverter.Converter<BoardMessage, Node>() { 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()); + 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); } @@ -488,8 +426,7 @@ try { for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count, - count + 1))); + path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1))); } } catch (Exception _e) { } @@ -498,11 +435,9 @@ Node node = tree.getRootNode(); DefaultTraverser traverser = new DefaultTraverser(); - TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>( - node); + TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>(node); DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser - .traverse(traversable, evaluator); + Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser.traverse(traversable, evaluator); if (ret.isA()) { Assert.fail(); } @@ -515,10 +450,9 @@ IterableConverter.Converter<BoardMessage, Node> converter = new IterableConverter.Converter<BoardMessage, Node>() { 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 BoardMessageImpl(null, message, uuid); } }; return new IterableConverter<BoardMessage, Node>(chs, converter); @@ -531,8 +465,7 @@ try { for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count, - count + 1))); + path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1))); } } catch (Exception _e) { }
--- a/src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java Mon Jul 28 17:02:31 2014 +0900 +++ b/src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java Tue Jul 29 10:58:11 2014 +0900 @@ -45,24 +45,19 @@ _pw.write("<h1>" + _bname + "</h1>\n"); _pw.write("<p>Latest renew time : " + bbs.getRenewTime(_bname) + "</p>\n"); - - _pw.write("<form action='" + createBoardMessagePath - + "' method='POST'\n"); - _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='" - + _bname - + "'/> EditKey : <input type='text' name='key'/></p>\n"); + ; + + _pw.write("<form action='" + createBoardMessagePath + "' method='POST'\n"); + _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='" + _bname + "'/> EditKey : <input type='text' name='key'/></p>\n"); _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n"); _pw.write("<p><input type='submit' value='submit'/></p>\n"); - + _pw.write("<small><a href=" + showMatrixPath + "?bname=" + _bname + "&uuid= >MatrixMode"+"</a></small><br>"); for (BoardMessage msg : bbs.getMessages(_bname)) {//フォルダの表示 _pw.write("<hr/>"); - _pw.write("<p><b>" + msg.getAuthor() + "</b></p>"); - _pw.write("<p>" + msg.getMessage() + "</p>"); - _pw.write("<small><a href=" + showMatrixPath + "?bname=" + _bname - + "&uuid=0" + ">"+msg.getMessage()+"(show matrix)"+"</a></small><br>"); - _pw.write("<small><a href='" + editMessagePath + "?bname=" + _bname - + "&uuid=" + msg.getUUID() + "'>edit</a></small>"); + _pw.write("<p> Author <b>" + msg.getAuthor() + "</b></p>"); + _pw.write("<small><a href=" + editMessagePath + "?bname=" + _bname + + "&uuid=" + msg.getUUID() + ">"+ msg.getMessage() +"</a></small><br>"); } //forコメントの表示
--- a/src/main/java/app/bbs/thinks/ShowMatrix.java Mon Jul 28 17:02:31 2014 +0900 +++ b/src/main/java/app/bbs/thinks/ShowMatrix.java Tue Jul 29 10:58:11 2014 +0900 @@ -36,26 +36,26 @@ public void doGet(HttpServletRequest _req, HttpServletResponse _res) { final String bname = _req.getParameter(PARAM_BOARD_NAME); String nodeNum = _req.getParameter("uuid"); + String nodeName = _req.getParameter("nodeName"); try { - printBoard(bname, nodeNum, _res.getWriter()); + printBoard(bname, nodeNum, nodeName, _res.getWriter()); } catch (Exception _e) { _res.setStatus(500); } } - private void printBoard(String _bname, String nodeNum, PrintWriter _pw) + private void printBoard(String _bname, String nodeNum, String nodeName, PrintWriter _pw) throws Exception { _pw.write("<html><body>\n"); - _pw.write("<h1>" + " This Borad is Test Board " + "</h1>\n"); - _pw.write("<p>Latest renew time : " + bbs.getRenewTime(_bname) - + "</p>\n"); - ; - - _pw.write("<form action='" + createBoardMessagePath - + "' method='POST'>\n"); - _pw.write("<p><input type='hidden' name='author'/> " - + "<input type='hidden' name='bname' value='" + _bname - + "'/> <input type='hidden' name='key'/></p>\n"); + + if(nodeName == null ) + nodeName = "rootNode" ; + + + _pw.write("<h1>" + nodeName + " Path = " + nodeNum + "</h1>\n"); + + _pw.write("<form action='" + createBoardMessagePath + "' method='POST'>\n"); + _pw.write("<p><input type='hidden' name='bname' value='" + _bname + "'/> </p>\n"); _pw.write("<p>Folder Name<br/> <input type='textarea' name='msg'/> </p>\n"); _pw.write("<input type='hidden' name='uuid' value='" + nodeNum + "'/>"); _pw.write("<p><input type='submit' value='submit'/></p>\n"); @@ -63,9 +63,7 @@ _pw.write("<p><br>add Attribute</p>"); _pw.write("<form action='" + createAttributePath + "' method='POST'\n"); - _pw.write("<p>AUTHOR :<input type='textarea' name='author'/> " - + "<input type='hidden' name='bname' value='" + _bname - + "'/> KEY :<input type='textarea' name='key'/></p>\n"); + _pw.write("<p><input type='hidden' name='bname' value='" + _bname + "'</p>\n"); _pw.write("<p>attributeName<br/> <input type='textarea' name='msg'/> </p>\n"); _pw.write("<input type='hidden' name='uuid' value='" + nodeNum + "'/>"); _pw.write("<p><input type='submit' value='submit'/></p>\n"); @@ -75,23 +73,16 @@ for (BoardMessage msg : bbs.getFolder(_bname, nodeNum)) { _pw.write("<hr/>"); - _pw.write("<small><a href=" + showMatrixPath + "?bname=" + _bname - + "&uuid=" + nodeNum + "/" + msg.getUUID() + ">" - + msg.getMessage() + "(folder)" + "</a></small><br>"); - _pw.write("<small><a href='" + createAttributePath + "?bname=" - + _bname + "&uuid=0" + msg.getUUID() - + "'>edit(not s)</a></small>"); + _pw.write("<small><a href=" + showMatrixPath + "?bname=" + _bname + "&uuid=" + nodeNum + "/" + msg.getUUID() + "&nodeName=" + msg.getMessage() + ">" + msg.getMessage() + "</a></small>"); + _pw.write(" "); + _pw.write("<small><a href='" + createAttributePath + "?bname=" + _bname + "&uuid=" + nodeNum + "/"+ msg.getUUID() + "'>edit(not s)</a></small>"); } - _pw.write("<br><br><hr/><p>Value</p><br><br>"); + + + _pw.write("<br><hr/><p>Value</p><br>"); getAttributeImp attribute = (bbs.getAttribute(_bname, nodeNum)); - for (int count = 0; attribute.getMessage(count) != null; count++) { - - _pw.write("<p><b>" + "Author : " + attribute.getMessage(count) - + "</b></p>"); - // _pw.write("<small><a href='" + createAttributePath + "?bname=" + - // _bname - // + "&uuid=" + msg.getUUID() + "'>edit</a></small>"); + _pw.write("<p><b>" + "Varue " + count + " : " + attribute.getMessage(count) + "</b></p>"); } _pw.write("</body></html>");
--- a/src/main/java/app/bbs/thinks/getAttributeImp.java Mon Jul 28 17:02:31 2014 +0900 +++ b/src/main/java/app/bbs/thinks/getAttributeImp.java Tue Jul 29 10:58:11 2014 +0900 @@ -2,7 +2,6 @@ -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; public class getAttributeImp @@ -19,11 +18,6 @@ return String.valueOf(num); } - public String getAuthor(int num) { - // TODO Auto-generated method stub - return new String(node.getAttributes().get("author" + String.valueOf(num)).array()); - } - public String getMessage(int num) { // TODO Auto-generated method stub return new String(node.getAttributes().get("mes" + String.valueOf(num)).array());