001: /*
002: * $RCSfile: PartialOrderNode.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:15 $
010: * $State: Exp $
011: */
012: package javax.media.jai;
013:
014: import java.util.Enumeration;
015: import java.util.Vector;
016:
017: /**
018: * A node in a directed graph of operations. Each node maintains
019: * three pieces of information, in addition to an arbitrary
020: * <code>Object</code> containing user data associated with the node,
021: * in order to allow topological sorting to be performed in linear time.
022: *
023: * <p> First, the in-degree (number of other nodes pointing to this
024: * node) is stored as an int. Nodes with in-degree equal to 0 are
025: * "free" and may appear first in a topological sort.
026: *
027: * <p> Second, a reference called <code>zeroLink</code> to another
028: * <code>PartialOrderNode</code> is kept in order to allow construction
029: * of a linked list of nodes with zero in-degree.
030: *
031: * <p> Third, a <code>Vector</code> of neighboring nodes is maintained
032: * (in no particular order). These are the nodes which are pointed to
033: * by the current node.
034: *
035: * <p> This class is used by the implementation of the
036: * <code>OperationRegistry</code> class and is not intended to be part
037: * of the API.
038: *
039: */
040: final class PartialOrderNode implements Cloneable, java.io.Serializable {
041:
042: /** The name of the object associated with this node. */
043: protected String name;
044:
045: /** The data associated with this node. */
046: protected Object nodeData;
047:
048: /** The in-degree of the node. */
049: protected int inDegree = 0;
050:
051: /** Copy of the inDegree of the node. */
052: protected int copyInDegree = 0;
053:
054: /** A link to another node with 0 in-degree, or null. */
055: protected PartialOrderNode zeroLink = null;
056:
057: /** A Vector of neighboring nodes. */
058: Vector neighbors = new Vector();
059:
060: /**
061: * Constructs an <code>PartialOrderNode</code> with given associated data.
062: *
063: * @param nodeData an <code>Object</code> to associate with this node.
064: */
065: PartialOrderNode(Object nodeData, String name) {
066: this .nodeData = nodeData;
067: this .name = name;
068: }
069:
070: /** Returns the <code>Object</code> represented by this node. */
071: Object getData() {
072: return nodeData;
073: }
074:
075: /** Returns the name of the <code>Object</code> represented by this node. */
076: String getName() {
077: return name;
078: }
079:
080: /** Returns the in-degree of this node. */
081: int getInDegree() {
082: return inDegree;
083: }
084:
085: /** Returns the copy in-degree of this node. */
086: int getCopyInDegree() {
087: return copyInDegree;
088: }
089:
090: /** Sets the copy in-degree of this node. */
091: void setCopyInDegree(int copyInDegree) {
092: this .copyInDegree = copyInDegree;
093: }
094:
095: /** Returns the next zero in-degree node in the linked list. */
096: PartialOrderNode getZeroLink() {
097: return zeroLink;
098: }
099:
100: /** Sets the next zero in-degree node in the linked list. */
101: void setZeroLink(PartialOrderNode poNode) {
102: zeroLink = poNode;
103: }
104:
105: /** Returns the neighbors of this node as an <code>Enumeration</code>. */
106: Enumeration getNeighbors() {
107: return neighbors.elements();
108: }
109:
110: /**
111: * Adds a directed edge to the graph. The neighbors list of this
112: * node is updated and the in-degree of the other node is incremented.
113: */
114: void addEdge(PartialOrderNode poNode) {
115: neighbors.addElement(poNode);
116: poNode.incrementInDegree();
117: }
118:
119: /**
120: * Removes a directed edge from the graph. The neighbors list of this
121: * node is updated and the in-degree of the other node is decremented.
122: */
123: void removeEdge(PartialOrderNode poNode) {
124: neighbors.removeElement(poNode);
125: poNode.decrementInDegree();
126: }
127:
128: /** Increments the in-degree of a node. */
129: void incrementInDegree() {
130: ++inDegree;
131: }
132:
133: /** Increments the copy-in-degree of a node. */
134: void incrementCopyInDegree() {
135: ++copyInDegree;
136: }
137:
138: /** Decrements the in-degree of a node. */
139: void decrementInDegree() {
140: --inDegree;
141: }
142:
143: /** Decrements the copy in-degree of a node. */
144: void decrementCopyInDegree() {
145: --copyInDegree;
146: }
147:
148: }
|