org.geotools.graph.path
Class Walk

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.ArrayList
              extended byorg.geotools.graph.path.Walk
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, NodeSequence, java.util.RandomAccess, java.io.Serializable
Direct Known Subclasses:
Cycle, Path

public class Walk
extends java.util.ArrayList
implements NodeSequence

Represents a walk in a graph. A walk W is defined as an ordered set of nodes that two adjacenct nodes in the set share an edge. More precisley:

G = {N,E} W = { n(i) in N | (n(i-1),n(i)) in E }

Author:
Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Walk()
           
Walk(java.util.Collection nodes)
           
 
Method Summary
 void add(int index, java.lang.Object element)
           
 boolean add(Node node)
          Adds a node to the walk.
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int index, java.util.Collection c)
           
 boolean addEdge(Edge e)
           
 void addEdges(java.util.Collection edges)
           
protected  java.util.List buildEdges()
          Internal method for building the edge set of the walk.
 Path duplicate()
           
 boolean equals(java.lang.Object other)
           
 boolean equals(Walk other)
           
 java.util.List getEdges()
          Calculates the edges in the walk.
 Node getFirst()
          Returns the first node in the sequence.
 Node getLast()
          Returns the last node in the sequence.
 int hashCode()
           
 boolean isClosed()
          Determines if the walk is closed.
 boolean isValid()
          A valid walk is one in which each pair of adjacent nodes in the sequence share an edge.
 java.lang.Object remove(int index)
           
 void remove(Node node)
          Removes a node from the walk.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 void reverse()
          Reverses the path.
 java.util.Iterator riterator()
          Returns an iterator that iterates over the path in reverse.
 void truncate(int index)
          Truncates the path at the specified index.
 
Methods inherited from class java.util.ArrayList
clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.geotools.graph.path.NodeSequence
iterator, size
 
Methods inherited from interface java.util.List
containsAll, iterator, listIterator, listIterator, retainAll, subList
 

Constructor Detail

Walk

public Walk()

Walk

public Walk(java.util.Collection nodes)
Method Detail

isValid

public boolean isValid()
A valid walk is one in which each pair of adjacent nodes in the sequence share an edge. Note,

Specified by:
isValid in interface NodeSequence
Returns:
True if valid, otherwise false.

getEdges

public java.util.List getEdges()
Calculates the edges in the walk. If the edges of the walk cannot be calculated (due to an invalid walk), null is returned, otherwise the list of edges is returned.

Returns:
The edges of the walk, otherwise null if the edges cannot be calculated.

add

public boolean add(Node node)
Adds a node to the walk. Adding a node clears the edge list which will be recalculated on the next call to getEdges().

Parameters:
node - Node to add to the walk.

add

public void add(int index,
                java.lang.Object element)
Specified by:
add in interface java.util.List

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.List

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.List

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List

addEdge

public boolean addEdge(Edge e)

addEdges

public void addEdges(java.util.Collection edges)

remove

public void remove(Node node)
Removes a node from the walk. Removing a node clears the edge list which will be recalculated on the next call to getEdges().

Parameters:
node - Node to remove from the walk.

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.List

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.List

isClosed

public boolean isClosed()
Determines if the walk is closed. A closed walk is one in which the first and last nodes are the same.

Returns:
True if closed, otherwise false.

getFirst

public Node getFirst()
Description copied from interface: NodeSequence
Returns the first node in the sequence.

Specified by:
getFirst in interface NodeSequence
Returns:
Object of tupe Node.
See Also:
NodeSequence.getFirst()

getLast

public Node getLast()
Description copied from interface: NodeSequence
Returns the last node in the sequence.

Specified by:
getLast in interface NodeSequence
Returns:
Object of type node.
See Also:
NodeSequence.getLast()

buildEdges

protected java.util.List buildEdges()
Internal method for building the edge set of the walk. This method calculated the edges upon every call.

Returns:
The list of edges for the walk, or null if the edge set could not be calculated due to an invalid walk.

reverse

public void reverse()
Reverses the path.


truncate

public void truncate(int index)
Truncates the path at the specified index. Nodes in the path whose index is >= the specified index are removed.

Parameters:
index - The index of first node to be removed.

riterator

public java.util.Iterator riterator()
Returns an iterator that iterates over the path in reverse. The iterator does not support the remove operation.

Returns:
the reverse iterator.

duplicate

public Path duplicate()

equals

public boolean equals(java.lang.Object other)
Specified by:
equals in interface java.util.List

equals

public boolean equals(Walk other)

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.List


Copyright © GeoTools. All Rights Reserved.