net.scheinerman.graph
Class Vertex<E>

java.lang.Object
  extended by net.scheinerman.graph.Vertex<E>

public class Vertex<E>
extends java.lang.Object

A vertex represents a node in a graph object. It has an associated integer value, and edges to other vertices.

Since:
1.6
Version:
1.0
Author:
Jonah Scheinerman

Constructor Summary
Vertex()
          Creates a new Vertex object with no value.
Vertex(E data)
           
Vertex(E data, Location location)
           
Vertex(Location location)
          Creates a new Vertex object at a given Location.
 
Method Summary
 void addEdge(Edge<E> e)
          Adds the given edge to this vertex object.
Warning: this will not add the same edge to the other vertex.
 void addEdgeTo(Vertex<E> v)
          Creates a new Edge object which connects this vertex to a given vertex.
 boolean equals(Vertex<E> obj)
          Tests if the location of the two vertices are the same.
 java.util.Set<Vertex<E>> getConnectedVertices()
          Returns a set of all vertices that are connected to this vertex via edges.
 E getData()
           
 java.util.ArrayList<Edge<E>> getEdges()
          Returns an array of all edges that this vertex connects to.
 Edge<E> getEdgeTo(Vertex<E> v)
          Returns the edge object with which this vertex connects to a given vertex.
 Location getLocation()
          This vertex's current location
 java.util.ArrayList<Vertex<E>> getNeighbors()
          Returns all the neighbors of this vertex.
 Vertex<E> getOtherEnd(Edge<E> e)
          Given an edge, returns the vertex that is not equal to this vertex.
 int getValue()
          Returns the value associated with this object.
 boolean hasEdgeTo(Vertex<E> v)
          Tests whether this vertex has a connection to a given vertex.
 boolean isSelected()
          Returns whether this vertex has been graphical selected.
 boolean isVisited()
          Returns whether this vertex has been visited during a traversal.
 void removeAllEdges()
          Removes all edges from this vertex object, but not from the vertices they connect to.
 void removeEdgeTo(Vertex<E> v)
          If there is an edge to the given vertex, it is removed from this vertex.
Warning: This method should called from both vertex objects.
 void setData(E data)
           
 void setLocation(Location location)
          Sets a new location for this vertex object.
 void setSelected(boolean isSelected)
          Changes the status of this objects selection for graphical interfaces.
 void setValue(int value)
          Sets a new integer value for this vertex.
 void setVisited(boolean isVisited)
          Sets this vertex as visited or unvisited for use in a traversal.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vertex

public Vertex()
Creates a new Vertex object with no value.


Vertex

public Vertex(E data)

Vertex

public Vertex(Location location)
Creates a new Vertex object at a given Location.

Parameters:
location - - the location at which to create the vertex.

Vertex

public Vertex(E data,
              Location location)
Method Detail

addEdge

public void addEdge(Edge<E> e)
Adds the given edge to this vertex object.
Warning: this will not add the same edge to the other vertex. This method is not recommended. Instead use: addEdgeTo(Vertex).

Parameters:
e -

addEdgeTo

public void addEdgeTo(Vertex<E> v)
Creates a new Edge object which connects this vertex to a given vertex.

Parameters:
v - - the vertex to connect the one to.

equals

public boolean equals(Vertex<E> obj)
Tests if the location of the two vertices are the same.

Parameters:
v - - another vertex
Returns:
true if locations are equal, false otherwise.

getData

public E getData()

getEdges

public java.util.ArrayList<Edge<E>> getEdges()
Returns an array of all edges that this vertex connects to.

Returns:
an array list of edges.

getConnectedVertices

public java.util.Set<Vertex<E>> getConnectedVertices()
Returns a set of all vertices that are connected to this vertex via edges.

Returns:
the set of all connected vertices

getEdgeTo

public Edge<E> getEdgeTo(Vertex<E> v)
Returns the edge object with which this vertex connects to a given vertex. If no such edge exists, null is returned.

Parameters:
v - - another vertex.
Returns:
the edge connecting the two vertices.

getLocation

public Location getLocation()
This vertex's current location

Returns:
a Location object for this vertex.

getNeighbors

public java.util.ArrayList<Vertex<E>> getNeighbors()
Returns all the neighbors of this vertex.

Returns:
a list of neighbors.

getOtherEnd

public Vertex<E> getOtherEnd(Edge<E> e)
Given an edge, returns the vertex that is not equal to this vertex.

Parameters:
e - - an edge
Returns:
the other end of the edge.

getValue

public int getValue()
Returns the value associated with this object.

Returns:
an integer value.

hasEdgeTo

public boolean hasEdgeTo(Vertex<E> v)
Tests whether this vertex has a connection to a given vertex.

Parameters:
v - - another vertex
Returns:
true if there is a connection, false otherwise.

isSelected

public boolean isSelected()
Returns whether this vertex has been graphical selected. Note: This method is only for graphical purposes, do not use otherwise.

Returns:
true if selected, false otherwise.

isVisited

public boolean isVisited()
Returns whether this vertex has been visited during a traversal. Note: Used only for traversal purposes, do not use otherwise.

Returns:
true if it has been visited, false otherwise.

removeEdgeTo

public void removeEdgeTo(Vertex<E> v)
If there is an edge to the given vertex, it is removed from this vertex.
Warning: This method should called from both vertex objects. If not, the other vertex will retain an edge to this vertex.

Parameters:
v - - another vertex

removeAllEdges

public void removeAllEdges()
Removes all edges from this vertex object, but not from the vertices they connect to.


setData

public void setData(E data)

setLocation

public void setLocation(Location location)
Sets a new location for this vertex object.

Parameters:
location - - a new Location

setSelected

public void setSelected(boolean isSelected)
Changes the status of this objects selection for graphical interfaces. Note: This is only for use for graphical purposes, do not use otherwise.

Parameters:
isSelected - - a new selection value

setValue

public void setValue(int value)
Sets a new integer value for this vertex.

Parameters:
value - - new integer value.

setVisited

public void setVisited(boolean isVisited)
Sets this vertex as visited or unvisited for use in a traversal. Note: Used only for traversal purposes, do not use otherwise.

Parameters:
isVisited -