1 /* 2 * $RCSfile: PartialOrderNode.java,v $ 3 * 4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 5 * 6 * Use is subject to license terms. 7 * 8 * $Revision: 1.1 $ 9 * $Date: 2005/02/11 04:57:15 $ 10 * $State: Exp $ 11 */ 12 package com.lightcrafts.mediax.jai; 13 import java.util.Enumeration; 14 import java.util.Vector; 15 16 /** 17 * A node in a directed graph of operations. Each node maintains 18 * three pieces of information, in addition to an arbitrary 19 * <code>Object</code> containing user data associated with the node, 20 * in order to allow topological sorting to be performed in linear time. 21 * 22 * <p> First, the in-degree (number of other nodes pointing to this 23 * node) is stored as an int. Nodes with in-degree equal to 0 are 24 * "free" and may appear first in a topological sort. 25 * 26 * <p> Second, a reference called <code>zeroLink</code> to another 27 * <code>PartialOrderNode</code> is kept in order to allow construction 28 * of a linked list of nodes with zero in-degree. 29 * 30 * <p> Third, a <code>Vector</code> of neighboring nodes is maintained 31 * (in no particular order). These are the nodes which are pointed to 32 * by the current node. 33 * 34 * <p> This class is used by the implementation of the 35 * <code>OperationRegistry</code> class and is not intended to be part 36 * of the API. 37 * 38 */ 39 final class PartialOrderNode implements Cloneable, java.io.Serializable { 40 41 /** The name of the object associated with this node. */ 42 protected String name; 43 44 /** The data associated with this node. */ 45 protected Object nodeData; 46 47 /** The in-degree of the node. */ 48 protected int inDegree = 0; 49 50 /** Copy of the inDegree of the node. */ 51 protected int copyInDegree = 0; 52 53 /** A link to another node with 0 in-degree, or null. */ 54 protected PartialOrderNode zeroLink = null; 55 56 /** A Vector of neighboring nodes. */ 57 Vector neighbors = new Vector(); 58 59 /** 60 * Constructs an <code>PartialOrderNode</code> with given associated data. 61 * 62 * @param nodeData an <code>Object</code> to associate with this node. 63 */ PartialOrderNode(Object nodeData, String name)64 PartialOrderNode(Object nodeData, String name) { 65 this.nodeData = nodeData; 66 this.name = name; 67 } 68 69 /** Returns the <code>Object</code> represented by this node. */ getData()70 Object getData() { 71 return nodeData; 72 } 73 74 /** Returns the name of the <code>Object</code> represented by this node. */ getName()75 String getName() { 76 return name; 77 } 78 79 /** Returns the in-degree of this node. */ getInDegree()80 int getInDegree() { 81 return inDegree; 82 } 83 84 /** Returns the copy in-degree of this node. */ getCopyInDegree()85 int getCopyInDegree() { 86 return copyInDegree; 87 } 88 89 /** Sets the copy in-degree of this node. */ setCopyInDegree(int copyInDegree)90 void setCopyInDegree(int copyInDegree) { 91 this.copyInDegree = copyInDegree; 92 } 93 94 /** Returns the next zero in-degree node in the linked list. */ getZeroLink()95 PartialOrderNode getZeroLink() { 96 return zeroLink; 97 } 98 99 /** Sets the next zero in-degree node in the linked list. */ setZeroLink(PartialOrderNode poNode)100 void setZeroLink(PartialOrderNode poNode) { 101 zeroLink = poNode; 102 } 103 104 /** Returns the neighbors of this node as an <code>Enumeration</code>. */ getNeighbors()105 Enumeration getNeighbors() { 106 return neighbors.elements(); 107 } 108 109 /** 110 * Adds a directed edge to the graph. The neighbors list of this 111 * node is updated and the in-degree of the other node is incremented. 112 */ addEdge(PartialOrderNode poNode)113 void addEdge(PartialOrderNode poNode) { 114 neighbors.addElement(poNode); 115 poNode.incrementInDegree(); 116 } 117 118 /** 119 * Removes a directed edge from the graph. The neighbors list of this 120 * node is updated and the in-degree of the other node is decremented. 121 */ removeEdge(PartialOrderNode poNode)122 void removeEdge(PartialOrderNode poNode) { 123 neighbors.removeElement(poNode); 124 poNode.decrementInDegree(); 125 } 126 127 /** Increments the in-degree of a node. */ incrementInDegree()128 void incrementInDegree() { 129 ++inDegree; 130 } 131 132 /** Increments the copy-in-degree of a node. */ incrementCopyInDegree()133 void incrementCopyInDegree() { 134 ++copyInDegree; 135 } 136 137 /** Decrements the in-degree of a node. */ decrementInDegree()138 void decrementInDegree() { 139 --inDegree; 140 } 141 142 /** Decrements the copy in-degree of a node. */ decrementCopyInDegree()143 void decrementCopyInDegree() { 144 --copyInDegree; 145 } 146 147 } 148