view src/alice/jungle/operations/NetworkTreeOperation.java @ 79:5b9708d9febc

Modified NetworkTreeOperationLog NetworkNodeOperation
author one
date Wed, 16 Oct 2013 19:25:02 +0900
parents 2dba7e1cf9fa
children b9dd8ec0e66e
line wrap: on
line source

package alice.jungle.operations;

import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;

import org.msgpack.annotation.Message;

@Message
public class NetworkTreeOperation implements TreeOperation {

	public NetworkNodePath path;
	public NetworkNodeOperation operation;
	
	public NetworkTreeOperation() {
		path = null;
		operation = null;
	}
	
	public NetworkTreeOperation(TreeOperation treeOp) {
		path = new NetworkNodePath(treeOp.getNodePath());
		operation = new NetworkNodeOperation(treeOp.getNodeOperation());
	}
	
	public NetworkTreeOperation(NodePath _p, NodeOperation _op) {
		path = new NetworkNodePath(_p);
		operation = new NetworkNodeOperation(_op);
	}

	public NetworkTreeOperation(NetworkNodePath _p, NodeOperation _op) {
		path = _p;
		operation = new NetworkNodeOperation(_op);
	}

	public NetworkTreeOperation(NetworkNodePath _p, NetworkNodeOperation _op) {
		path = _p;
		operation = _op;
	}
	
	@Override
	public NodePath getNodePath() {
		return path;
	}
	
	@Override
	public NodeOperation getNodeOperation() {
		Command c = operation.getCommand();
		switch(c) {
		case PUT_ATTRIBUTE:
			return new PutAttributeOperation(operation.getKey(), operation.getValue());
		case APPEND_CHILD:
			return new AppendChildAtOperation(operation.getPosition());
		case DELETE_CHILD:
			return new DeleteChildAtOperation(operation.getPosition());
		case DELETE_ATTRIBUTE:
			return new DeleteAttributeOperation(operation.getKey());
		default:
			break;
		}
		return null;
	}
	
}