NORSYS SOFTWARE © 2012 | NETICA API | JAVA VERSION 5.04 |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--norsys.netica.General
A class that provides generic useful documentation and utility information regarding a Netica object.
Currently only Net, Node, and int extend this class, but other classes may do so in future.
There is no public constructor for the General class; obtain a General object by constructing a Node or Net or by calling Node.state
A General object contains accessors and mutators for the following data:
name | A size-restricted and character restricted name for the object. Must contain only ascii letters, digits, or underscores, start with a letter, and be of 30 characters or less in length. | |
title | An unrestricted name for the object. May be any length of arbitrary Unicode, but recommended that it not be very long (the comment field is available for that). | |
comment | An unrestricted comment text block (any length of arbitrary Unicode), but semantically meant to describe or give detailed documentation concerning the object in question. | |
user fields | A set of key-value pairs (attribute-value pairs), where the keys are strings and the values may be of a variety of types. These WILL be saved when the General object is written to a file or stream. All userFields are placed in the User object owned by this General. Access them by calling user()user . For example: node.user().setString ("extraInfo", "This is some extra information."); | |
user reference | A single arbitrary object (but can be absolutely anything, including a Collection) that will NOT be saved when this General object is written to a file or stream, or duplicated when this General object is duplicated. The userReference resides in the User object owned by this General. Access it by calling user()user . For example: node.user().setReference (myCollection); |
Note. Currently States only have the name, title, and comment methods. This restriction will be removed in a future release of Netica.
Field Summary | |
static int |
NAME_MAX
The maximum number of characters in the name of a General Netica object (e.g., Node, Net, State). |
Constructor Summary | |
General()
|
Method Summary | |
void |
addListener(NeticaListener listener)
Adds the given listener to this object's list of listeners. |
void |
eventOccurred(NeticaEvent event)
Netica calls back this method when an event occurred to an object we expressed interest in (by calling addListener). |
java.lang.String |
getComment()
Gets the documentation text concerning this object. |
Environ |
getEnviron()
Returns the Environ this object belong's to. |
java.lang.String |
getLabel()
|
java.lang.String |
getLabel(java.lang.String options)
|
java.lang.String |
getName()
Returns the identifer name of this object. |
java.lang.String |
getTitle()
Gets the unrestricted label of this object. |
void |
removeListener(NeticaListener listener)
Removes the given listener from this object's list of listeners. |
void |
setComment(java.lang.String comment)
Sets the documentation or a description of an object. |
void |
setName(java.lang.String name)
Changes the name of this object to be name. |
void |
setTitle(java.lang.String title)
Sets the title of this object to the unrestricted string title. |
java.lang.String |
toString()
Returns the value of getName. |
User |
user()
Retrieve the User object that stores user controlled data associated with this object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int NAME_MAX |
Constructor Detail |
public General ( ) throws NeticaException |
Method Detail |
public void addListener ( |
| ) throws NeticaException |
Currently only Net and Node objects accept listeners.
Parameters:
NeticaListener | listener | The object to be informed. |
removeListener | Removes a listener from the listener list | |
eventOccurred | Receives the event |
The following complete program illustrates how any java object, if it chooses to implement the NeticaListener interface, can listen to NeticaEvents:/* * SampleListener.java * * Example use of NeticaListener interface to listen to NeticaEvents on objects. * * Copyright (c) 2002 by Norsys Software Corp. */ import norsys.netica.*; public class SampleListener implements NeticaListener { public static void main (String[] arg) { SampleListener sa = new SampleListener(); sa.run(); } public void run() { try { Environ env = new Environ (null); Net net = new Net(); net.setName("testNet"); Node node1 = new Node ("node1", 0, net); Node node2 = new Node ("node2", 0, net); Node node3 = new Node ("node3", 0, net); Node node4 = new Node ("node4", 0, net); node1.addListener (this); node2.addListener (this); node3.addListener (this); // note, we aren't listening to node4 net.addListener (this); System.out.println("----------- A"); node2.delete(); System.out.println("----------- B"); net.finalize(); System.out.println("----------- C"); } catch (Exception e) { e.printStackTrace(); } } public void eventOccurred(NeticaEvent ne) { if (ne.getKind() == NeticaEvent.REMOVE_EVENT) { System.out.print ("The following object has been removed from Netica: "); Object obj = ne.getObject(); // the object generating the event if (obj instanceof Node) { System.out.print ("(Node): "); } else if (obj instanceof Net) { System.out.print (" (Net): "); } System.out.println (obj); } } } When run, the above program prints the following:----------- A The following object has been removed from Netica: (Node): node2 ----------- B The following object has been removed from Netica: (Node): node1 The following object has been removed from Netica: (Node): node3 The following object has been removed from Netica: (Net): testNet ----------- C
public void eventOccurred ( |
| ) |
If you override this method, be sure to call the base class method (super.eventOccurred();).
Parameters:
NeticaEvent | event | An object providing information about the event that occurred. |
addListener | Indicates an object wants to receive events |
See addListener
eventOccurred
in interface NeticaListener
public String getComment ( ) throws NeticaException |
The comment may contain anything, but see setComment for what it's meant to contain.
There is no restriction on the length of the comment, or on what characters it might contain.
Note. Currently State's do not have comment fields, and so an exception is thrown if you attempt to call this method on a State object.
Version:
setComment | Sets it |
public Environ getEnviron ( ) throws NeticaException |
public String getLabel ( ) throws NeticaException |
public String getLabel ( |
| ) throws NeticaException |
public String getName ( ) throws NeticaException |
You can count on the name to be present, and to be a legal IDname , which means that it begins with a letter, is composed only of ascii letters, numbers, or underscores, and is NAME_MAX (30) or fewer characters in length.
Note that two different nets in Netica's memory may have the same name, however, two different nodes in a net always have distinct names, and two different node-states in the same node always have distinct names also.
If you have never set a Net's name, it will be assigned a default name of the form "Unnamed_#" where '#' is an integer.
If you have never set a State's name, this will return a default name of the form "s#" where '#' is the state index.
Version:
setName | Sets it | |
getTitle | Longer, unrestricted label |
public String getTitle ( ) throws NeticaException |
Returns the title of this object, or the empty string (rather than null) if this object does not have a title.
This may be different from this object's "name"
.
There is no restriction on the length of the title, or on what characters it might contain.
Keep in mind that titles are not necessarily unique.
Version:
setTitle | Sets it | |
getName | Gets this object's name (limited chars and length, always exists) |
public void removeListener ( |
| ) throws NeticaException |
NeticaListener | listener | The object to be removed from the listener list. |
addListener | Adds a listener to the listener list |
public void setComment ( |
| ) throws NeticaException |
This associates the character string comment with this object (net or node) to help document it.
The comment may contain anything, but is usually used to store such things as the origin of this object, its purpose or applicability, background information on the problem domain, a copyright notice, how to use this object, notes for future changes, etc. It is best if the comment consists only of that sort of descriptive information (and as ascii text characters), in order to meet expectations in case you share this Bayes net with other people or view it with Netica Application. If you wish to attach other data, and this object is a Net or Node, use its User object (retrieved with the user method).
To remove a comment, pass null or the empty string for comment.
Note. Currently State's do not have comment fields, and so an exception is thrown if you attempt to call this method on a State object.
Parameters:
String | comment | A text String of arbitrary length. |
getComment | Retrieves value | |
user | To attach other types of information, and have it saved to file with the net |
// append String addon to the end of the existing comment for net // net.setComment( net.getComment() + addon);
public void setName ( |
| ) throws NeticaException |
name must be a legal IDname, which means it must have NAME_MAX (30) or fewer ascii characters, all of which are letters, digits or underscores, and it must start with a letter.
Two nodes in the same net may not have identical names, and two states in the same node may not have identical names (case sensitive comparison). (However, two nets in the same environment, may have identical names.)
Throws a NeticaException, if the name is invalid, explaining why it is invalid.
For General State objects only
Node.setStateNames
.String | name | The new name desired. |
getName | Retrieves value | |
setTitle | Doesn't have the restriction of an IDname |
public void setTitle ( |
| ) throws NeticaException |
"name"
).
It is advised not to put too much information in the title, since the "comment"
field is available for that.
To remove a title, pass null or the empty string for title.
Titles never have to be unique; two nodes in the same net can have the same title as can two states in the same node, although usually that is not advisable.
Parameters:
String | title | The new title desired. |
getTitle | Retrieves value | |
setName | The short, restricted name | |
setComment | For longer descriptions |
public String toString ( ) |
toString
in class java.lang.Object
public User user ( ) throws NeticaException |
Currently, only Net and Node objects have User objects.
Version:
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |