diff src/main/java/app/bbs/NetworkJungleBulletinBoard.java @ 170:2403b9a4416f

create Delete Attribute Method
author tatsuki
date Wed, 30 Jul 2014 10:20:01 +0900
parents 54d68cda84c4
children df063cf6f3b5
line wrap: on
line diff
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java	Tue Jul 29 18:51:44 2014 +0900
+++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java	Wed Jul 30 10:20:01 2014 +0900
@@ -356,7 +356,6 @@
 			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("mes" + String.valueOf(count)) != null; count++) {
@@ -411,6 +410,48 @@
 		} while (either.isA());
 	}
 
+	public void deleteAttribute(String _board, String _path ,final String id) {
+		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;
+		DefaultNodePath path = new DefaultNodePath();
+		do {
+			try {
+				for (int count = 0; _path.substring(count, count + 1) != null; count++) {
+					if (!_path.substring(count, count + 1).equals("/"))
+						path = path.add(Integer.parseInt(_path.substring(count,	count + 1)));
+				}
+			} catch (Exception _e) {
+			}
+			
+			JungleTreeEditor editor = tree.getTreeEditor();
+			NodeEditor e = new NodeEditor() {
+				public <T extends EditableNode<T>> Either<Error, T> edit(T _e) {
+					_e = _e.getAttributes().delete("mes" + id ).b();
+					_e = _e.getAttributes().delete("timestamp" + id ).b();
+					int count = Integer.parseInt(id);
+						for (; _e.getAttributes().get("mes" + String.valueOf(count + 1)) != null; count++) {
+							_e = _e.getAttributes().put("mes" + count, _e.getAttributes().get("mes" + String.valueOf(count + 1))).b();
+							_e = _e.getAttributes().put("timestamp" + count, tBuffer).b();
+						}
+					_e = _e.getAttributes().delete("mes" + count ).b();
+					_e = _e.getAttributes().delete("timestamp" + count ).b();
+					return DefaultEither.newB(_e);
+				}
+			};
+			either = editor.edit(path, e);
+			if (either.isA()) {
+				throw new IllegalStateException();
+			}
+			editor = either.b();
+			either = editor.success();
+		} while (either.isA());
+	}
+		
+
 	
 	public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) {
 		requestCounter.incrementAndGet();
@@ -556,6 +597,4 @@
 
 	}
 
-
-
 }