org.graphstream.graph.implementations
Class AbstractNode

java.lang.Object
  extended by org.graphstream.graph.implementations.AbstractElement
      extended by org.graphstream.graph.implementations.AbstractNode
All Implemented Interfaces:
Iterable<Edge>, Element, Node
Direct Known Subclasses:
AdjacencyListNode

public abstract class AbstractNode
extends AbstractElement
implements Node

This class provides a basic implementation of Node interface, to minimize the effort required to implement this interface.

This class implements all the methods of org.graphstream.graph.implementations and most of the methods of org.graphstream.graph (there are "only" ten abstract methods). In addition to these, subclasses must provide implementations for addEdgeCallback(AbstractEdge) and removeEdgeCallback(AbstractEdge) which are called by the parent graph when an edge incident to this node is added to or removed from the graph. This class has a low memory overhead (one reference as field).


Nested Class Summary
 
Nested classes/interfaces inherited from class org.graphstream.graph.implementations.AbstractElement
AbstractElement.AttributeChangeEvent
 
Method Summary
<T extends Node>
Iterator<T>
getBreadthFirstIterator()
          This implementation creates an instance of org.graphstream.graph and returns it.
<T extends Node>
Iterator<T>
getBreadthFirstIterator(boolean directed)
          This implementation creates an instance of org.graphstream.graph and returns it.
abstract  int getDegree()
          Total number of relations with other nodes or this node.
<T extends Node>
Iterator<T>
getDepthFirstIterator()
          This implementation creates an instance of org.graphstream.graph and returns it.
<T extends Node>
Iterator<T>
getDepthFirstIterator(boolean directed)
          This implementation creates an instance of org.graphstream.graph and returns it.
<T extends Edge>
Iterable<T>
getEachEdge()
          This implementation uses getEdgeIterator()
<T extends Edge>
Iterable<T>
getEachEnteringEdge()
          This implementation uses getEnteringEdgeIterator()
<T extends Edge>
Iterable<T>
getEachLeavingEdge()
          This implementation uses getLeavingEdgeIterator()
abstract
<T extends Edge>
T
getEdge(int i)
          I-th edge.
<T extends Edge>
T
getEdgeBetween(int index)
          This implementation uses getEdgeBetween(Node)
abstract
<T extends Edge>
T
getEdgeBetween(Node node)
          Retrieves an edge between this node and and another node if one exists.
<T extends Edge>
T
getEdgeBetween(String id)
          This implementation uses getEdgeBetween(Node)
<T extends Edge>
T
getEdgeFrom(int index)
          This implementation uses getEdgeFrom(Node)
abstract
<T extends Edge>
T
getEdgeFrom(Node node)
          Retrieves an edge that leaves given node toward this node.
<T extends Edge>
T
getEdgeFrom(String id)
          This implementation uses getEdgeFrom(Node)
abstract
<T extends Edge>
Iterator<T>
getEdgeIterator()
          Iterator on the set of connected edges.
<T extends Edge>
Collection<T>
getEdgeSet()
          This implementation uses getEdgeIterator() and getDegree()
<T extends Edge>
T
getEdgeToward(int index)
          This implementation uses getEdgeToward(Node)
abstract
<T extends Edge>
T
getEdgeToward(Node node)
          Retrieves an edge that leaves this node toward another node.
<T extends Edge>
T
getEdgeToward(String id)
          This implementation uses getEdgeToward(Node)
abstract
<T extends Edge>
T
getEnteringEdge(int i)
          I-th entering edge.
abstract
<T extends Edge>
Iterator<T>
getEnteringEdgeIterator()
          Iterator only on leaving edges.
<T extends Edge>
Collection<T>
getEnteringEdgeSet()
          This implementation uses getEnteringEdgeIterator() and #geIntDegree()
 Graph getGraph()
          This implementation returns graph.
abstract  int getInDegree()
          Number of entering edges.
abstract
<T extends Edge>
T
getLeavingEdge(int i)
          I-th leaving edge.
abstract
<T extends Edge>
Iterator<T>
getLeavingEdgeIterator()
          Iterator only on entering edges.
<T extends Edge>
Collection<T>
getLeavingEdgeSet()
          This implementation uses #getLeavingIterator() and #geOuttDegree()
<T extends Node>
Iterator<T>
getNeighborNodeIterator()
          This implementation uses getEdgeIterator() and stores the visited nodes in a set.
