Newer
Older
CactusServer / src / main / java / cactusServer / entities / Instance.java
r-isitani on 21 May 2018 1 KB enumのスペルミスの修正.
package cactusServer.entities;

import java.util.HashMap;
import java.util.HashSet;

import cactusServer.entities.Area.Allowed;
import cactusServer.entities.Object;
import framework.model3D.Position3D;
import framework.physics.AngularVelocity3D;
import framework.physics.Velocity3D;

/**
 * インスタンス
 * @author ryo isitani
 *
 */
public class Instance {
	private String name;
	private State state;
	private HashMap<String, Area> areaMap = new HashMap<>();
	private HashMap<String, Object> objMap = new HashMap<>();
	
	/**
	 * (引数は現時点での仮のもの)
	 * @param name インスタンス名
	 */
	public Instance(String name, State state) {
		this.name = name;
		this.state = state;
	}

	public String getName() {
		return name;
	}
	
	public State getState() {
		return state;
	}
	
	public HashMap<String, Area> getAreaMap() {
		return areaMap;
	}
	
	public Area getArea(String areaId) {
		return areaMap.get(areaId);
	}
	
	public HashMap<String, Object> getObjMap() {
		return objMap;
	}
	
	public Object getObject(String objId) {
		return objMap.get(objId);
	}
	
	public void setState(State state) {
		this.state = state;
	}
	
	public Area createArea(String areaId, String name, Plain[] regions, HashSet<Allowed> permissions) {
		if (areaMap.containsKey(areaId)) {
			return null;
		}
		Area area = new Area(name, regions, permissions);
		areaMap.put(areaId, area);
		return area;
	}
	
	public Object createObject(String objId, Position3D position, Velocity3D velocity, AngularVelocity3D angularVelocity) {
		if (objMap.containsKey(objId)) {
			return null;
		}
		Object object = new Object(position, velocity, angularVelocity);
		objMap.put(objId, object);
		return object;
	}
	
	public Area removeArea(String areaId) {
		return areaMap.remove(areaId);
	}
	
	public Object removeObject(String objId) {
		return objMap.remove(objId);
	}
	
	public static enum State {
		AVAILABLE, MAINTENANCE;
	}
}