UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.graphs
Class Node

java.lang.Object
  |
  +--edu.berkeley.guir.lib.graphs.Node
All Implemented Interfaces:
Cloneable, GraphConst, Serializable

public class Node
extends Object
implements GraphConst, Serializable, Cloneable

A single Node in a Graph, as well as the adjacency list of inlinks (what other Nodes are connected to this Node) and outlinks (what other Nodes can we get to from this Node).

The inlink weight is the negative of the actual outlink weight. For example, if the weight from A to B were 1, then from B to A is -1.

Assumes a simple Graph (one that does not have multiple edges between two nodes).

Also assumes that no two Nodes will have the same name.

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Nov 24 1997, JH
               Created class
             - GUIRLib-v1.0-1.1.0, Feb 24 2000, JH
               Updated for JDK1.3RC1 to use the Collections
             - GUIRLib-v1.2-1.1.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.1.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.1.0, Aug 31 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.1.1, Oct 07 2000, JH
               Changed addInLink() and addOutLink() from package to protected
 

Since:
1.3RC1
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu)
See Also:
Serialized Form

Fields inherited from interface edu.berkeley.guir.lib.graphs.GraphConst
DEFAULT_NUMBER_EDGES, DEFAULT_NUMBER_NODES, DEFAULT_PATH_SIZE, DEFAULT_WEIGHT, ERROR, TRUE
 
Constructor Summary
protected Node()
          Creates a new and empty Node.
  Node(String strName)
          Create a new Node with the specified name.
 
Method Summary
protected  void addInlink(String strNodeToName)
          Add a Node connected to this Node by an in link.
protected  void addInlink(String strNodeToName, float weight)
          Add a Node connected to this Node by an in link.
protected  void addOutlink(String strNodeToName)
          Add a Node connected to this Node by an out link.
protected  void addOutlink(String strNodeToName, float weight)
          Add a Node connected to this Node by an out link.
 Object clone()
          Clones this Node.
 boolean equals(Object obj)
           
 int getInDegree()
          Get the number of edges that come into this Node.
 Iterator getInlinks()
          Get an Iteration of the names of the Nodes that can get to this Node (that is, the Nodes connected by inlinks into this Node).
 float getInlinkWeight(String strName)
          Return the weight of a Node connected by an in link.
 String getName()
          Get the name of the source node.
 int getOutDegree()
          Get the number of edges that come out of this Node.
 Iterator getOutlinks()
          Get an Iteration of the names of the Nodes you can get to from this Node (that is, the Nodes connected by outlinks from this Node).
 float getOutlinkWeight(String strName)
          Return the weight of a Node connected by an out link.
 boolean hasInlinkFrom(String strName)
          See if the given node is adjacent to the source Node by an out link.
 boolean hasOutlinkTo(String strName)
          See if the given node is adjacent to the source Node by an out link.
static void setDefaultNumberEdges(int edges)
          Sets the default number of edges in the Adjacency List of each Node.
 void setName(String strName)
          Set the name for this Node.
static void setPrintLinks(boolean flag)
          Set the flag for whether or not method toString() should print out the inlinks and outlinks for this Node.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

protected Node()
Creates a new and empty Node. Used in the clone() method.

Node

public Node(String strName)
Create a new Node with the specified name.
Parameters:
strName - is the name of the Node to create an Adjacency list.
Method Detail

setDefaultNumberEdges

public static void setDefaultNumberEdges(int edges)
Sets the default number of edges in the Adjacency List of each Node.
Parameters:
iNumEdges - is the number of edges, and must be greater than the default number of edges. If it is less, then it will revert to the default number of edges. Ignores negative values.

setPrintLinks

public static void setPrintLinks(boolean flag)
Set the flag for whether or not method toString() should print out the inlinks and outlinks for this Node.
Parameters:
flag - is true if the links should be printed, false otherwise.

getName

public String getName()
Get the name of the source node.
Returns:
The source Node.

getOutlinks

public Iterator getOutlinks()
Get an Iteration of the names of the Nodes you can get to from this Node (that is, the Nodes connected by outlinks from this Node).
Returns:
An Iterator containing the Nodes connected by outgoing edges.

getInlinks

public Iterator getInlinks()
Get an Iteration of the names of the Nodes that can get to this Node (that is, the Nodes connected by inlinks into this Node).
Returns:
An Iterator containing the Nodes connected by incoming edges.

getInDegree

public int getInDegree()
Get the number of edges that come into this Node.
Returns:
An int containing the in degree of this Node.

getOutDegree

public int getOutDegree()
Get the number of edges that come out of this Node.
Returns:
An int containing the out degree of this Node.

hasOutlinkTo

public boolean hasOutlinkTo(String strName)
See if the given node is adjacent to the source Node by an out link.
Parameters:
strName - is the name of the Node to check if it is connected.

hasInlinkFrom

public boolean hasInlinkFrom(String strName)
See if the given node is adjacent to the source Node by an out link.
Parameters:
strName - is the name of the Node to check if it is connected.

getOutlinkWeight

public float getOutlinkWeight(String strName)
Return the weight of a Node connected by an out link. Use method hasOutlinkTo() first to see if the two Nodes are adjacent.
Parameters:
strName - is the name of the Node to check for adjacency.
Returns:
a float containing the weight between this Node and the specified Node, or NaN (not a number) if the two are not adjacent.

getInlinkWeight

public float getInlinkWeight(String strName)
Return the weight of a Node connected by an in link. Use method hasInlinkFrom() first to see if the two Nodes are adjacent.

The inlink weight is the negative of the actual outlink weight. For example, if the weight from A to B were 1, then from B to A is -1.

Parameters:
strName - is the name of the Node to check for adjacency.
Returns:
a float containing the weight between this Node and the specified Node, or NaN (not a number) if the two are not adjacent.

setName

public void setName(String strName)
Set the name for this Node.
Parameters:
strName - is the name of the Node to set to.

addOutlink

protected void addOutlink(String strNodeToName)
Add a Node connected to this Node by an out link. If the Node is already in here, it will be overwritten.

The weight of the edge is defaulted to GraphConst.DEFAULT_WEIGHT. Use this method if you don't really care about the weight of the edge.

Parameters:
strToNodeName - is the name of the adjacent Node.
See Also:
GraphConst

addOutlink

protected void addOutlink(String strNodeToName,
                          float weight)
Add a Node connected to this Node by an out link. If the Node is already in here, it will be overwritten.
Parameters:
nodeTo - is the adjacent Node to add.
weight - is the weight of this edge. weight can be negative.

addInlink

protected void addInlink(String strNodeToName)
Add a Node connected to this Node by an in link. If the Node is already in here, it will be overwritten.

The weight of the edge is defaulted to GraphConst.DEFAULT_WEIGHT. Use this method if you don't really care about the weight of the edge.

Parameters:
strToNodeName - is the name of the adjacent Node.
See Also:
GraphConst

addInlink

protected void addInlink(String strNodeToName,
                         float weight)
Add a Node connected to this Node by an in link. If the Node is already in here, it will be overwritten.

The weight of this inlink should be the negative of the outlink. For example, if the weight from A to B were 1, then from B to A is -1.

Parameters:
nodeTo - is the adjacent Node to add.
weight - is the weight of this edge. weight can be negative.

toString

public String toString()
Overrides:
toString in class Object

clone

public Object clone()
Clones this Node.
Overrides:
clone in class Object
Returns:
a Node object that has the same values as this Node object.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

Copyright Information