abstract  int getOutDegree()
          Number of leaving edges.
 boolean hasEdgeBetween(int index)
          This implementation returns true if getEdgeBetween(int) is not null.
 boolean hasEdgeBetween(Node node)
          This implementation returns true if getEdgeBetween(Node) is not null.
 boolean hasEdgeBetween(String id)
          This implementation returns true if getEdgeBetween(Node) is not null.
 boolean hasEdgeFrom(int index)
          This implementation returns true if getEdgeFrom(int) is not null.
 boolean hasEdgeFrom(Node node)
          This implementation returns true if getEdgeFrom(Node) is not null.
 boolean hasEdgeFrom(String id)
          This implementation returns true if getEdgeFrom(Node) is not null.
 boolean hasEdgeToward(int index)
          This implementation returns true if getEdgeToward(int) is not null.
 boolean hasEdgeToward(Node node)
          This implementation returns true if getEdgeToward(Node) is not null.
 boolean hasEdgeToward(String id)
          This implementation returns true if getEdgeToward(Node) is not null.
 boolean isEnteringEdge(Edge e)
          Checks if an edge enters this node.
 boolean isIncidentEdge(Edge e)
          Checks if an edge is incident to this node.
 boolean isLeavingEdge(Edge e)
          Checks if an edge leaves this node.
 Iterator<Edge> iterator()
          This implementation uses getEdgeIterator()
 
Methods inherited from class org.graphstream.graph.implementations.AbstractElement
addAttribute, addAttributes, changeAttribute, clearAttributes, getArray, getAttribute, getAttribute, getAttributeCount, getAttributeKeyIterator, getAttributeKeySet, getEachAttributeKey, getFirstAttributeOf, getFirstAttributeOf, getHash, getId, getIndex, getLabel, getNumber, getVector, hasArray, hasAttribute, hasAttribute, hasHash, hasLabel, hasNumber, hasVector, removeAttribute, setAttribute, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.graphstream.graph.Node
toString
 
Methods inherited from interface org.graphstream.graph.Element
addAttribute, addAttributes, changeAttribute, clearAttributes, getArray, getAttribute, getAttribute, getAttributeCount, getAttributeKeyIterator, getAttributeKeySet, getFirstAttributeOf, getFirstAttributeOf, getHash, getId, getIndex, getLabel, getNumber, getVector, hasArray, hasAttribute, hasAttribute, hasHash, hasLabel, hasNumber, hasVector, removeAttribute, setAttribute
 

Method Detail

getGraph

public Graph getGraph()
This implementation returns graph.

Specified by:
getGraph in interface Node
Returns:
The graph containing this node or null if unknown.
See Also:
Node.getGraph()

getDegree

public abstract int getDegree()
Description copied from interface: Node
Total number of relations with other nodes or this node.

Specified by:
getDegree in interface Node
Returns:
The number of edges/relations/links.

getInDegree

public abstract int getInDegree()
Description copied from interface: Node
Number of entering edges.

Specified by:
getInDegree in interface Node
Returns:
the count of edges that only leave this node plus all undirected edges.

getOutDegree

public abstract int getOutDegree()
Description copied from interface: Node
Number of leaving edges.

Specified by:
getOutDegree in interface Node
Returns:
the count of edges that only enter this node plus all undirected edges.

hasEdgeToward

public boolean hasEdgeToward(Node node)
This implementation returns true if getEdgeToward(Node) is not null.

Specified by:
hasEdgeToward in interface Node
Parameters:
node - The target node.
Returns:
True if a directed edge goes from this node to the other node or if an undirected edge exists.
See Also:
Node.getEdgeToward(org.graphstream.graph.Node)

hasEdgeToward

public boolean hasEdgeToward(int index)
This implementation returns true if getEdgeToward(int) is not null.

Specified by:
hasEdgeToward in interface Node
Parameters:
index - Index of the target node.
Returns:
True if a directed edge goes from this node to the other node or if an undirected edge exists.
See Also:
Node.hasEdgeToward(int)

hasEdgeToward

public boolean hasEdgeToward(String id)
This implementation returns true if getEdgeToward(Node) is not null.

Specified by:
hasEdgeToward in interface Node
Parameters:
id - Identifier of the target node.
Returns:
True if a directed edge goes from this node to 'id' or if an undirected edge exists.
See Also:
Node.hasEdgeToward(java.lang.String)

hasEdgeFrom

public boolean hasEdgeFrom(Node node)
This implementation returns true if getEdgeFrom(Node) is not null.

Specified by:
hasEdgeFrom in interface Node
Parameters:
node - The source node.
Returns:
True if a directed edge goes from the other node to this node or if an undirected edge exists.
See Also:
Node.hasEdgeFrom(org.graphstream.graph.Node)

hasEdgeFrom

