view src/main/java/alice/datasegment/CommandType.java @ 345:8f71c3e6f11d

Change directory structure Maven standard
author sugi
date Wed, 16 Apr 2014 18:26:07 +0900
parents
children aefbe41fcf12
line wrap: on
line source

package alice.datasegment;

import java.util.HashMap;

public enum CommandType {
	PUT,
	UPDATE, // remove a DataSegment value and put
	PEEK,
	TAKE,
	REMOVE,
	REPLY,
	CLOSE,
	FINISH, 
	PING,
	RESPONSE;
	
	public int id;
	public static HashMap<Integer, CommandType> hash = new HashMap<Integer, CommandType>();
	private static int lastId = 0;
	
	private CommandType(int id) {
		this.id = id;
		setLastId(id);
	}
	
	private CommandType() {
		this.id = incrementLastId();
	}
	
	private void setLastId(int id) {
		lastId =id;
	}
	
	private int incrementLastId() {
		return ++lastId;
	}
	
	public static CommandType getCommandTypeFromId(int id) {
		return hash.get(id);
	}
	
	static {
		for (CommandType type : CommandType.values()) {
			hash.put(type.id, type);
		}
	}
	
}