// Adapted from Carrano&Savitch, Data Structures and Abstractions With Java

import java.util.*;

public class Vertex {

    private Object label;     // labeling, as in numbering of verticies
    private LinkedList edges; // adjacent edges (edges emanating from vertex)
    private boolean visited;  // tag to indicate vertex was visited
    private int cost;         // cost to this node from a source (SSSP)
    private Vertex prev;      // previous node from path (SSSP)

    // Make new Vertex with no adjacencies:
    public Vertex(Object o) {
	label = o;
	edges = new LinkedList();
    }
    
    // Add edge with or without weight:
    public void addEdge(Vertex dest, int weight) {
	Vertex source = this;
	edges.add(new Edge(source,dest,weight));
    }
    public void addEdge(Vertex d) {
	addEdge(d,0);
    }

    // Add pre-made edge:
    public boolean addEdge(Edge e) {
	if (e.getSource()==this) {
	    edges.add(e);
	    return true;
	}
	return false;
    }

    // Equality for searching, detecting loops,...:
    public boolean equals(Vertex other) {
	return label.equals( ((Vertex)other).label );
    }

    // Stringify as just label:
    public String toString() { 
	return label.toString();
    }

    // Getters:
    public Collection getEdges() { return edges; }
    public Object getLabel() { return label; }

    // **** New ****
    public int getCost() { return cost; }
    public void setCost(int c) { cost=c; }
    public Vertex getPrev() { return prev; }
    public void setPrev(Vertex p) { prev = p; }
    public boolean hasPrev() { return prev !=null; }
    public void visit() { visited = true; }
    public void unvisit() { visited = false; }
    public boolean isVisited() { return visited; }

    // Return iterator on adjacent edges:
    public Iterator getEdgeIterator() { 
	return edges.iterator();
    }

}
      