public boolean hasEdgeFrom(int index)
This implementation returns true if getEdgeFrom(int) is not null.

Specified by:
hasEdgeFrom in interface Node
Parameters:
index - Index of the source node.
Returns:
True if a directed edge goes from the other node to this node or if an undirected edge exists.
See Also:
Node.hasEdgeFrom(int)

hasEdgeFrom

public boolean hasEdgeFrom(String id)
This implementation returns true if getEdgeFrom(Node) is not null.

Specified by:
hasEdgeFrom in interface Node
Parameters:
id - Identifier of the source node.
Returns:
True if a directed edge goes from this node to 'id' or if an undirected edge exists.
See Also:
Node.hasEdgeFrom(java.lang.String)

hasEdgeBetween

public boolean hasEdgeBetween(Node node)
This implementation returns true if getEdgeBetween(Node) is not null.

Specified by:
hasEdgeBetween in interface Node
Parameters:
node - Another node.
Returns:
True if an edge exists between this node and the other node.
See Also:
Node.hasEdgeBetween(org.graphstream.graph.Node)

hasEdgeBetween

public boolean hasEdgeBetween(int index)
This implementation returns true if getEdgeBetween(int) is not null.

Specified by:
hasEdgeBetween in interface Node
Parameters:
index - Index of another node.
Returns:
True if an edge exists between this node and the other node.
See Also:
Node.hasEdgeBetween(int)

hasEdgeBetween

public boolean hasEdgeBetween(String id)
This implementation returns true if getEdgeBetween(Node) is not null.

Specified by:
hasEdgeBetween in interface Node
Parameters:
id - Identifier of another node.
Returns:
True if a edge exists between this node and node 'id'.
See Also:
Node.hasEdgeBetween(java.lang.String)

getEdgeToward

public abstract <T extends Edge> T getEdgeToward(Node node)
Description copied from interface: Node
Retrieves an edge that leaves this node toward another node.

This method selects only edges leaving this node an pointing at the parameter node (this also selects undirected edges).

This method is implicitly generic and returns something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :

 ExtendedEdge e = node.getEdgeToward(...);
 
the method will return an ExtendedEdge. If no left part exists, method will just return an Edge.

Specified by:
getEdgeToward in interface Node
Parameters:
node - The target node.
Returns:
Directed edge going from this node to the parameter node, or undirected edge if it exists, else null.

getEdgeToward

public <T extends Edge> T getEdgeToward(int index)
This implementation uses getEdgeToward(Node)

Specified by:
getEdgeToward in interface Node
Parameters:
index - Index of the target node.
Returns:
Directed edge going from this node to the parameter node, or undirected edge if it exists, else null.
See Also:
Node.getEdgeToward(int)

getEdgeToward

public <T extends Edge> T getEdgeToward(String id)
This implementation uses getEdgeToward(Node)

Specified by:
getEdgeToward in interface Node
Parameters:
id - Identifier of the target node.
Returns:
Directed edge going from this node to 'id', or undirected edge if it exists, else null.
See Also:
Node.getEdgeToward(java.lang.String)

getEdgeFrom

public abstract <T extends Edge> T getEdgeFrom(Node node)
Description copied from interface: Node
Retrieves an edge that leaves given node toward this node.

This method selects only edges leaving the other node an pointing at this node (this also selects undirected edges).

This method is implicitly generic and returns something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :

 ExtendedEdge e = node.getEdgeFrom(...);
 
the method will return an ExtendedEdge. If no left part exists, method will just return an Edge.

Specified by:
getEdgeFrom in interface Node
Parameters:
node - The source node.
Returns:
Directed edge going from the parameter node to this node, or undirected edge if it exists, else null.

getEdgeFrom

public <T extends Edge> T getEdgeFrom(int index)
This implementation uses getEdgeFrom(Node)

Specified by:
getEdgeFrom in interface Node
Parameters:
index - Index of the source node.
Returns:
Directed edge going from the parameter node to this node, or undirected edge if it exists, else null.
See Also:
Node.getEdgeFrom(int)

getEdgeFrom

public <T extends Edge> T getEdgeFrom(String id)
This implementation uses getEdgeFrom(Node)

Specified by:
getEdgeFrom in interface Node
Parameters:
id - Identifier of the source node.
Returns:
Directed edge going from node 'id' to this node, or undirected edge if it exists, else null.
See Also:
Node.getEdgeFrom(java.lang.String)

getEdgeBetween

public abstract <T extends Edge> T getEdgeBetween(Node node)
Description copied from interface: Node
Retrieves an edge between this node and and another node if one exists.

