FileDocCategorySizeDatePackage
DigraphNode.javaAPI DocJava SE 5 API3913Fri Aug 26 14:57:30 BST 2005javax.imageio.spi

DigraphNode

public class DigraphNode extends Object implements Serializable, Cloneable
A node in a directed graph. In addition to an arbitrary Object containing user data associated with the node, each node maintains a Sets of nodes which are pointed to by the current node (available from getOutNodes). The in-degree of the node (that is, number of nodes that point to the current node) may be queried.
version
0.5

Fields Summary
protected Object
data
The data associated with this node.
protected Set
outNodes
A Set of neighboring nodes pointed to by this node.
protected int
inDegree
The in-degree of the node.
private Set
inNodes
A Set of neighboring nodes that point to this node.
Constructors Summary
public DigraphNode(Object data)


       
        this.data = data;
    
Methods Summary
public booleanaddEdge(javax.imageio.spi.DigraphNode node)
Adds a directed edge to the graph. The outNodes list of this node is updated and the in-degree of the other node is incremented.

param
node a DigraphNode.
return
true if the node was not previously the target of an edge.

        if (outNodes.contains(node)) {
            return false;
        }

        outNodes.add(node);
        node.inNodes.add(this);
        node.incrementInDegree();
        return true;
    
private voiddecrementInDegree()
Decrements the in-degree of this node.

        --inDegree;
    
public voiddispose()
Removes this node from the graph, updating neighboring nodes appropriately.

        Object[] inNodesArray = inNodes.toArray();
        for(int i=0; i<inNodesArray.length; i++) {
            DigraphNode node = (DigraphNode) inNodesArray[i];
            node.removeEdge(this);
        }

        Object[] outNodesArray = outNodes.toArray();
        for(int i=0; i<outNodesArray.length; i++) {
            DigraphNode node = (DigraphNode) outNodesArray[i];
            removeEdge(node);
        }
    
public java.lang.ObjectgetData()
Returns the Object referenced by this node.

        return data;
    
public intgetInDegree()
Returns the in-degree of this node.

        return inDegree;
    
public java.util.IteratorgetOutNodes()
Returns an Iterator containing the nodes pointed to by this node.

        return outNodes.iterator();
    
public booleanhasEdge(javax.imageio.spi.DigraphNode node)
Returns true if an edge exists between this node and the given node.

param
node a DigraphNode.
return
true if the node is the target of an edge.

        return outNodes.contains(node);
    
private voidincrementInDegree()
Increments the in-degree of this node.

        ++inDegree;
    
public booleanremoveEdge(javax.imageio.spi.DigraphNode node)
Removes a directed edge from the graph. The outNodes list of this node is updated and the in-degree of the other node is decremented.

return
true if the node was previously the target of an edge.

        if (!outNodes.contains(node)) {
            return false;
        }

        outNodes.remove(node);
        node.inNodes.remove(this);
        node.decrementInDegree();
        return true;