package traffic.graph;
/**
 * Jonathan Ramaswamy
 * GraphNode
 * GraphNode represents the nodes that make up the graph
 */
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import traffic.strategy.SpeedStrategy;


public class GraphNode {
	
	private Set<GraphNode> outgoing; //Nodes that this node has an edge directed towards
	private int nodeNum; //The number of this node on the graph
	private List<Integer> cars; //The cars at this node
	private SpeedStrategy ss; //The strategy by which the speed changes
	private int delay; //The basic delay of this node. To be modified by the speed strategy
	
	/**
	 * Creates a node with delay 1.
	 * @param n
	 * @param s
	 */
	public GraphNode(int n, SpeedStrategy s) {
		this(n, s, 1);
	}
	
	public GraphNode(int n, SpeedStrategy s, int delay ) {
		nodeNum = n;
		outgoing = new HashSet<GraphNode>();
		cars = new ArrayList<Integer>();
		ss = s;
		this.delay = delay;
	}
		
	public void addEdge( GraphNode to ) {
		if ( to == null ) return;
		outgoing.add( to );
	}
	
	public void removeEdge( GraphNode to ) {
		outgoing.remove( to );
	}
	
	/**
	 * Returns all nodes this node has an edge directed towards
	 */
	public List<GraphNode> getNeighbors() {
		return new ArrayList<GraphNode>(outgoing);
	}
	
	/**
	 * Adds the given car number to the list of cars currently at the node
	 * Changes the speed limit at the node
	 */
	public void addCar(int i) {
		cars.add(i);
	}
	
	/**
	 * Removes the given car from the list of cars at this node
	 * Changes the speed limit at the node
	 */
	public void removeCar(int i) {
		cars.remove(cars.indexOf(i));
	}
	
	/**
	 * Returns the number of turns a car must stay limited at this node
	 */
	public int getDelay() {
		return delay;
	}
	
	public int getCurrentDelay() {
		return delay + ss.getDelay( cars.size() );
	}
	
	/**
	 * Returns the number of cars currently at this node
	 */
	public int numCarsAtNode() {
		return cars.size();
	}

	public int getID() {
		return nodeNum;
	}

	/**
	 * @return the ss
	 */
	public SpeedStrategy getSpeedStrategy() {
		return ss;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return nodeNum;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GraphNode other = (GraphNode) obj;
		if (nodeNum != other.nodeNum)
			return false;
		return true;
	}

	/**
	 * @return the cars
	 */
	public List<Integer> getCars() {
		return cars;
	}
}

@@ -1001,12 +1001,160 @@
 %09%7D%0D%0A
+%09%0D%0A%09/* ***************************************************%0D%0A%09 * GRAPH MANAGEMENT METHODS%0D%0A%09 *************************************************** */%0D%0A
 %09%09%0D%0A
-
 %09pub
@@ -1485,32 +1485,414 @@
 going);%0D%0A%09%7D%0D%0A%09%0D%0A
+%09public int getID() %7B%0D%0A%09%09return nodeNum;%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * @return the ss%0D%0A%09 */%0D%0A%09public SpeedStrategy getSpeedStrategy() %7B%0D%0A%09%09return ss;%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * @return the cars%0D%0A%09 */%0D%0A%09public List%3CInteger%3E getCars() %7B%0D%0A%09%09return cars;%0D%0A%09%7D%0D%0A%0D%0A%09/* ***************************************************%0D%0A%09 * TRAFFIC MANAGEMENT METHODS%0D%0A%09 *************************************************** */%0D%0A
 %09/**%0D%0A%09 * Adds t
@@ -2589,152 +2589,9 @@
 %09%7D%0D%0A
-%0D%0A%09public int getID() %7B%0D%0A%09%09return nodeNum;%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * @return the ss%0D%0A%09 */%0D%0A%09public SpeedStrategy getSpeedStrategy() %7B%0D%0A%09%09return ss;%0D%0A%09%7D%0D%0A
+%09
 %0D%0A%09/
@@ -3060,16 +3060,16 @@
 false;%0D%0A
+
 %09%09return
@@ -3083,99 +3083,8 @@
 %0A%09%7D%0D
-%0A%0D%0A%09/**%0D%0A%09 * @return the cars%0D%0A%09 */%0D%0A%09public List%3CInteger%3E getCars() %7B%0D%0A%09%09return cars;%0D%0A%09%7D%0D
 %0A%7D%0D%0A

Reorganize and comment GraphNode methods.