Class SessionNode
- All Implemented Interfaces:
Node
,TetradSerializable
,Serializable
,Comparable<Node>
Represents a node in a session for a model in a particular class. The sets of possible model classes for this node are given in the constructors of the model classes for the node. Parents (also SessionNodes) may be added to this node provided some combination of the parents' model classes serves a partial argument set to some constructor of the one of this node's model classes. To put it slightly differently, parents can be added to this node one at a time, though at any step along the way it ought to be possible (perhaps by adding more parent nodes) to use the parent models to construct a model of one of the legal types for this node.> 0
To retrieve the list of classes for which models may be created, call the getConsistentModelClasses
. To construct a model for a particular model choice, call
createModel
method for the desired class. If the model has a
parameterizing object, this object may be passed in using the
createParameterizedModel
method. For parameterized models, the
model object is treated simply as an additional parent to the model and therefore must appear as an argument to one
of the constructors of the model.> 0
This node keeps track of its parents and its children and keeps these two sets of SessionNodes in sync.> 0
- Author:
- josephramsey
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionSessionNode
(Class modelClass) Creates a new session node capable of implementing the given model class.SessionNode
(Class[] modelClasses) Creates a new session node with the given name capable of implementing the given model classes.SessionNode
(String boxType, String displayName, Class modelClass) Creates a new session node with the given name, capable of implementing the given model class.SessionNode
(String boxType, String displayName, Class[] modelClasses) Creates a new session node with the given name capable of implementing the given model classes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(String key, Object value) boolean
addChild
(SessionNode child) Adds a child to the node, provided this node can be added as a parent to the child node.boolean
addParent
(SessionNode parent) Adds a parent to this node provided the resulting set of parents taken together provides some combination of possible model classes that can be used as a constructor to some one of the model classes for this node.boolean
addParent2
(SessionNode parent) Same as addParent except tests if this has already been created.void
Adds a property change listener.void
Adds a session listener.boolean
assignClasses
(Class[] constructorTypes, Class[] modelTypes, boolean exact, List<SessionNode> existingNodes) Object[]
assignParameters
(Class[] parameterTypes, List objects) Returns the objects in the List as an array in the same order as the parameter types.int
Returns the hashcode for this node.boolean
containsChild
(SessionNode child) boolean
createModel
(boolean simulation) Creates a model, provided the class of the model can be uniquely determined without any further hints.void
createModel
(Class modelClass, boolean simulation) Creates a model of the given class using models of the parent SessionNodes as constructor arguments.void
Sets the model to null.boolean
existsConstructor
(Class modelClass, Class[] argumentTypes) Tests whether the model class has an argument that takes all of the given argument classes (or more) as arguments.boolean
existsParameterizedConstructor
(Class modelClass) void
Forgets the old model so that it can't be used to recapture parameter values.void
getAssignableClass
(List classes, Class clazz) Returns the first class c inclasses
thatclazz
is assignable to.> 0getAttribute
(String key) Gets the (optional) name of this node.int
Returns the x coordinate of the center of this node.int
Returns the y coordinate of the center of this node.Class[]
getConsistentModelClasses
(boolean exact) getLoggerConfig
(Class modelClass) getModel()
Class[]
Object[]
getModelConstructorArguments
(Class modelClass) getName()
Returns the name of this node.Returns the node type for this node.Returns the node shape for this node.int
int
Gets the parameter object for the givem model class.int
getProduct
(int[] arr) int
int[]
getValueCombination
(int index, int[] numValues) boolean
isConsistentModelClass
(Class<Type1> modelClass, List nodes, boolean exact) Determines whether a given model class is consistent with the models contained in the given List of nodes, in the sense that the model class has a constructor that can take the models of the nodes as arguments.boolean
isConsistentParent
(SessionNode parent) boolean
isConsistentParent
(SessionNode parent, List<SessionNode> existingNodes) boolean
boolean
Tests whether two session nodes that are not necessarily object identical are nevertheless identical in structure.Creates a new node of the same type as this one with the given name.void
putParam
(Class modelClass, Parameters param) Sets the parameter object for the given model class to the given object.void
removeAttribute
(String key) boolean
removeChild
(SessionNode child) Removes a child from the node.void
removeParam
(Class modelClass) Removes the parameter object for the given model class.boolean
removeParent
(SessionNode parent) Removes a parent from the node.void
Removes a session listener.void
Resets this sesion node to the state it was in when first constructed.void
void
restrictConnectionsToList
(List sessionNodes) Removes any parents or children of the node that are not in the given list.void
Removes any listeners that are not SessionNodes.static SessionNode
Generates a simple exemplar of this class to test serialization.final void
setBoxType
(String boxType) Sets the (optional) name for this node.void
setCenter
(int centerX, int centerY) Sets the (x, y) coordinates of the center of this node.void
setCenterX
(int centerX) Sets the x coordinate of the center of this node.void
setCenterY
(int centerY) Sets the y coordinate of the center of this node.final void
setDisplayName
(String displayName) final void
setModelClasses
(Class[] modelClasses) Sets the model classes to the new array of model classes.void
Sets the name of this node.void
setNextEdgeAddAllowed
(boolean nextEdgeAddAllowed) True iff the next edge should not be added.void
setNodeType
(NodeType nodeType) Sets the node type for this node.void
setNodeVariableType
(NodeVariableType nodeVariableType) Sets the type (domain, interventional status, interventional value..) for this node variablevoid
setRepetition
(int repetition) toString()
Prints out the name of the session node.boolean
-
Constructor Details
-
SessionNode
Creates a new session node capable of implementing the given model class. -
SessionNode
Creates a new session node with the given name, capable of implementing the given model class.- Parameters:
boxType
- The name of the box type--for instance, "Graph."displayName
- The name of this particular session node. Any non-null string.modelClass
- A single model class associated with this session node.
-
SessionNode
Creates a new session node with the given name capable of implementing the given model classes. -
SessionNode
Creates a new session node with the given name capable of implementing the given model classes. When models are created, they will be of one of these classes. Reflection will be used to create the models by matching the models of the parent Session Nodes to constructor arguments of the class given as argument to thecreateModel
method, which must itself be one of these model classes.- Parameters:
boxType
- The name of the box type--for instance, "Graph."displayName
- The name of this particular session node. Any non-null string.modelClasses
- An array of model classes associated with this session node.
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization. -
addParent
Adds a parent to this node provided the resulting set of parents taken together provides some combination of possible model classes that can be used as a constructor to some one of the model classes for this node. -
isConsistentParent
-
isConsistentParent
-
addParent2
Same as addParent except tests if this has already been created. If so the user is asked whether to add parent and update parent's desendents or to cancel the operation. -
removeParent
Removes a parent from the node. -
getParents
- Returns:
- the set of parents.
-
getNumParents
public int getNumParents()- Returns:
- the number of parents.
-
addChild
Adds a child to the node, provided this node can be added as a parent to the child node. -
containsChild
- Returns:
- true iff the given node is child of this node.
-
removeChild
Removes a child from the node. -
getChildren
- Returns:
- the set of children.
-
getNumChildren
public int getNumChildren()- Returns:
- the number of children.
-
createModel
public boolean createModel(boolean simulation) Creates a model, provided the class of the model can be uniquely determined without any further hints. If a model was created previously, the previous model class is used. If there is only one consistent model class, than that model class is used. Otherwise, an exception is thrown.- Returns:
- true iff this node contains a model when this method completes.
- Throws:
RuntimeException
- if the model could not be created.
-
createModel
Creates a model of the given class using models of the parent SessionNodes as constructor arguments. If no appropriate constructor is available, no model is created, and the method returns false. If the attempt to construct a model using reflection fails, the stack trace is printed to System.err and an IllegalArgumentException is thrown. t- Throws:
RuntimeException
- if the attempt to construct the model throws either an IllegalAccessException, an InstantiationException, or an InvocationTargetException. In this case, a stack trace is printed to System.err.Exception
-
getLoggerConfig
-
getLoggerConfig
-
destroyModel
public void destroyModel()Sets the model to null. This step must be performed before a new model can be created. -
forgetOldModel
public void forgetOldModel()Forgets the old model so that it can't be used to recapture parameter values. -
getModelClasses
- Returns:
- the class of the model.
-
setModelClasses
Sets the model classes to the new array of model classes. -
getConsistentModelClasses
- Parameters:
exact
-- Returns:
- those model classes among the possible model classes that are at least consistent with the model class of the parent session nodes, in the sense that possibly with the addition of more parent session nodes, and assuming that the models of the parent session nodes are non-null, it is possible to construct a model in one of the legal classes for this node using the parent models as arguments to some constructor in that class.
-
getModel
- Returns:
- the model, or null if no model has been created yet.
-
getLastModelClass
- Returns:
- the class of the last model that was created, or null if no model has been created yet.
-
addSessionListener
Adds a session listener. -
removeSessionListener
Removes a session listener. -
isFreshlyCreated
public boolean isFreshlyCreated()- Returns:
- true iff this node is in a freshly created state. A node that is in a freshly created state has no model, no parents, no children, and no listeners. It does, however, have the array of possible model classes that it was constructed with, and it may or may not have a name.
-
resetToFreshlyCreated
public void resetToFreshlyCreated()Resets this sesion node to the state it was in when first constructed. Removes any parents or children, destroys the model if there is one, and resets all listeners. Fires an event for each action taken. -
restrictConnectionsToList
Removes any parents or children of the node that are not in the given list. -
restrictListenersToSessionNodes
public void restrictListenersToSessionNodes()Removes any listeners that are not SessionNodes. -
isStructurallyIdentical
Tests whether two session nodes that are not necessarily object identical are nevertheless identical in structure. This method should not be made to override
equals
sinceequals
is used in the Collections API to determine, for example, containment in an ArrayList, and the sense of equality needed for that is object identity. Nevertheless, for certain other purposes, such as checking serialization, a looser sense of structural identity is helpful.> 0Two SessionNodes are structurally identical just in case their possible model classes are equal, the parameter type arrays used to construct their models are equal, their models themselves are equal, and the model classes of the parent and child SessionNodes are equal. We dare not check equality of parents and children outright for fear of circularity.> 0
-
getBoxType
Gets the (optional) name of this node. May be null. -
setBoxType
Sets the (optional) name for this node. May be null. -
putParam
Sets the parameter object for the given model class to the given object. -
getParam
Gets the parameter object for the givem model class. -
removeParam
Removes the parameter object for the given model class. -
getModelConstructorArguments
-
getName
Description copied from interface:Node
Returns the name of this node. -
setName
Description copied from interface:Node
Sets the name of this node. -
getNodeType
Description copied from interface:Node
Returns the node type for this node.- Specified by:
getNodeType
in interfaceNode
- Returns:
- the node type for this node.
-
setNodeType
Description copied from interface:Node
Sets the node type for this node.- Specified by:
setNodeType
in interfaceNode
- Parameters:
nodeType
- the node type for this node.
-
toString
Prints out the name of the session node. -
getCenterX
public int getCenterX()Description copied from interface:Node
Returns the x coordinate of the center of this node.- Specified by:
getCenterX
in interfaceNode
- Returns:
- the x coordinate of the center of the node.
-
setCenterX
public void setCenterX(int centerX) Description copied from interface:Node
Sets the x coordinate of the center of this node.- Specified by:
setCenterX
in interfaceNode
- Parameters:
centerX
- This coordinate.
-
getCenterY
public int getCenterY()Description copied from interface:Node
Returns the y coordinate of the center of this node.- Specified by:
getCenterY
in interfaceNode
- Returns:
- the y coordinate of the center of the node.
-
setCenterY
public void setCenterY(int centerY) Description copied from interface:Node
Sets the y coordinate of the center of this node.- Specified by:
setCenterY
in interfaceNode
- Parameters:
centerY
- This coordinate.
-
setCenter
public void setCenter(int centerX, int centerY) Description copied from interface:Node
Sets the (x, y) coordinates of the center of this node. -
addPropertyChangeListener
Description copied from interface:Node
Adds a property change listener.- Specified by:
addPropertyChangeListener
in interfaceNode
- Parameters:
l
- This listener.
-
like
Description copied from interface:Node
Creates a new node of the same type as this one with the given name. -
compareTo
Description copied from interface:Node
Returns the hashcode for this node.- Specified by:
compareTo
in interfaceComparable<Node>
- Specified by:
compareTo
in interfaceNode
- Parameters:
node
- the object to be compared.- Returns:
- the hashcode for this node.
-
existsParameterizedConstructor
-
getRepetition
public int getRepetition() -
setRepetition
public void setRepetition(int repetition) -
useClonedModel
public boolean useClonedModel()- Returns:
- true if the cloning operation was successful, false if not. If the cloning operation was not successful, the model will not have been altered.
-
forgetSavedModel
public void forgetSavedModel() -
restoreOriginalModel
public void restoreOriginalModel() -
isConsistentModelClass
Determines whether a given model class is consistent with the models contained in the given List of nodes, in the sense that the model class has a constructor that can take the models of the nodes as arguments. -
existsConstructor
Tests whether the model class has an argument that takes all of the given argument classes (or more) as arguments. The purpose of this is to allow parent nodes to be added one at a time to this node, whether or not any of the nodes in question have non-null models.> 0
-
getAssignableClass
Returns the first class c in
classes
thatclazz
is assignable to.> 0 -
assignParameters
Returns the objects in the List as an array in the same order as the parameter types. If an exact match cannot be found, throws a RuntimeException with an appropriate message.
- Parameters:
parameterTypes
- a list of classes; if any of them is null, a NullPointerException will be thrown.objects
- a List of objects. (The nulls will be automatically thrown out for this one.)- Throws:
RuntimeException
-
assignClasses
public boolean assignClasses(Class[] constructorTypes, Class[] modelTypes, boolean exact, List<SessionNode> existingNodes) throws RuntimeException - Throws:
RuntimeException
-
getValueCombination
public int[] getValueCombination(int index, int[] numValues) - Returns:
- an array with a combination of particular values for variables given an array indicating the number of values for each variable.
-
getProduct
public int getProduct(int[] arr) - Returns:
- the product of the entries in the given array.
-
setNextEdgeAddAllowed
public void setNextEdgeAddAllowed(boolean nextEdgeAddAllowed) True iff the next edge should not be added. (Included for GUI user control.) Reset to true every time an edge is added; edge adds must be disallowed individually. To disallow the next edge add, set to false. -
getDisplayName
-
setDisplayName
-
getParameters
-
getNodeVariableType
Description copied from interface:Node
Returns the node shape for this node.- Specified by:
getNodeVariableType
in interfaceNode
- Returns:
- the intervention type
-
setNodeVariableType
Description copied from interface:Node
Sets the type (domain, interventional status, interventional value..) for this node variable- Specified by:
setNodeVariableType
in interfaceNode
- Parameters:
nodeVariableType
- the type (domain, interventional status, interventional value..) for this node variable
-
getAllAttributes
- Specified by:
getAllAttributes
in interfaceNode
-
getAttribute
- Specified by:
getAttribute
in interfaceNode
-
removeAttribute
- Specified by:
removeAttribute
in interfaceNode
-
addAttribute
- Specified by:
addAttribute
in interfaceNode
-