comparison 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
comparison
equal deleted inserted replaced
169:54d68cda84c4 170:2403b9a4416f
354 } 354 }
355 355
356 JungleTreeEditor editor = tree.getTreeEditor(); 356 JungleTreeEditor editor = tree.getTreeEditor();
357 NodeEditor e = new NodeEditor() { 357 NodeEditor e = new NodeEditor() {
358 public <T extends EditableNode<T>> Either<Error, T> edit(T _e) { 358 public <T extends EditableNode<T>> Either<Error, T> edit(T _e) {
359 // EnableNodeWrapper<T> node = _e.getWrap();
360 String str = "0"; 359 String str = "0";
361 int count = 0; 360 int count = 0;
362 for (; _e.getAttributes().get("mes" + String.valueOf(count)) != null; count++) { 361 for (; _e.getAttributes().get("mes" + String.valueOf(count)) != null; count++) {
363 } 362 }
364 str = String.valueOf(count); 363 str = String.valueOf(count);
408 } 407 }
409 editor = either.b(); 408 editor = either.b();
410 either = editor.success(); 409 either = editor.success();
411 } while (either.isA()); 410 } while (either.isA());
412 } 411 }
412
413 public void deleteAttribute(String _board, String _path ,final String id) {
414 requestCounter.incrementAndGet();
415 final long timestamp = System.currentTimeMillis();
416 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
417 tBuffer.putLong(timestamp);
418 JungleTree tree = jungle.getTreeByName(_board);
419 Either<Error, JungleTreeEditor> either = null;
420 DefaultNodePath path = new DefaultNodePath();
421 do {
422 try {
423 for (int count = 0; _path.substring(count, count + 1) != null; count++) {
424 if (!_path.substring(count, count + 1).equals("/"))
425 path = path.add(Integer.parseInt(_path.substring(count, count + 1)));
426 }
427 } catch (Exception _e) {
428 }
429
430 JungleTreeEditor editor = tree.getTreeEditor();
431 NodeEditor e = new NodeEditor() {
432 public <T extends EditableNode<T>> Either<Error, T> edit(T _e) {
433 _e = _e.getAttributes().delete("mes" + id ).b();
434 _e = _e.getAttributes().delete("timestamp" + id ).b();
435 int count = Integer.parseInt(id);
436 for (; _e.getAttributes().get("mes" + String.valueOf(count + 1)) != null; count++) {
437 _e = _e.getAttributes().put("mes" + count, _e.getAttributes().get("mes" + String.valueOf(count + 1))).b();
438 _e = _e.getAttributes().put("timestamp" + count, tBuffer).b();
439 }
440 _e = _e.getAttributes().delete("mes" + count ).b();
441 _e = _e.getAttributes().delete("timestamp" + count ).b();
442 return DefaultEither.newB(_e);
443 }
444 };
445 either = editor.edit(path, e);
446 if (either.isA()) {
447 throw new IllegalStateException();
448 }
449 editor = either.b();
450 either = editor.success();
451 } while (either.isA());
452 }
453
413 454
414 455
415 public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) { 456 public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) {
416 requestCounter.incrementAndGet(); 457 requestCounter.incrementAndGet();
417 final long timestamp = System.currentTimeMillis(); 458 final long timestamp = System.currentTimeMillis();
554 return uuid; 595 return uuid;
555 } 596 }
556 597
557 } 598 }
558 599
559
560
561 } 600 }