Class Path

java.lang.Object
  |
  +--Path

public class Path
extends java.lang.Object

Class representing a path in a Graph as a sequence of connected nodes.

Author:
Dries.VanDyck@rug.ac.be
See Also:
NodeIterator

Constructor Summary
  Path()
          Creates a new empty Path.
protected Path(java.util.ArrayList nodes)
          Wraps a new Path object around this vector.
  Path(int[] apath)
          Creates a new Path representing apath[0]->..->apath[apath.length-1].
  Path(int i, int j)
          Creates a new path being the edge (i,j).
 
Method Summary
 void addBack(int node)
          Adds node node to the end of this Path.
 void addFront(int node)
          Adds node node to the end of this Path (O(length)).
 void append(Path p)
          Appends p to this path where appropriate.
 java.lang.Object clone()
          Implementation of the Cloneable interface.
 Path concat(Path p)
          Returns the concatenation of this path with the path p as a new Path object.
 NodeIterator first()
          Returns an NodeIterator over the nodes of this Path following the edges of this Path starting at the first node (by a call to the next() method).
 int[] intersection(Path p)
          Returns the nodes common in both paths.
 boolean isCanonical()
          True if this path is cylic canonical.
 NodeIterator last()
          Returns an NodeIterator over the nodes of this Path following the edges of this Path starting at the last node (by a call to the previous() method)
 int length()
          Returns the length of this Path (nr of edges).
 int nodeAt(int d)
          Returns the node at distance d from the startnode of this Path.
 NodeIterator nodeIterator(int node)
          Returns an NodeIterator over the nodes of this Path following the edges of this path starting at the specified node (by a call to the next() method).
 void removeBack()
          Removes the last node from this Path.
 void removeFront()
          Removes the first node from this Path (O(length)).
 java.lang.String toString()
          Returns a String representation of this path.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Path

public Path()
Creates a new empty Path.


Path

public Path(int i,
            int j)
Creates a new path being the edge (i,j).

Parameters:
i - first node of the Path
j - second node of the Path

Path

public Path(int[] apath)
Creates a new Path representing apath[0]->..->apath[apath.length-1].

Parameters:
apath - the nodes of the Path as an array

Path

protected Path(java.util.ArrayList nodes)
Wraps a new Path object around this vector.

Parameters:
nodes - the ArrayList around which a Path has to be wrapped
Method Detail

length

public int length()
Returns the length of this Path (nr of edges).

Returns:
the length of this Path

nodeAt

public int nodeAt(int d)
Returns the node at distance d from the startnode of this Path.

Parameters:
d - the distance (within the Path)
Returns:
the node at the specified distance from the startnode

addBack

public void addBack(int node)
Adds node node to the end of this Path.

Parameters:
node - the node to be added to the back

addFront

public void addFront(int node)
Adds node node to the end of this Path (O(length)).

Parameters:
node - the node to be added to the front

removeBack

public void removeBack()
Removes the last node from this Path.


removeFront

public void removeFront()
Removes the first node from this Path (O(length)).


append

public void append(Path p)
Appends p to this path where appropriate. Appending to the back is more efficient.

Parameters:
p - the Path to be appended

concat

public Path concat(Path p)
Returns the concatenation of this path with the path p as a new Path object.

Parameters:
p - the Path to be concatenated with this Path
Returns:
the result of the concatatenation as a new Path object

isCanonical

public boolean isCanonical()
True if this path is cylic canonical. We call a path i->j cyclic canonical if if it only passes nodes bigger than i, with other words the startnode must be the lowest node of the path.

Returns:
true if this Path is cyclic canonical, false otherwise

intersection

public int[] intersection(Path p)
Returns the nodes common in both paths.

Parameters:
p - the path to be intersected with this Path
Returns:
the nodes common to this and the specified Path

first

public NodeIterator first()
Returns an NodeIterator over the nodes of this Path following the edges of this Path starting at the first node (by a call to the next() method).

Returns:
a NodeIterator pointing to the last node
See Also:
NodeIterator, NodeIterator.next()

last

public NodeIterator last()
Returns an NodeIterator over the nodes of this Path following the edges of this Path starting at the last node (by a call to the previous() method)

Returns:
a NodeIterator pointing to the last node.
See Also:
NodeIterator, NodeIterator.previous()

nodeIterator

public NodeIterator nodeIterator(int node)
Returns an NodeIterator over the nodes of this Path following the edges of this path starting at the specified node (by a call to the next() method).

Parameters:
node - the node to be returned by the first NodeIterator.next() of the returned NodeIterator
Returns:
a NodeIterator returning node by the first NodeIterator.next() call.
See Also:
NodeIterator, NodeIterator.next()

clone

public java.lang.Object clone()
Implementation of the Cloneable interface.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this Path

toString

public java.lang.String toString()
Returns a String representation of this path.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this path.