JBoss Common Classes 2.2.17.GA

org.jboss.util.graph
Class Vertex<T>

java.lang.Object
  extended by org.jboss.util.graph.Vertex<T>
Type Parameters:
T -

public class Vertex<T>
extends Object

A named graph vertex with optional data.

Version:
$Revision$
Author:
Scott.Stark@jboss.org, Ales.Justin@jboss.org

Constructor Summary
Vertex()
          Calls this(null, null).
Vertex(String n)
          Create a vertex with the given name and no data
Vertex(String n, T data)
          Create a Vertex with name n and given data
 
Method Summary
 boolean addEdge(Edge<T> e)
          Add an edge to the vertex.
 void addIncomingEdge(Vertex<T> from, int cost)
          Add an incoming edge starting at from
 void addOutgoingEdge(Vertex<T> to, int cost)
          Add an outgoing edge ending at to.
 void clearMark()
          Clear the visited mark flag.
 int cost(Vertex<T> dest)
          What is the cost from this vertext to the dest vertex.
 Edge<T> findEdge(Edge<T> e)
          Search the outgoing edges for a match to e.
 Edge<T> findEdge(Vertex<T> dest)
          Search the outgoing edges looking for an edge whose's edge.to == dest.
 T getData()
           
 Edge<T> getIncomingEdge(int i)
          Get the ith incoming edge
 int getIncomingEdgeCount()
           
 List getIncomingEdges()
          Get the incoming edges
 int getMarkState()
          Get the mark state value.
 String getName()
           
 Edge<T> getOutgoingEdge(int i)
          Get the ith outgoing edge
 int getOutgoingEdgeCount()
           
 List getOutgoingEdges()
          Get the outgoing edges
 boolean hasEdge(Edge<T> e)
          Check the vertex for either an incoming or outgoing edge mathcing e.
 boolean hasEdge(Vertex<T> dest)
          Is there an outgoing edge ending at dest.
 void mark()
          Set the vertex mark flag.
 boolean remove(Edge<T> e)
          Remove an edge from this vertex
 void setData(T data)
           
 void setMarkState(int state)
          Set the mark state to state.
 String toString()
           
 void visit()
          Visit the vertex and set the mark flag to true.
 boolean visited()
          Has this vertex been marked during a visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vertex

public Vertex()
Calls this(null, null).


Vertex

public Vertex(String n)
Create a vertex with the given name and no data

Parameters:
n -

Vertex

public Vertex(String n,
              T data)
Create a Vertex with name n and given data

Parameters:
n - - name of vertex
data - - data associated with vertex
Method Detail

getName

public String getName()
Returns:
the possibly null name of the vertex

getData

public T getData()
Returns:
the possibly null data of the vertex

setData

public void setData(T data)
Parameters:
data - The data to set.

addEdge

public boolean addEdge(Edge<T> e)
Add an edge to the vertex. If edge.from is this vertex, its an outgoing edge. If edge.to is this vertex, its an incoming edge. If neither from or to is this vertex, the edge is not added.

Parameters:
e - - the edge to add
Returns:
true if the edge was added, false otherwise

addOutgoingEdge

public void addOutgoingEdge(Vertex<T> to,
                            int cost)
Add an outgoing edge ending at to.

Parameters:
to - - the destination vertex
cost - the edge cost

addIncomingEdge

public void addIncomingEdge(Vertex<T> from,
                            int cost)
Add an incoming edge starting at from

Parameters:
from - - the starting vertex
cost - the edge cost

hasEdge

public boolean hasEdge(Edge<T> e)
Check the vertex for either an incoming or outgoing edge mathcing e.

Parameters:
e - the edge to check
Returns:
true it has an edge

remove

public boolean remove(Edge<T> e)
Remove an edge from this vertex

Parameters:
e - - the edge to remove
Returns:
true if the edge was removed, false if the edge was not connected to this vertex

getIncomingEdgeCount

public int getIncomingEdgeCount()
Returns:
the count of incoming edges

getIncomingEdge

public Edge<T> getIncomingEdge(int i)
Get the ith incoming edge

Parameters:
i - the index into incoming edges
Returns:
ith incoming edge

getIncomingEdges

public List getIncomingEdges()
Get the incoming edges

Returns:
incoming edge list

getOutgoingEdgeCount

public int getOutgoingEdgeCount()
Returns:
the count of incoming edges

getOutgoingEdge

public Edge<T> getOutgoingEdge(int i)
Get the ith outgoing edge

Parameters:
i - the index into outgoing edges
Returns:
ith outgoing edge

getOutgoingEdges

public List getOutgoingEdges()
Get the outgoing edges

Returns:
outgoing edge list

findEdge

public Edge<T> findEdge(Vertex<T> dest)
Search the outgoing edges looking for an edge whose's edge.to == dest.

Parameters:
dest - the destination
Returns:
the outgoing edge going to dest if one exists, null otherwise.

findEdge

public Edge<T> findEdge(Edge<T> e)
Search the outgoing edges for a match to e.

Parameters:
e - - the edge to check
Returns:
e if its a member of the outgoing edges, null otherwise.

cost

public int cost(Vertex<T> dest)
What is the cost from this vertext to the dest vertex.

Parameters:
dest - - the destination vertex.
Returns:
Return Integer.MAX_VALUE if we have no edge to dest, 0 if dest is this vertex, the cost of the outgoing edge otherwise.

hasEdge

public boolean hasEdge(Vertex<T> dest)
Is there an outgoing edge ending at dest.

Parameters:
dest - - the vertex to check
Returns:
true if there is an outgoing edge ending at vertex, false otherwise.

visited

public boolean visited()
Has this vertex been marked during a visit

Returns:
true is visit has been called

mark

public void mark()
Set the vertex mark flag.


setMarkState

public void setMarkState(int state)
Set the mark state to state.

Parameters:
state - the state

getMarkState

public int getMarkState()
Get the mark state value.

Returns:
the mark state

visit

public void visit()
Visit the vertex and set the mark flag to true.


clearMark

public void clearMark()
Clear the visited mark flag.


toString

public String toString()
Overrides:
toString in class Object
Returns:
a string form of the vertex with in and out edges.

JBoss Common Classes 2.2.17.GA

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.