public class Path extends java.lang.Object implements Structure
A path is a class that stores ordered lists of nodes and links that are adjacent. Such a path may be manipulated with nodes and/or edges added or removed. This class is designed as a dynamic structure that is, to add edges during the construction of the path. Only edges need to be added, the nodes list is maintained automatically.
The two lists (one for nodes, one for edges) may be acceded at any moment in constant time.
The constraint of this class is that it needs to know the first node of the
path (the root). This root can be set with the setRoot(Node)
method
or by using the add(Node, Edge)
method.
The normal use with this class is to first use the setRoot(Node)
method to initialize the path; then to use the add(Edge)
method to
grow it and the popEdge()
or popNode()
.
Constructor and Description |
---|
Path()
New empty path.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Edge edge)
Adds an edge to the path.
|
void |
add(Node from,
Edge edge)
Adds a node and an edge to the path.
|
void |
clear()
Clears the path;
|
boolean |
contains(Edge edge)
Says whether the path contains this edge or not.
|
boolean |
contains(Node node)
Says whether the path contains this node or not.
|
java.util.stream.Stream<Edge> |
edges() |
boolean |
empty()
Returns true if the path is empty.
|
boolean |
equals(Path p)
Compare the content of the current path and the specified path to decide
weather they are equal or not.
|
Path |
getACopy()
Get a copy of this path
|
int |
getEdgeCount()
Number of edges in this graph.
|
java.util.List<Edge> |
getEdgePath()
Returns the list of edges representing the path.
|
<T extends Edge> |
getEdgeSet() |
int |
getNodeCount()
Returns the size of the path.
|
java.util.List<Node> |
getNodePath()
Construct an return a list of nodes that represents the path.
|
<T extends Node> |
getNodeSet() |
java.lang.Double |
getPathWeight(java.lang.String characteristic)
It returns the sum of the
characteristic given value in the
Edges of the path. |
Node |
getRoot()
Get the root (the first node) of the path.
|
java.util.stream.Stream<Node> |
nodes() |
Edge |
peekEdge()
Looks at the edge at the top of the stack without removing it from the stack.
|
Node |
peekNode()
Looks at the node at the top of the stack without removing it from the stack.
|
Edge |
popEdge()
This methods pops the 2 stacks (
edgePath and
nodePath ) and returns the removed edge. |
Node |
popNode()
This methods pops the 2 stacks (
edgePath and
nodePath ) and returns the removed node. |
void |
push(Edge edge)
A synonym for
add(Edge) . |
void |
push(Node from,
Edge edge)
A synonym for
add(Edge) . |
void |
removeLoops()
Remove all parts of the path that start at a given node and pass a new at
this node.
|
void |
setRoot(Node root)
Set the root (first node) of the path.
|
int |
size()
Returns the size of the path
|
java.lang.String |
toString()
Returns a String description of the path.
|
public Node getRoot()
public void setRoot(Node root)
root
- The root of the path.public boolean contains(Node node)
node
- The node tested for existence in the path.true
if the path contains the node.public boolean contains(Edge edge)
edge
- The edge tested for existence in the path.true
if the path contains the edge.public boolean empty()
true
if the path is empty.public int size()
public java.lang.Double getPathWeight(java.lang.String characteristic)
characteristic
given value in the
Edges of the path.characteristic
- The characteristic.public java.util.List<Edge> getEdgePath()
public java.util.List<Node> getNodePath()
public void add(Node from, Edge edge)
from
- The start node.edge
- The edge used.public void add(Edge edge)
edge
- The edge to add to the path.public Edge popEdge()
edgePath
and
nodePath
) and returns the removed edge.public Node popNode()
edgePath
and
nodePath
) and returns the removed node.public Node peekNode()
public Edge peekEdge()
public void clear()
public Path getACopy()
public void removeLoops()
public boolean equals(Path p)
p
- A path to compare to the curent one.public java.lang.String toString()
toString
in class java.lang.Object
public int getNodeCount()
size()
.getNodeCount
in interface Structure
public int getEdgeCount()
Structure
getEdgeCount
in interface Structure
public <T extends Node> java.util.Collection<T> getNodeSet()
public <T extends Edge> java.util.Collection<T> getEdgeSet()