org.geotools.graph.path

Class Walk

• All Implemented Interfaces:
Serializable, Cloneable, Iterable<Node>, Collection<Node>, List<Node>, RandomAccess, NodeSequence
Direct Known Subclasses:
Cycle, Path

```public class Walk
extends ArrayList<Node>
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
Serialized Form

• Fields inherited from class AbstractList

`modCount`
• Constructor Summary

Constructors
Constructor and Description
`Walk()`
`Walk(Collection<Node> nodes)`
• Method Summary

All Methods
Modifier and Type Method and Description
`void` ```add(int index, Node element)```
`boolean` `add(Node node)`
Adds a node to the walk.
`boolean` `addAll(Collection<? extends Node> c)`
`boolean` ```addAll(int index, Collection<? extends Node> c)```
`boolean` `addEdge(Edge e)`
`void` `addEdges(Collection<Edge> edges)`
`protected List<Edge>` `buildEdges()`
Internal method for building the edge set of the walk.
`Path` `duplicate()`
`boolean` `equals(Object other)`
`boolean` `equals(Walk other)`
`List<Edge>` `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.
`Node` `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<Node>` `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, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize`
• Methods inherited from class AbstractCollection

`containsAll, 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`
• Methods inherited from interface Collection

`parallelStream, stream`
• Constructor Detail

• Walk

`public Walk()`
• Walk

`public Walk(Collection<Node> 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<Edge> 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.

`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().
Specified by:
`add` in interface `Collection<Node>`
Specified by:
`add` in interface `List<Node>`
Overrides:
`add` in class `ArrayList<Node>`
Parameters:
`node` - Node to add to the walk.

```public void add(int index,
Node element)```
Specified by:
`add` in interface `List<Node>`
Overrides:
`add` in class `ArrayList<Node>`

`public boolean addAll(Collection<? extends Node> c)`
Specified by:
`addAll` in interface `Collection<Node>`
Specified by:
`addAll` in interface `List<Node>`
Overrides:
`addAll` in class `ArrayList<Node>`

```public boolean addAll(int index,
Collection<? extends Node> c)```
Specified by:
`addAll` in interface `List<Node>`
Overrides:
`addAll` in class `ArrayList<Node>`

`public boolean addEdge(Edge e)`

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

`public boolean remove(Object o)`
Specified by:
`remove` in interface `Collection<Node>`
Specified by:
`remove` in interface `List<Node>`
Overrides:
`remove` in class `ArrayList<Node>`
• removeAll

`public boolean removeAll(Collection c)`
Specified by:
`removeAll` in interface `Collection<Node>`
Specified by:
`removeAll` in interface `List<Node>`
Overrides:
`removeAll` in class `ArrayList<Node>`
• 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.
`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.
`NodeSequence.getLast()`
• buildEdges

`protected List<Edge> 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<Node> 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<Node>`
Specified by:
`equals` in interface `List<Node>`
Overrides:
`equals` in class `AbstractList<Node>`
• equals

`public boolean equals(Walk other)`
• hashCode

`public int hashCode()`
Specified by:
`hashCode` in interface `Collection<Node>`
Specified by:
`hashCode` in interface `List<Node>`
Overrides:
`hashCode` in class `AbstractList<Node>`