Package org.geotools.graph.path
Class Walk
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Node>
,Collection<Node>
,List<Node>
,RandomAccess
,NodeSequence
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
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description Walk()
Walk(Collection<Node> nodes)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, Node element)
boolean
add(Node node)
Adds a node to the walk.boolean
addAll(int index, Collection<? extends Node> c)
boolean
addAll(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)
boolean
remove(Object o)
void
remove(Node node)
Removes a node from the walk.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 interface Collection
parallelStream, stream, toArray
-
Methods inherited from interface List
containsAll
-
Methods inherited from interface NodeSequence
iterator, size
-
-
-
-
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 interfaceNodeSequence
- 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.
-
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().
-
add
public void add(int index, Node element)
-
addAll
public boolean addAll(Collection<? extends Node> c)
-
addAll
public boolean addAll(int index, Collection<? extends Node> c)
-
addEdge
public boolean addEdge(Edge e)
-
addEdges
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)
-
remove
public boolean remove(Object o)
-
removeAll
public boolean removeAll(Collection c)
-
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 interfaceNodeSequence
- 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 interfaceNodeSequence
- Returns:
- Object of type node.
- See Also:
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)
-
equals
public boolean equals(Walk other)
-
-