Package org.geotools.graph.path
Class Walk
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Node>
,Collection<Node>
,List<Node>
,RandomAccess
,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 }
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:
-
Field Summary
Fields inherited from class AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
Adds a node to the walk.boolean
addAll
(int index, Collection<? extends Node> c) boolean
addAll
(Collection<? extends Node> c) boolean
void
addEdges
(Collection<Edge> edges) Internal method for building the edge set of the walk.boolean
boolean
getEdges()
Calculates the edges in the walk.getFirst()
Returns the first node in the sequence.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.remove
(int index) boolean
void
Removes a node from the walk.boolean
void
reverse()
Reverses the path.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 interface Collection
parallelStream, stream, toArray
Methods inherited from interface List
containsAll
Methods inherited from interface NodeSequence
iterator, size
-
Constructor Details
-
Walk
public Walk() -
Walk
-
-
Method Details
-
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 interfaceNodeSequence
- Returns:
- True if valid, otherwise false.
-
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
Adds a node to the walk. Adding a node clears the edge list which will be recalculated on the next call to getEdges(). -
add
-
addAll
-
addAll
-
addEdge
-
addEdges
-
remove
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
-
remove
-
removeAll
-
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
Description copied from interface:NodeSequence
Returns the first node in the sequence.- Specified by:
getFirst
in interfaceNodeSequence
- Returns:
- Object of tupe Node.
- See Also:
-
getLast
Description copied from interface:NodeSequence
Returns the last node in the sequence.- Specified by:
getLast
in interfaceNodeSequence
- Returns:
- Object of type node.
- See Also:
-
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
Returns an iterator that iterates over the path in reverse. The iterator does not support the remove operation.- Returns:
- the reverse iterator.
-
duplicate
-
equals
-
equals
-
hashCode
public int hashCode()
-