ps3.graph
Class WeightedNodePath

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

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

A WeightedNodePath characterizes a path of WeightedNodes. The cost for a path is the sum of the costs of the WeightedNodes it contains.

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

Specfields inherited from Path:

Specification Fields

Constructor Summary
WeightedNodePath(WeightedNode node)
          Constructs a WeightedNodePath 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(Object o)
           
 boolean equals(WeightedNodePath wnp)
           
 WeightedNodePath 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

WeightedNodePath

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

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

extend

public WeightedNodePath 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,WeightedNodePath>
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,WeightedNodePath>
Returns:
this.cost

iterator

public Iterator<WeightedNode> iterator()
Specified by:
iterator in interface Iterable<WeightedNode>
Specified by:
iterator in interface Path<WeightedNode,WeightedNodePath>
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 WeightedNodePath and o.elements is the same sequence as this.elements

equals

public boolean equals(WeightedNodePath 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,WeightedNodePath>
Returns:
the end of the path