view src/alice/test/dpp/datasegment/Fork.java @ 32:b4a700fd1bd8 draft default tip

move some files
author one
date Tue, 29 Jan 2013 17:33:35 +0900
parents 80023cb92594
children
line wrap: on
line source

package alice.test.dpp.datasegment;

import org.msgpack.annotation.Message;
import org.msgpack.annotation.MessagePackOrdinalEnum;

@Message
public class Fork {


	private String forkName;
	private String owner;
	private State state;

	private final String TABLE = "TABLE";

	@MessagePackOrdinalEnum
	public enum State {
		ON_THE_TABLE,
		IN_THE_HAND;
	}

	public Fork() {}
	
	public Fork(String n) {
		forkName = n;
		owner = TABLE;
		state = State.ON_THE_TABLE;
	}

	public State getState() {
		return state;
	}

	public String getForkName() {
		return forkName;
	}

	public boolean takeFork(String pName) {
		if (state == State.ON_THE_TABLE) {
			state = State.IN_THE_HAND;
			owner = pName;
			return true;
		} else {
			return false;
		}
	}
	
	public boolean onTheTable(String pName) {
		if (owner.equals(pName)) {
			state = State.ON_THE_TABLE;
			owner = TABLE;
			return true;
		} else {
			return false;
		}
	}
	
	public boolean ownerEquals(String s) {
		return owner.equals(s);
	}
	
	public String getOwner() {
		return owner;
	}

	
}