com.cra.bnet.engine
Class Node

java.lang.Object
  |
  +--com.cra.bnet.engine.Node
Direct Known Subclasses:
DiscreteNode

public abstract class Node
extends Object

A node in a Bayesian network.

This class provides an ordered list of its parent nodes via the getParents method. Although node.getBayesianNetwork().getTopology().inEdgeSet(node) can also be used to obtain a node's parents, the inEdgeSet method does not specify an ordering of the elements of the returned set. Thus, the getParents method should be used when the order of parents is needed.

Each node can have a set of custom user propeties. A user property is defined as a pair (String, Object) that represents something in a particular application. The String is the property name and the Object is the property value. The getProperties method returns a fully modifiable map that clients may store user properties in. Clients may also register PropertyChangeListeners to be notified when the user property map is modified.

The equals and hashCode methods of this class forward to the corresponding methods of the Object class. That is, the equals method only returns true when given the same instance and hashCode most likely returns unique integers for unique instances. This ensures that instances of this class can safely be used as keys in maps and vertices in graphs.

Note: Each node in a Bayesian network has a conditional probability distribution (CPD) that specifies the probabilistic effects of its parents. In the future the Cpd interface may support arbitrary CPDs; however, because this version of BNet.EngineKit only suppo9rts discrete nodes, only conditional probability tables (CPT) are currently supported. See the DiscreteNode and Cpt classes for more details.


Method Summary
 void addBeliefListener(BeliefListener listener)
          Registers the specified belief listener to receive belief events when this node's beliefs change.
 void addCptListener(CptListener listener)
          Registers the specified CPT listener to receive CPT events when this node's CPT changes.
 void addEvidenceListener(EvidenceListener listener)
          Registers the specified listener to receive evidence events when evidence is posted to or retracted from this node.
 void addNodeListener(NodeListener listener)
          Registers the specified node listener to receive node events when aspects of this node change.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Registers the specified property change listener to receive events when the user properties of this node change.
 boolean equals(Object obj)
          Returns true if the specified object is equal to this node.
protected  void fireDescriptionChanged(String oldDescription, String newDescription)
          Notifies node listeners that this node's description was changed.
protected  void fireLocationChanged(Point oldLocation, Point newLocation)
          Notifies node listeners that this node's location was changed.
protected  void fireNameChanged(String oldName, String newName)
          Notifies node listeners that this node's name was changed.
protected  void fireParentReordered(Node parent, int index)
          Notifies node listeners and the belief updater that one of this node's parents was reordered.
 BayesianNetwork getBayesianNetwork()
          Returns the Bayesian network that this node belongs to.
 Cpd getCpd()
          Returns this node's conditional probability distribution.
 String getDescription()
          Returns this node's description.
 Point getLocation()
          Returns this node's location.
 String getName()
          Returns this node's name.
 List getParents()
          Returns an unmodifiable list of this node's parents.
 Map getProperties()
          Returns this node's user properties.
 int hashCode()
          Returns this node's hash code.
 void removeBeliefListener(BeliefListener listener)
          Unregisters the specified listener so it will no longer receive belief events from this node.
 void removeCptListener(CptListener listener)
          Unregisters the specified listener so it will no longer receive CPT events from this node.
 void removeEvidenceListener(EvidenceListener listener)
          Unregisters the specified listener so it will no longer receive evidence events from this node.
 void removeNodeListener(NodeListener listener)
          Unregisters the specified listener so it will no longer receive node events from this node.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Unregisters the specified property change listener so it will no longer receive events when the user properties of this node change.
 boolean reorderParent(Node parent, int index)
          Moves the specified parent to the specified index.
protected  void setCpd(Cpd cpd)
          Sets this node's conditional probability distribution.
 void setDescription(String description)
          Sets this node's description to the specified description.
 void setLocation(Point location)
          Sets this node's location to the specified point.
 void setLocationHelper(Point location)
          Use this method instead of setLocation if you don't want a ChangeLocationEdit to be posted.
 boolean setName(String newName)
          Sets this node's name to the specified name.
 String toString()
          Returns a string representation of this node.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

toString

public String toString()
Returns a string representation of this node.

Overrides:
toString in class Object
Returns:
a string representation of this node.

addNodeListener

public void addNodeListener(NodeListener listener)
Registers the specified node listener to receive node events when aspects of this node change.

Parameters:
listener - node listener to register with this node.
Throws:
IllegalArgumentException - if listener is null.

removeNodeListener

public void removeNodeListener(NodeListener listener)
Unregisters the specified listener so it will no longer receive node events from this node.

Parameters:
listener - node listener to remove from this node.

addCptListener

public void addCptListener(CptListener listener)
Registers the specified CPT listener to receive CPT events when this node's CPT changes.

Parameters:
listener - cpt listener to register with this node.

removeCptListener

