ps3.graph
Class NodeCountingPath

java.lang.Object
  extended by ps3.graph.NodeCountingPath
All Implemented Interfaces:
Comparable<Path<?,?>>, Iterable<WeightedNode>, Path<WeightedNode,NodeCountingPath>

public class NodeCountingPath
extends Object
implements Path<WeightedNode,NodeCountingPath>

A NodeCountingPath characterizes a path of WeightedNodes. The cost for a path is the number of WeightedNodes it contains; the cost of the WeightedNodes are ignored.

A NodeCountingPath is immutable. A new NodeCountingPath is returned through the extend path operation.

The main purpose of this class is to illustrate that there can be multiple implementations of Paths of WeightedNodes.

Specfields inherited from Path:

Specification Fields

Constructor Summary
NodeCountingPath(WeightedNode node)
          Constructs a NodeCountingPath containing one node.
 
Method Summary
 int compareTo(Path<?,?> p)
          Compares the cost of this path to the given path.
 double cost()
           
 WeightedNode end()
          Return the end of this path
 boolean equals(NodeCountingPath wnp)
           
 boolean equals(Object o)
           
 NodeCountingPath extend(WeightedNode node)
          Creates an extended path by adding a new node to its end.
 int hashCode()
           
 Iterator<WeightedNode> iterator()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeCountingPath

public NodeCountingPath(WeightedNode node)
Constructs a NodeCountingPath containing one node.

Requires:
node != null
Effects:
Creates a new NodeCountingPath which originates at node.
Method Detail

extend

public NodeCountingPath extend(WeightedNode node)
Description copied from interface: Path
Creates an extended path by adding a new node to its end.

Specified by:
extend in interface Path<WeightedNode,NodeCountingPath>
Returns:
a new Path p such that p.elements = this.elements + [ n ] && p.cost >= this.cost

cost

public double cost()
Specified by:
cost in interface Path<WeightedNode,NodeCountingPath>
Returns:
this.cost

iterator

public Iterator<WeightedNode> iterator()
Specified by:
iterator in interface Iterable<WeightedNode>
Specified by:
iterator in interface Path<WeightedNode,NodeCountingPath>
Returns:
an Iterator over the elements in the path in order from start to end.

toString

public String toString()
Overrides:
toString in class Object
Returns:
a string representation of this.

equals

public boolean equals(Object o)
Overrides:
equals in class Object
Returns:
true iff o is a NodeCountingPath and o.elements is the same sequence as this.elements

equals

public boolean equals(NodeCountingPath wnp)
Returns:
true iff wnp.elements is the same sequence as this.elements

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a valid hashcode for this.

compareTo

public int compareTo(Path<?,?> p)
Compares the cost of this path to the given path.

Specified by:
compareTo in interface Comparable<Path<?,?>>
Returns:
the value 0 if the cost of this path is equal to the cost of the given path; a value less than 0 if this.cost is less than p.cost; and a value greater than 0 if this.cost is greater than p.cost.
See Also:
Comparable.compareTo(T)

end

public WeightedNode end()
Return the end of this path

Specified by:
end in interface Path<WeightedNode,NodeCountingPath>
Returns:
the end of the path