/**
 * Vertex class containing a map of other vertices to edge data.
 * 
 */
package com.codemelon.graph.vertex;
import java.util.Enumeration;
import java.util.concurrent.ConcurrentHashMap;

import com.codemelon.graph.common.Color;
import com.codemelon.graph.common.EdgeData;

/**
 * @author Marshall Farrier
 * @version 11-23-2012
 */
public class Vertex {
	private ConcurrentHashMap<Vertex, EdgeData> adjacencies;
	public int label;
	public Color color;
	public Vertex parent;
	public int distance;	// for BFS, etc.
	// for DFS
	public int discoveryTime;
	public int finishTime;
	public int treeNumber;	// to identify components after DFS
	
	public Vertex() {
		this(VertexConstants.INITIAL_COLOR);
	}
	public Vertex(int label) {
		this(label, VertexConstants.INITIAL_COLOR, null, VertexConstants.INITIAL_DISTANCE, 
				VertexConstants.INITIAL_DISCOVERY_TIME, 
				VertexConstants.INITIAL_FINISH_TIME,
				VertexConstants.INITIAL_TREE_NUMBER);
	}
	public Vertex(Color color) {
		this(VertexConstants.DEFAULT_LABEL, color, null, VertexConstants.INITIAL_DISTANCE, 
				VertexConstants.INITIAL_DISCOVERY_TIME, 
				VertexConstants.INITIAL_FINISH_TIME,
				VertexConstants.INITIAL_TREE_NUMBER);
	}
	public Vertex(int label, Color color, Vertex parent, int distance, int discoveryTime,
			int finishTime, int treeNumber) {
		adjacencies = new ConcurrentHashMap<Vertex, EdgeData>();
		this.label = label;
		this.color = color;
		this.parent = parent;
		this.distance = distance;
		this.discoveryTime = discoveryTime;
		this.finishTime = finishTime;
		this.treeNumber = treeNumber;
	}
	/**
	 * Copy constructor. Copies all satellite data but leaves adjacency list
	 * and parent of new vertex empty or, in the case of parent, null.
	 * @param v vertex to be copied
	 */
	public Vertex(Vertex v) {
		this(v, null);
	}
	/**
	 * Copies all satellite data from vertexToCopy and assigns vertexParent
	 * as parent. Adjacency list is empty on initialization
	 * @param vertexToCopy vertex from which to copy satellite data
	 * @param vertexParent parent to assign to new vertex
	 */
	public Vertex(Vertex vertexToCopy, Vertex vertexParent) {
		this(vertexToCopy.label, vertexToCopy.color, vertexParent, vertexToCopy.distance, 
				vertexToCopy.discoveryTime, vertexToCopy.finishTime, 
				vertexToCopy.treeNumber);		
	}
	
	/**
	 * Adds the specified vertex to the set of adjacencies
	 * @param v vertex to be added
	 * @return true if the adjacency list did not already contain v
	 */
	public boolean addAdjacency(Vertex v) {
		if (adjacencies.containsKey(v)) { return false; }
		adjacencies.put(v, new EdgeData());
		return true;
	}
	
	/**
	 * Removes the specified vertex from the adjacency set
	 * @param v vertex to be removed
	 * @return true if the vertex was found in the adjacency set
	 */
	public boolean removeAdjacency(Vertex v) {
		if (!adjacencies.containsKey(v)) { return false; }
		adjacencies.remove(v);
		return true;
	}
	
	/**
	 * Removes all vertices from the adjacency set. The adjacency set will be
	 * empty after this call returns.
	 */
	public void clearAdjacencies() {
		adjacencies.clear();
	}
	 
	/**
	 * Returns true if the adjacency set contains the specified vertex
	 * @param v vertex whose presence is to be tested
	 * @return true if v is found in the adjacency set
	 */
	public boolean containsAdjacency(Vertex v) {
		return adjacencies.containsKey(v);
	}
	
	public boolean containsAdjacency(int label) {
		Enumeration<Vertex> adjacencyEnumeration = adjacencies.keys();
		while (adjacencyEnumeration.hasMoreElements()) {
			if (adjacencyEnumeration.nextElement().label == label) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Returns the number of vertices in the adjacency set
	 * @return the number of vertices in this adjacency set (its cardinality)
	 */
	public int adjacencyCount() {
		return adjacencies.size();
	}
	
	public Enumeration<Vertex> getAdjacencies() {
		return adjacencies.keys();
	}

	/**
	 * Returns true if the adjacency is non-empty.
	 * @return true if the adjacency is non-empty.
	 */
	public boolean hasAdjacencies() {
		return !adjacencies.isEmpty();
	}
}

@@ -348,16 +348,46 @@
 s Vertex
+ implements Comparable%3CVertex%3E
  %7B%0A%09priv
@@ -4137,10 +4137,181 @@
 y();%0A%09%7D%0A
+%09@Override%0A%09public int compareTo(Vertex v) %7B%0A%09%09return this.label - v.label;%0A%09%7D%0A%09@Override%0A%09public boolean equals(Object o) %7B%0A%09%09return this.label == ((Vertex) o).label;%0A%09%7D%0A
 %7D%0A

Add compareTo() and equals() methods for vertices