This method selects directed or undirected edges. If the edge is directed, its direction is not important and leaving or entering edges will be selected.

This method is implicitly generic and return something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :

 ExtendedEdge e = node.getEdgeBetween(...);
 
the method will return an ExtendedEdge. If no left part exists, method will just return an Edge.

Specified by:
getEdgeBetween in interface Node
Parameters:
node - The opposite node.
Returns:
Edge between this node and the parameter node if it exists, else null.

getEdgeBetween

public <T extends Edge> T getEdgeBetween(int index)
This implementation uses getEdgeBetween(Node)

Specified by:
getEdgeBetween in interface Node
Parameters:
index - The index of the opposite node.
Returns:
Edge between node with index i and this node if it exists, else null.
See Also:
Node.getEdgeBetween(int)

getEdgeBetween

public <T extends Edge> T getEdgeBetween(String id)
This implementation uses getEdgeBetween(Node)

Specified by:
getEdgeBetween in interface Node
Parameters:
id - Identifier of the opposite node.
Returns:
Edge between node 'id' and this node if it exists, else null.
See Also:
Node.getEdgeBetween(java.lang.String)

getEdgeIterator

public abstract <T extends Edge> Iterator<T> getEdgeIterator()
Description copied from interface: Node
Iterator on the set of connected edges.

This iterator iterates on all edges leaving and entering (this includes any non-directed edge present, and a non-directed edge is only iterated once).

This method is implicitly generic and return 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 = node.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 Node
Returns:
The iterator, edges are iterated in arbitrary order.

getEnteringEdgeIterator

public abstract <T extends Edge> Iterator<T> getEnteringEdgeIterator()
Description copied from interface: Node
Iterator only on leaving edges.

This iterator iterates only on directed edges going from this node to others (non-directed edges are included in the iteration).

This method is implicitly generic and return 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 = node.getEnteringEdgeIterator();
 
the method will return an Iterator<ExtendedEdge>. If no left part exists, method will just return an Iterator<Edge>.

Specified by:
getEnteringEdgeIterator in interface Node
Returns:
The iterator, edges are iterated in arbitrary order.

getLeavingEdgeIterator

public abstract <T extends Edge> Iterator<T> getLeavingEdgeIterator()
Description copied from interface: Node
Iterator only on entering edges.

This iterator iterates only on directed edges going from other nodes toward this node (non-directed edges are included in the iteration).

This method is implicitly generic and return 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 = node.getLeavingEdgeIterator();
 
the method will return an Iterator<ExtendedEdge>. If no left part exists, method will just return an Iterator<Edge>.

Specified by:
getLeavingEdgeIterator in interface Node
Returns:
The iterator, edges are iterated in arbitrary order.

getEachEdge

public <T extends Edge> Iterable<T> getEachEdge()
This implementation uses getEdgeIterator()

Specified by:
getEachEdge in interface Node
Returns:
A collection containing all directed and undirected edges, leaving or entering.
See Also:
Node.getEachEdge()

getEachEnteringEdge

public <T extends Edge> Iterable<T> getEachEnteringEdge()
This implementation uses getEnteringEdgeIterator()

Specified by:
getEachEnteringEdge in interface Node
Returns:
A collection of only edges that enter this node plus all undirected edges.
See Also:
Node.getEachEnteringEdge()

getEachLeavingEdge

public <T extends Edge> Iterable<T> getEachLeavingEdge()
This implementation uses getLeavingEdgeIterator()

Specified by:
getEachLeavingEdge in interface Node
Returns:
A collection of only edges that leave this node plus all undirected edges.
See Also:
Node.getEachLeavingEdge()

getEdgeSet

public <T extends Edge> Collection<T> getEdgeSet()
This implementation uses getEdgeIterator() and getDegree()

Specified by:
getEdgeSet in interface Node
Returns:
A collection containing all directed and undirected edges, leaving or entering.
See Also:
Node.getEdgeSet()

getEnteringEdgeSet

public <T extends Edge> Collection<T> getEnteringEdgeSet()
This implementation uses getEnteringEdgeIterator() and #geIntDegree()

Specified by:
getEnteringEdgeSet in interface Node
Returns:
A collection of only edges that enter this node plus all undirected edges.
See Also:
Node.getEnteringEdgeSet()

getLeavingEdgeSet

public <T extends Edge> Collection<T> getLeavingEdgeSet()
This implementation uses #getLeavingIterator() and #geOuttDegree()

Specified by:
getLeavingEdgeSet in interface Node
Returns:
A collection of only edges that leave this node plus all undirected edges.
See Also:
Node.getLeavingEdgeSet()

