org.geotools.graph.path
Class Walk

Object
  extended by AbstractCollection<E>
      extended by AbstractList<E>
          extended by ArrayList
              extended by Walk
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, List, RandomAccess, NodeSequence
Direct Known Subclasses:
Cycle, Path

public class Walk
extends 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
Module:

Field Summary
 
Fields inherited from class AbstractList
modCount
 
Constructor Summary
Walk()
           
Walk(Collection nodes)
           
 
Method Summary
 void add(int index, Object element)
           
 boolean add(Node node)
          Adds a node to the walk.
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 boolean addAll(int index, Collection c)
           
 boolean addEdge(Edge e)
           
 void addEdges(Collection edges)
           
protected  List buildEdges()
          Internal method for building the edge set of the walk.
 Path duplicate()
           
 boolean equals(Object other)
           
 boolean equals(Walk other)
           
 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.
 Object remove(int index)
           
 void remove(Node node)
          Removes a node from the walk.
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 void reverse()
          Reverses the path.
 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 ArrayList
clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class AbstractList
iterator, listIterator, listIterator, subList
 
Methods inherited from class AbstractCollection
containsAll, retainAll, toString
 
Methods inherited from class Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface NodeSequence
iterator, size
 
Methods inherited from interface List
containsAll, iterator, listIterator, listIterator, retainAll, subList
 

Constructor Detail

Walk

public Walk()

Walk

public Walk(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 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,
                Object element)
Specified by:
add in interface List
Overrides:
add in class ArrayList

add

public boolean add(Object o)
Specified by:
add in interface Collection
Specified by:
add in interface List
Overrides:
add in class ArrayList

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List
Overrides:
addAll in class ArrayList

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List
Overrides:
addAll in class ArrayList

addEdge

public boolean addEdge(Edge e)

addEdges

public void addEdges(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 Object remove(int index)
Specified by:
remove in interface List
Overrides:
remove in class ArrayList

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection
Specified by:
remove in interface List
Overrides:
remove in class ArrayList

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List
Overrides:
removeAll in class AbstractCollection

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 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 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(Object other)
Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class AbstractList

equals

public boolean equals(Walk other)

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface List
Overrides:
hashCode in class AbstractList


Copyright © 1996-2009 Geotools. All Rights Reserved.