V
- the type of the verticespublic class WalkByID<V extends Vertex>
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Graph
using the identifiers of the vertices.
WalkByID
to serialize a Walk
. If you deserialize a WalkByID
keep in mind to set the associated graph with
setGraph(Graph)
otherwise the walk is not functioning any more.
cast()
to convert this walk using vertex identifiers in a Walk
using concrete Vertex
s.PathByID
,
TrailByID
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected Graph<V,? extends Edge> |
graph
the associated graph
|
protected java.util.List<java.lang.Integer> |
vertices
the list of identifiers of the vertices of the walk
|
Constructor and Description |
---|
WalkByID(Graph<V,? extends Edge> graph)
Creates an empty walk.
|
WalkByID(Graph<V,? extends Edge> graph,
java.lang.Integer[] walk)
Creates a walk based on a predefined walk.
|
WalkByID(Graph<V,? extends Edge> graph,
java.util.List<java.lang.Integer> walk)
Creates a walk based on a predefined walk.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int vertexID)
Adds a new vertex to the walk.
|
void |
add(V vertex)
Adds a new vertex to the walk.
|
java.util.List<java.lang.Integer> |
asList()
Gets the walk as a list.
|
Walk<V> |
cast()
|
WalkByID<V> |
clone()
Gets a shallow copy of this walk (the identifiers of the vertices in the walk are not cloned).
|
boolean |
contains(Edge edge)
Indicates whether the walk contains the specified edge or more precisely whether the walk contains
the predecessor and the successor of the edge regarding the direction of the edge.
|
boolean |
contains(int vertexID)
Indicates whether the specified vertex is on this walk.
|
boolean |
contains(V vertex)
Indicates whether the specified vertex is on this walk.
|
boolean |
equals(java.lang.Object o)
Indicates whether this walk equals the specified one.
|
boolean |
equals(WalkByID<V> w)
Indicates whether this walk equals the specified one.
|
java.lang.Integer |
get(int index)
Gets a vertex identifier at the specified index.
|
float |
getWeight()
Gets the weight (or cost) of the walk which is the sum of the weights of the traversed edges.
|
boolean |
isClosed()
Indicates whether the walk is closed meaning the walk ends on the same vertex on which it began.
|
int |
length()
The length of the walk meaning the number of edges.
|
void |
removeLast()
Removes the last vertex of the walk.
|
void |
setGraph(Graph<V,? extends Edge> graph)
Sets the associated graph of the walk.
|
protected static java.util.List<java.lang.Integer> |
toList(java.lang.Integer[] array)
Converts the given array to a list.
|
java.lang.String |
toString() |
protected void |
updateWeight()
Updates the weight of the walk.
|
protected final java.util.List<java.lang.Integer> vertices
public WalkByID(Graph<V,? extends Edge> graph) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this walkjava.lang.IllegalArgumentException
- public WalkByID(Graph<V,? extends Edge> graph, java.lang.Integer[] walk) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this walkwalk
- the predefined walk or null
java.lang.IllegalArgumentException
- public WalkByID(Graph<V,? extends Edge> graph, java.util.List<java.lang.Integer> walk) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this walkwalk
- the predefined walk or null
java.lang.IllegalArgumentException
- public void setGraph(Graph<V,? extends Edge> graph) throws java.lang.IllegalArgumentException
WalkByID
is deserialized from a byte stream because the associated graph
can not be serialized. If you do not set the associated graph after deserialization the walk is not functioning any more.graph
- the graph its vertices can be part of the walk (ensure that this is the one you have used to create the walk)java.lang.IllegalArgumentException
- public void add(int vertexID) throws java.lang.UnsupportedOperationException, java.lang.IllegalArgumentException
vertexID
- the id of the vertexjava.lang.UnsupportedOperationException
- setGraph(Graph)
)java.lang.IllegalArgumentException
- WalkByID
)public void add(V vertex) throws java.lang.UnsupportedOperationException, java.lang.IllegalArgumentException
vertex
- the vertexjava.lang.UnsupportedOperationException
- setGraph(Graph)
)java.lang.IllegalArgumentException
- WalkByID
)public void removeLast() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
- setGraph(Graph)
)public int length()
public java.lang.Integer get(int index) throws java.lang.UnsupportedOperationException, java.lang.IndexOutOfBoundsException
length()
returns the number of edges meaning that get(length())
is the last vertex of the walk.index
- the indexjava.lang.UnsupportedOperationException
- setGraph(Graph)
)java.lang.IndexOutOfBoundsException
- index < 0 || index > length()
)public boolean contains(int vertexID) throws java.lang.UnsupportedOperationException
vertexID
- the vertex idtrue
if the vertex is on this walk otherwise false
java.lang.UnsupportedOperationException
- setGraph(Graph)
)public boolean contains(V vertex) throws java.lang.UnsupportedOperationException
vertex
- the vertextrue
if the vertex is on this walk otherwise false
java.lang.UnsupportedOperationException
- setGraph(Graph)
)public boolean contains(Edge edge)
edge
- the edgetrue
if the walk contains the specified edge otherwise false
public boolean isClosed()
true
if the walk is closed otherwise false
public float getWeight()
public Walk<V> cast() throws java.lang.UnsupportedOperationException, java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
- setGraph(Graph)
)java.lang.IllegalArgumentException
- public java.util.List<java.lang.Integer> asList()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- another walk of the same vertex type that should be compared with this walktrue
if the walks are equal otherwise false
public boolean equals(WalkByID<V> w)
w
- another walk that should be compared with this walktrue
if the walks are equal otherwise false
public WalkByID<V> clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
protected static java.util.List<java.lang.Integer> toList(java.lang.Integer[] array)
array
- the arrayprotected void updateWeight()