iterator

public Iterator<Edge> iterator()
This implementation uses getEdgeIterator()

Specified by:
iterator in interface Iterable<Edge>
See Also:
Iterable.iterator()

getEdge

public abstract <T extends Edge> T getEdge(int i)
Description copied from interface: Node
I-th edge. Edges are stored in no given order.

However this method allows to iterate very quickly on all edges, or to choose a given edge with direct access.

This method is implicitly generic and return something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :

 ExtendedEdge e = node.getEdge(i);
 
the method will return an ExtendedEdge. If no left part exists, method will just return an Edge.

Specified by:
getEdge in interface Node
Parameters:
i - Index of the edge.
Returns:
The i-th edge.

getEnteringEdge

public abstract <T extends Edge> T getEnteringEdge(int i)
Description copied from interface: Node
I-th entering edge. Edges are stored in no given order.

However this method allows to iterate very quickly on all entering edges, or to choose a given entering edge with direct access.

This method is implicitly generic and return something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :

 ExtendedEdge e = node.getEnteringEdge(i);
 
the method will return an ExtendedEdge. If no left part exists, method will just return an Edge.

Specified by:
getEnteringEdge in interface Node
Parameters:
i - Index of the edge.
Returns:
The i-th entering edge.

getLeavingEdge

public abstract <T extends Edge> T getLeavingEdge(int i)
Description copied from interface: Node
I-th leaving edge. Edges are stored in no given order.

However this method allows to iterate very quickly on all leaving edges, or to choose a given leaving edge with direct access.

This method is implicitly generic and return something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :

 ExtendedEdge e = node.getLeavingEdge(i);
 
the method will return an ExtendedEdge. If no left part exists, method will just return an Edge.

Specified by:
getLeavingEdge in interface Node
Parameters:
i - Index of the edge.
Returns:
The i-th leaving edge.

getNeighborNodeIterator

public <T extends Node> Iterator<T> getNeighborNodeIterator()
This implementation uses getEdgeIterator() and stores the visited nodes in a set. In this way it ensures that each neighbor will be visited exactly once, even in multi-graph.

Specified by:
getNeighborNodeIterator in interface Node
Returns:
The iterator, neighbors are iterated in arbitrary order.
See Also:
Node.getNeighborNodeIterator()

getBreadthFirstIterator

public <T extends Node> Iterator<T> getBreadthFirstIterator()
This implementation creates an instance of org.graphstream.graph and returns it.

Specified by:
getBreadthFirstIterator in interface Node
Returns:
An iterator able to explore the graph in a breadth first way starting at this node.
See Also:
Node.getBreadthFirstIterator()

getBreadthFirstIterator

public <T extends Node> Iterator<T> getBreadthFirstIterator(boolean directed)
This implementation creates an instance of org.graphstream.graph and returns it.

Specified by:
getBreadthFirstIterator in interface Node
Parameters:
directed - If false, the iterator will ignore edge orientation (the default is "True").
Returns:
An iterator able to explore the graph in a breadth first way starting at this node.
See Also:
Node.getBreadthFirstIterator(boolean)

getDepthFirstIterator

public <T extends Node> Iterator<T> getDepthFirstIterator()
This implementation creates an instance of org.graphstream.graph and returns it.

Specified by:
getDepthFirstIterator in interface Node
Returns:
An iterator able to explore the graph in a depth first way starting at this node.
See Also:
Node.getDepthFirstIterator()

getDepthFirstIterator

public <T extends Node> Iterator<T> getDepthFirstIterator(boolean directed)
This implementation creates an instance of org.graphstream.graph and returns it.

Specified by:
getDepthFirstIterator in interface Node
Parameters:
directed - If false, the iterator will ignore edge orientation (the default is "True").
Returns:
An iterator able to explore the graph in a depth first way starting at this node.
See Also:
Node.getDepthFirstIterator(boolean)

isEnteringEdge

public boolean isEnteringEdge(Edge e)
Checks if an edge enters this node. Utility method that can be useful in subclasses.

Parameters:
e - an edge
Returns:
true if e is entering edge for this node.

isLeavingEdge

public boolean isLeavingEdge(Edge e)
Checks if an edge leaves this node. Utility method that can be useful in subclasses.

Parameters:
e - an edge
Returns:
true if e is leaving edge for this node.

isIncidentEdge

public boolean isIncidentEdge(Edge e)
Checks if an edge is incident to this node. Utility method that can be useful in subclasses.

Parameters:
e - an edge
Returns:
true if e is incident edge for this node.


Copyright © 2013. All Rights Reserved.