view src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transformer/NetworkAppendChildAt.java @ 265:b3a04bc21b23 Implementation_of_communication

add UnDefineNode
author tatsuki
date Tue, 13 Dec 2016 03:16:12 +0900
parents cac88cf813f1
children c62462c28807
line wrap: on
line source

package jp.ac.u_ryukyu.ie.cr.jungleNetwork.transformer;


/*
 * This code same AppendChildAt. 
 */

import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode;
import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode;
import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog;
import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor;
import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither;
import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
import jp.ac.u_ryukyu.ie.cr.jungle.util.Error;
import org.msgpack.annotation.Message;

@Message
public class NetworkAppendChildAt implements NodeEditor {

	private final int pos;
	
	public NetworkAppendChildAt(int _pos) {
		pos = _pos;
	}

	public Either<Error, LoggingNode> _edit(LoggingNode _e)
	{
		Either<Error,LoggingNode> either = _e.getChildren().addNewChildAt(pos);
		if(either.isA()){
			// error
			return either;
		}
		return DefaultEither.newB(either.b());
	}
	
	@Override
	public Either<Error, LoggingNode> edit(TreeNode _e) {
		LoggingNode logNode = wrap(_e);
		return _edit(logNode);
	}

	public LoggingNode wrap(TreeNode node) {
		return new LoggingNode(node);
	}

	@Override
	public LoggingNode wrap(TreeNode node, OperationLog op) {
		return new LoggingNode(node, op);
	}

}