fi.joensuu.cs.tra
Class Vertex

java.lang.Object
  extended by fi.joensuu.cs.tra.Vertex
All Implemented Interfaces:
Comparable, Iterable

public class Vertex
extends Object
implements Comparable, Iterable

Vertices are objects that are connected to other vertices by Edges to form a graph.

See Also:
Edge, Graph, DiGraph

Nested Class Summary
 class Vertex.EdgeIteratorWrapper
           
 class Vertex.NeighborIteratorWrapper
           
 
Method Summary
 Edge addEdge(Vertex vertex)
          Attaches a new Edge between this Vertex and the specified one.
 Edge addEdge(Vertex vertex, float weight)
          Attaches a new Edge between this Vertex and the specified one.
 Edge addEdge(Vertex vertex, int color)
          Attaches a new Edge between this Vertex and the specified one.
 Edge addEdge(Vertex vertex, int color, float weight)
          Attaches a new Edge between this Vertex and the specified one.
 Edge addEdge(Vertex vertex, String label)
          Attaches a new Edge between this Vertex and the specified one.
 Edge addEdge(Vertex vertex, String label, int color)
          Attaches a new Edge between this Vertex and the specified one.
 Edge addEdge(Vertex vertex, String label, int color, float weight)
          Attaches a new Edge between this Vertex and the specified one.
 int compareTo(Object o)
          Defined in Comparable.
 Iterator<Edge> edgeIterator()
          Returns an Iterator over the Edges attached to this Vertex.
 Iterable<Edge> edges()
          Returns an Iterable over this Vertex's Edges that can be used in a foreach construct.
 int getColor()
          Gets this Vertex's color.
 Edge getEdge(Vertex destination)
          Returns the edge from this Vertex to the specified one or null if one doesn't exist.
 int getIndex()
          Gets this Vertex's index.
 String getLabel()
          Gets this Vertex's label.
 float getWeight()
          Gets this Vertex's weight.
 boolean isAdjacent(Vertex vertex)
          Determines if the specified Vertex is adjacent to this one (whether they are connected with an Edge.)
 Iterator<Edge> iterator()
          Returns an Iterator over the Edges attached to this Vertex.
 Iterator<Vertex> neighborIterator()
          Returns an Iterator over this Vertex's neighbors.
 Iterable<Vertex> neighbors()
          Returns an Iterable over this Vertex's neighbors that can be used in a foreach construct.
 boolean removeEdge(Edge edge)
          Removes the specified Edge.
 void removeEdges()
          Removes all the Edges attached to this Vertex.
 int setColor(int color)
          Sets this Vertex's color.
 int setIndex(int index)
          Sets this Vertex's index.
 String setLabel(String label)
          Sets this Vertex's label.
 float setWeight(float weight)
          Sets this Vertex's weight.
 String toString()
          Returns a String representation of this Vertex.
 String toString(boolean neighborsToo)
          Returns a String representation of this Vertex and optionally its neighbors and their connecting Edges.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getLabel

public String getLabel()
Gets this Vertex's label.

Returns:
the current label.

setLabel

public String setLabel(String label)
Sets this Vertex's label.

Parameters:
label - the new label for this Vertex.
Returns:
this Vertex's old label

getColor

public int getColor()
Gets this Vertex's color.

Returns:
the current color

setColor

public int setColor(int color)
Sets this Vertex's color.

Parameters:
color - the new color for this Vertex
Returns:
this Vertex's old color

getIndex

public int getIndex()
Gets this Vertex's index.

Returns:
the current index

setIndex

public int setIndex(int index)
Sets this Vertex's index.

Parameters:
index - the new index for this Vertex
Returns:
this Vertex's old index

getWeight

public float getWeight()
Gets this Vertex's weight.

Returns:
the current weight

setWeight

public float setWeight(float weight)
Sets this Vertex's weight.

Parameters:
weight - the new weight for this Vertex
Returns:
this Vertex's old weight

compareTo

public int compareTo(Object o)
Defined in Comparable.

Specified by:
compareTo in interface Comparable

addEdge

public Edge addEdge(Vertex vertex,
                    String label,
                    int color,
                    float weight)
Attaches a new Edge between this Vertex and the specified one.

Parameters:
vertex - the endpoint of the new Edge
label - the label for the new Edge
color - the color for the new Edge
weight - the weight for the new Edge
Returns:
the new Edge
Throws:
GraphException - if color is negative,
destination vertex is null,
there already exists an Edge between the two nodes or
if the graph is not a DiGraph and the endpoint is this Vertex

addEdge

