org.graphstream.graph
Class Path

java.lang.Object
  extended by org.graphstream.graph.Path
All Implemented Interfaces:
Structure

public class Path
extends Object
implements Structure

Path description.

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 Summary
Path()
          New empty path.
 
Method Summary
 void add(Edge edge)
          Method that adds an edge an a node to the path.
 void add(Node from, Edge edge)
          Method that 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.
 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
<T extends Edge>
Iterable<? extends T>
getEachEdge()
          Set of edges usable in a for-each instruction.
<T extends Node>
Iterable<? extends T>
getEachNode()
          Set of nodes usable in a for-each instruction.
 int getEdgeCount()
          Number of edges in this graph.
<T extends Edge>
Iterator<T>
getEdgeIterator()
          Iterator on the set of edges, in an undefined order.
 List<Edge> getEdgePath()
          Returns the list of edges representing the path.
<T extends Edge>
Collection<T>
getEdgeSet()
          Unmodifiable view of the set of edges.
 int getNodeCount()
          Returns the size of the path.
<T extends Node>
Iterator<T>
getNodeIterator()
          Iterator on the set of nodes, in an undefined order.
 List<Node> getNodePath()
          Construct an return a list of nodes that represents the path.
<T extends Node>
Collection<T>
getNodeSet()
          Unmodifiable view of the set of nodes.
 Double getPathWeight(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.
 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
 String toString()
          Returns a String description of the path.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Path

public Path()
New empty path.

Method Detail

getRoot

public Node getRoot()
Get the root (the first node) of the path.

Returns:
the root of the path.

setRoot

public void setRoot(Node root)
Set the root (first node) of the path.

Parameters:
root - The root of the path.

contains

public boolean contains(Node node)
Says whether the path contains this node or not.

Parameters:
node - The node tested for existence in the path.
Returns:
true if the path contains the node.

contains

public boolean contains(Edge edge)
Says whether the path contains this edge or not.

Parameters:
edge - The edge tested for existence in the path.
Returns:
true if the path contains the edge.

empty

public boolean empty()
Returns true if the path is empty.

Returns:
true if the path is empty.

size

public int size()
Returns the size of the path


getPathWeight

public Double getPathWeight(String characteristic)
It returns the sum of the characteristic given value in the Edges of the path.

Parameters:
characteristic - The characteristic.
Returns:
Sum of the characteristics.

getEdgePath

public List<Edge> getEdgePath()
Returns the list of edges representing the path.

Returns:
The list of edges representing the path.

getNodePath

public List<Node> getNodePath()
Construct an return a list of nodes that represents the path.

Returns:
A list of nodes representing the path.

add

public void add(Node from,
                Edge edge)
Method that adds a node (and an edge) to the path. Parameters are the start node : the one who already belong to the path or the first one if the path is empty. The other parameter is the the new edge to add.

Parameters:
from - The start node.
edge - The edge used.

add

public void add(Edge edge)
Method that adds an edge an a node to the path. The new edge to add is given.

Parameters:
edge - The edge to add to the path.

push

public void push(Node from,
                 Edge edge)
A synonym for add(Edge).


push

public void push(Edge edge)
A synonym for add(Edge).


popEdge

public Edge popEdge()
This methods pops the 2 stacks (edgePath and nodePath) and returns the removed edge.

Returns:
The edge that have just been removed.

popNode

public Node popNode()
This methods pops the 2 stacks (edgePath and nodePath) and returns the removed node.

Returns:
The node that have just been removed.

peekNode

public Node peekNode()
Looks at the node at the top of the stack without removing it from the stack.

Returns:
The node at the top of the stack.

peekEdge

public Edge peekEdge()
Looks at the edge at the top of the stack without removing it from the stack.

Returns:
The edge at the top of the stack.

clear

public void clear()
Clears the path;


getACopy

public Path getACopy()
Get a copy of this path

Returns:
A copy of this path.

removeLoops

public void removeLoops()
Remove all parts of the path that start at a given node and pass a new at this node.


equals

public boolean equals(Path p)
Compare the content of the current path and the specified path to decide weather they are equal or not.

Parameters:
p - A path to compare to the curent one.
Returns:
True if both paths are equal.

toString

public String toString()
Returns a String description of the path.

Overrides:
toString in class Object
Returns:
A String representation of the path.

getNodeCount

public int getNodeCount()
Returns the size of the path. Identical to size().

Specified by:
getNodeCount in interface Structure
Returns:
The size of the path.

getEdgeCount

public int getEdgeCount()
Description copied from interface: Structure
Number of edges in this graph.

Specified by:
getEdgeCount in interface Structure
Returns:
The number of edges.

getNodeIterator

public <T extends Node> Iterator<T> getNodeIterator()
Description copied from interface: Structure
Iterator on the set of nodes, in an undefined order. This method is implicitly generic and returns an Iterator over something which extends Node. The return type is the one of the left part of the assignment. For example, in the following call :
 Iterator<ExtendedNode> ite = graph.getNodeIterator();
 
the method will return an Iterator<ExtendedNode>. If no left part exists, method will just return an Iterator<Node>.

Specified by:
getNodeIterator in interface Structure
Returns:
The iterator.

getEdgeIterator

public <T extends Edge> Iterator<T> getEdgeIterator()
Description copied from interface: Structure
Iterator on the set of edges, in an undefined order. This method is implicitly generic and returns an Iterator over something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :
 Iterator<ExtendedEdge> ite = graph.getEdgeIterator();
 
the method will return an Iterator<ExtendedEdge>. If no left part exists, method will just return an Iterator<Edge>.

Specified by:
getEdgeIterator in interface Structure
Returns:
The iterator.

getEachNode

public <T extends Node> Iterable<? extends T> getEachNode()
Description copied from interface: Structure
Set of nodes usable in a for-each instruction. This method is implicitly generic and returns an Iterable over something which extends Node. The return type is the one of the left part of the assignment. For example, in the following call :
 Iterable<ExtendedNode> ite = struct.getEachNode();
 
the method will return an Iterable<ExtendedNode>. If no left part exists, method will just return an Iterable<Node>. It is possible to use it in a for-each loop by giving the parameter :
 for (ExtendedNode n : struct.<ExtendedNode> getEachNode()) {
        // ...
 }
 

Specified by:
getEachNode in interface Structure
Returns:
An "iterable" view of the set of nodes.
See Also:
Structure.getNodeIterator(), Structure.getEachNode()

getEachEdge

public <T extends Edge> Iterable<? extends T> getEachEdge()
Description copied from interface: Structure
Set of edges usable in a for-each instruction. This method is implicitly generic and returns an Iterable over something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :
 Iterable<ExtendedNEdge> ite = struct.getEachEdge();
 
the method will return an Iterable<ExtendedEdge>. If no left part exists, method will just return an Iterable<Edge>. It is possible to use it in a for-each loop by giving the parameter :
 for (ExtendedEdge e : struct.<ExtendedEdge> getEachEdge()) {
        // ...
 }
 

Specified by:
getEachEdge in interface Structure
Returns:
An "iterable" view of the set of edges.
See Also:
Structure.getEdgeIterator(), Structure.getEdgeSet()

getNodeSet

public <T extends Node> Collection<T> getNodeSet()
Description copied from interface: Structure
Unmodifiable view of the set of nodes. This method is implicitly generic and returns a Collection of something which extends Node. The return type is the one of the left part of the assignment. For example, in the following call :
 Collection<ExtendedNode> c = struct.getNodeSet();
 
the method will return a Collection<ExtendedNode>. If no left part exists, method will just return a Collection<Node>.

Specified by:
getNodeSet in interface Structure
Returns:
A set of nodes that can only be read, not changed.
See Also:
Structure.getNodeIterator(), Structure.getEachNode()

getEdgeSet

public <T extends Edge> Collection<T> getEdgeSet()
Description copied from interface: Structure
Unmodifiable view of the set of edges. This method is implicitly generic and returns a Collection of something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :
 Collection<ExtendedEdge> c = struct.getEdgeSet();
 
the method will return a Collection<ExtendedEdge>. If no left part exists, method will just return a Collection<Edge>.

Specified by:
getEdgeSet in interface Structure
Returns:
A set of edges that can only be read, not changed.
See Also:
Structure.getEdgeIterator(), Structure.getEachEdge()


Copyright © 2013. All Rights Reserved.