public void removeCptListener(CptListener listener)
Unregisters the specified listener so it will no longer receive CPT events from this node.

Parameters:
listener - CPT listener to remove from this node.

addBeliefListener

public void addBeliefListener(BeliefListener listener)
Registers the specified belief listener to receive belief events when this node's beliefs change.

Parameters:
listener - belief listener to register with this node.
Throws:
IllegalArgumentException - if listener is null.

removeBeliefListener

public void removeBeliefListener(BeliefListener listener)
Unregisters the specified listener so it will no longer receive belief events from this node.

Parameters:
listener - belief listener to remove from this node.

addEvidenceListener

public void addEvidenceListener(EvidenceListener listener)
Registers the specified listener to receive evidence events when evidence is posted to or retracted from this node.

Parameters:
listener - evidence listener to register with this node.
Throws:
IllegalArgumentException - if listener is null.

removeEvidenceListener

public void removeEvidenceListener(EvidenceListener listener)
Unregisters the specified listener so it will no longer receive evidence events from this node.

Parameters:
listener - evidence listener to remove from this node.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Registers the specified property change listener to receive events when the user properties of this node change.

Parameters:
listener - property change listener to register with this node.
Throws:
IllegalArgumentException - if listener is null.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Unregisters the specified property change listener so it will no longer receive events when the user properties of this node change.

Parameters:
listener - property change listener to remove from this node.

getName

public String getName()
Returns this node's name.

Returns:
this node's name.

setName

public boolean setName(String newName)
Sets this node's name to the specified name. If the specified name is null, empty, the same as the old name or the same as the name of another node in the Bayesian network, this method will return false.

Parameters:
newName - new name for this node.
Returns:
true if node was renamed and false if it was not.

getParents

public List getParents()
Returns an unmodifiable list of this node's parents. Elements of the returned list are guaranteed to be of type Node and in the proper order.

Returns:
an unmodifiable list of this node's parents.

getBayesianNetwork

public BayesianNetwork getBayesianNetwork()
Returns the Bayesian network that this node belongs to.

Returns:
the Bayesian network that this node belongs to.

getLocation

public Point getLocation()
Returns this node's location.

Returns:
node's location.

setLocation

public void setLocation(Point location)
Sets this node's location to the specified point.

Parameters:
location - new location.

setLocationHelper

public void setLocationHelper(Point location)
Use this method instead of setLocation if you don't want a ChangeLocationEdit to be posted.

Parameters:
location - new location.

reorderParent

public boolean reorderParent(Node parent,
                             int index)
Moves the specified parent to the specified index.

This method will return false if any of the following are true:

If the specified index is the same as the specified parent's current index, this method does nothing and returns true.

Parameters:
parent - parent to reorder.
index - new index of parent.
Returns:
true if the parent was reordered and false otherwise.

getCpd

public Cpd getCpd()
Returns this node's conditional probability distribution.

Returns:
this node's conditional probability distribution.

setCpd

protected void setCpd(Cpd cpd)
Sets this node's conditional probability distribution.

Parameters:
cpd - new conditional probability distribution.
Throws:
NullPointerException - if cpd is null.

equals

public final boolean equals(Object obj)
Returns true if the specified object is equal to this node. This method uses instance equality.

Overrides:
equals in class Object
Parameters:
obj - object to test for equality.
Returns:
true if the specified object is equal to this node and false otherwise.

hashCode

public final int hashCode()
Returns this node's hash code. This method just returns super.hashCode().

Overrides:
hashCode in class Object
Returns:
super.hashCode().

getDescription

public String getDescription()
Returns this node's description.

Returns:
this node's description.

setDescription

public void setDescription(String description)
Sets this node's description to the specified description.

Parameters:
description - description of this node.

getProperties

public Map getProperties()
Returns this node's user properties. The returned map is fully modifiable and expects entries of the form (String, Object). Changing the returned map will fire an event to all PropertyChangeListeners registered with this node.

Returns:
this node's user properties.

fireNameChanged

protected void fireNameChanged(String oldName,
                               String newName)
Notifies node listeners that this node's name was changed.

Parameters:
oldName - this node's old name.
newName - this node's new name.

fireDescriptionChanged

protected void fireDescriptionChanged(String oldDescription,
                                      String newDescription)
Notifies node listeners that this node's description was changed.

Parameters:
oldDescription - this node's old description.
newDescription - this node's new description.

fireLocationChanged

protected void fireLocationChanged(Point oldLocation,
                                   Point newLocation)
Notifies node listeners that this node's location was changed.

Parameters:
oldLocation - old location.
newLocation - new location.

fireParentReordered

protected void fireParentReordered(Node parent,
                                   int index)
Notifies node listeners and the belief updater that one of this node's parents was reordered.

Parameters:
parent - reordered parent.
index - old index of parent.