package classes;

import java.util.ArrayList;
import java.util.HashMap;

public class CpsUpperNode extends AbstractCpsObject {

	private ArrayList<AbstractCpsObject> nodes;
	private ArrayList<CpsEdge> nodeEdges;
	private ArrayList<CpsEdge> oldEdges;
	private HashMap<Integer, Integer> nodesIdx;

	public CpsUpperNode(String nodeName) {
		super(nodeName);
		this.setConnections(new ArrayList<CpsEdge>());
		this.setImage("/Images/upper_node.png");
		this.setSav("CVS");
		this.setID(IdCounter.nextId());
		this.setNodes(new ArrayList<AbstractCpsObject>());
		this.setNodeEdges(new ArrayList<CpsEdge>());
		this.setOldEdges(new ArrayList<CpsEdge>());
		this.setNodesIdx(new HashMap<Integer, Integer>());
		// TODO Auto-generated constructor stub
	}

	/**
	 * @return the nodes
	 */
	public ArrayList<AbstractCpsObject> getNodes() {
		return nodes;
	}

	/**
	 * @param nodes
	 *            the nodes to set
	 */
	public void setNodes(ArrayList<AbstractCpsObject> nodes) {
		this.nodes = nodes;
	}

	/**
	 * @return the nodeEdges
	 */
	public ArrayList<CpsEdge> getNodeEdges() {
		return nodeEdges;
	}

	/**
	 * @param nodeEdges
	 *            the nodeEdges to set
	 */
	public void setNodeEdges(ArrayList<CpsEdge> nodeEdges) {
		this.nodeEdges = nodeEdges;
	}

	/**
	 * @return the oldEdges
	 */
	public ArrayList<CpsEdge> getOldEdges() {
		return oldEdges;
	}

	/**
	 * @param oldEdges
	 *            the oldEdges to set
	 */
	public void setOldEdges(ArrayList<CpsEdge> oldEdges) {
		this.oldEdges = oldEdges;
	}

	/**
	 * @return the nodesIdx
	 */
	public HashMap<Integer, Integer> getNodesIdx() {
		return nodesIdx;
	}

	/**
	 * @param nodesIdx
	 *            the nodesIdx to set
	 */
	public void setNodesIdx(HashMap<Integer, Integer> nodesIdx) {
		this.nodesIdx = nodesIdx;
	}

	public ArrayList<HolonObject> getNumHolonObj() {
		ArrayList<HolonObject> onlyHolonObj = new ArrayList<HolonObject>();
		for (AbstractCpsObject temp : getNodes()) {
			if (temp instanceof HolonObject) {
				onlyHolonObj.add((HolonObject) temp);
			}
		}
		return onlyHolonObj;
	}

	public ArrayList<HolonSwitch> getNumSwitches() {
		ArrayList<HolonSwitch> onlySwitsches = new ArrayList<HolonSwitch>();
		for (AbstractCpsObject temp : getNodes()) {
			if (temp instanceof HolonSwitch) {
				onlySwitsches.add((HolonSwitch) temp);
			}
		}
		return onlySwitsches;
	}

	public ArrayList<CpsUpperNode> getNumUpperNodes() {
		ArrayList<CpsUpperNode> onlyUpperNodes = new ArrayList<CpsUpperNode>();
		for (AbstractCpsObject temp : getNodes()) {
			if (temp instanceof CpsUpperNode) {
				onlyUpperNodes.add((CpsUpperNode) temp);
			}
		}
		return onlyUpperNodes;
	}

	public AbstractCpsObject searchObj(int ID) {
		AbstractCpsObject result = null;
		for (AbstractCpsObject obj : getNodes()) {
			if (obj.getID() == ID) {
				result = obj;
				break;
			}
		}
		return result;
	}

}