public Edge addEdge(Vertex vertex,
                    String label,
                    int color)
Attaches a new Edge between this Vertex and the specified one.

Parameters:
vertex - the endpoint of the new Edge
label - the label for the new Edge
color - the color for the new Edge
Returns:
the new Edge
Throws:
GraphException - if color is negative,
destination vertex is null,
there already exists an Edge between the two nodes or
if the graph is not a DiGraph and the endpoint is this Vertex

addEdge

public Edge addEdge(Vertex vertex,
                    String label)
Attaches a new Edge between this Vertex and the specified one.

Parameters:
vertex - the endpoint of the new Edge
label - the label for the new Edge
Returns:
the new Edge
Throws:
GraphException - if destination vertex is null,
there already exists an Edge between the two nodes or
if the graph is not a DiGraph and the endpoint is this Vertex

addEdge

public Edge addEdge(Vertex vertex)
Attaches a new Edge between this Vertex and the specified one.

Parameters:
vertex - the endpoint of the new Edge
Returns:
the new Edge
Throws:
GraphException - if destination vertex is null,
there already exists an Edge between the two nodes or
if the graph is not a DiGraph and the endpoint is this Vertex

addEdge

public Edge addEdge(Vertex vertex,
                    int color,
                    float weight)
Attaches a new Edge between this Vertex and the specified one.

Parameters:
vertex - the endpoint of the new Edge
color - the color for the new Edge
weight - the weight for the new Edge
Returns:
the new Edge
Throws:
GraphException - if color is negative,
destination vertex is null,
there already exists an Edge between the two nodes or
if the graph is not a DiGraph and the endpoint is this Vertex

addEdge

public Edge addEdge(Vertex vertex,
                    int color)
Attaches a new Edge between this Vertex and the specified one.

Parameters:
vertex - the endpoint of the new Edge
color - the color for the new Edge
Returns:
the new Edge
Throws:
GraphException - if color is negative,
destination vertex is null,
there already exists an Edge between the two nodes or
if the graph is not a DiGraph and the endpoint is this Vertex

addEdge

public Edge addEdge(Vertex vertex,
                    float weight)
Attaches a new Edge between this Vertex and the specified one.

Parameters:
vertex - the endpoint of the new Edge
weight - the weight for the new Edge
Returns:
the new Edge
Throws:
GraphException - if destination vertex is null,
there already exists an Edge between the two nodes or
if the graph is not a DiGraph and the endpoint is this Vertex

getEdge

public Edge getEdge(Vertex destination)
Returns the edge from this Vertex to the specified one or null if one doesn't exist.

Parameters:
destination - the Vertex and Edge leading to which is sought.
Returns:
an Edge leading to the specified Vertex or null if none exists.

iterator

public Iterator<Edge> iterator()
Returns an Iterator over the Edges attached to this Vertex.

Specified by:
iterator in interface Iterable
Returns:
an iterator over this Vertex's Edges.

edgeIterator

public Iterator<Edge> edgeIterator()
Returns an Iterator over the Edges attached to this Vertex.

Returns:
an iterator over this Vertex's Edges.

edges

public Iterable<Edge> edges()
Returns an Iterable over this Vertex's Edges that can be used in a foreach construct.

Returns:
an Iterable over this this Vertex's Edges

neighbors

public Iterable<Vertex> neighbors()
Returns an Iterable over this Vertex's neighbors that can be used in a foreach construct.

Returns:
an Iterable over this Vertex's neighbors

neighborIterator

public Iterator<Vertex> neighborIterator()
Returns an Iterator over this Vertex's neighbors.

Returns:
an iterator over this Vertex's neighbors

removeEdges

public void removeEdges()
Removes all the Edges attached to this Vertex.


removeEdge

public boolean removeEdge(Edge edge)
Removes the specified Edge.

Parameters:
edge - the Edge to remove
Returns:
true if the removal was succesful, false otherwise

isAdjacent

public boolean isAdjacent(Vertex vertex)
Determines if the specified Vertex is adjacent to this one (whether they are connected with an Edge.)

Parameters:
vertex - the Vertex to check
Returns:
true if vertex is adjacent to this one, false otherwise

toString

public String toString()
Returns a String representation of this Vertex.

Overrides:
toString in class Object
Returns:
a String representation of this Vertex

toString

public String toString(boolean neighborsToo)
Returns a String representation of this Vertex and optionally its neighbors and their connecting Edges.

Parameters:
neighborsToo - whether to recursively include the neighbours and the connecting Edges
Returns:
a String representation of this Vertex and optionally its neighbors and their connecting Edges