view src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java @ 190:a01507a9f826 default tip

change TreeMapBenchMark
author tatsuki
date Tue, 21 Apr 2015 17:28:20 +0900
parents e26462a38ce0
children
line wrap: on
line source

package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger;

import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.ReplaceRootNodeOperation;
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;


public class LoggingNode
{
  
  private final TreeNode wrap;
  private final OperationLog log;
  
	public LoggingNode(TreeNode _wrap)
	{
		this(_wrap,new DefaultOperationLog());
	}
	
	public LoggingNode(TreeNode _wrap,OperationLog _log)
	{
		wrap = _wrap;
		log = _log;
	}
	
	public LoggingAttributes getAttributes()
	{
		return new LoggingAttributes(wrap,log);
	}
	
	public LoggingChildren getChildren()
	{
		return new LoggingChildren(wrap,log);
	}
	

	public OperationLog getOperationLog()
	{
		return log;
	}
	

  public Either<Error, LoggingNode> replaceNewRootNode() {
   NodeOperation replaceRootNode = new ReplaceRootNodeOperation();
   return edit(replaceRootNode);
  }

  public Either<Error, LoggingNode> edit(NodeOperation op){
    Either<Error,TreeNode> either = op.invoke(wrap);
    if(either.isA()){
      return DefaultEither.newA(either.a());
    }
    
    TreeNode newWrap = either.b();
    OperationLog newLog = log.add(op);
    LoggingNode newLoggingNode = new LoggingNode(newWrap,newLog);
    return DefaultEither.newB(newLoggingNode);
  }
  
  public TreeNode getWrap()
  {
    return wrap;
  }
}