Package generic.constraint
Class DecisionTree<T>
java.lang.Object
generic.constraint.DecisionTree<T>
- Type Parameters:
T
- the type of object that the constraints are checked against.
- Direct Known Subclasses:
ProgramDecisionTree
A decisionTree is used to find property values that are determined by traversing a tree
of constraints. Each node in the tree has an associated constraint. If the constraint is
satisfied for a given test object, then its child nodes are tested to find more and more
specific results. When either there are no children in a node or none of the children's
constraints are satisfied or by traversing those that are satisfied did not result in find
a property match, the current node is check to see if it has a value for the property being
search. If so, that result is added as a Decision.
There can be multiple paths where all constraints a matched resulting in multiple possible decisions.
A non-leaf node can have properties as well, that serve as a default if it's constraint is satisfied, but not of its children is satisfied or resulted in a decision.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetDecisionsSet
(T testObject, String propertyName) Searches the decision tree for values of given property name that match the constraints within this tree.void
loadConstraints
(ResourceFile file) Loads the tree from an xml constraint file.void
loadConstraints
(String name, InputStream stream) Loads the tree from an xml data contained within an input stream.void
registerConstraintType
(String name, Class<? extends Constraint<T>> constraintClass) Registers a constraint class to be recognized from an xml constraint specification file.void
registerPropertyName
(String propertyName) Registers a property name.
-
Constructor Details
-
DecisionTree
public DecisionTree()
-
-
Method Details
-
getDecisionsSet
Searches the decision tree for values of given property name that match the constraints within this tree.- Parameters:
testObject
- the object that the constraints are test against.propertyName
- the name of the property whose values are being collected.- Returns:
- a DecisionSet containing all the values of the given property whose path in the tree matched all the constraints for the given test object.
-
registerConstraintType
Registers a constraint class to be recognized from an xml constraint specification file.- Parameters:
name
- the name of the constraint which is also the xml tag value.constraintClass
- the constraint type which will be initialized from the xml constraint specification file.
-
registerPropertyName
Registers a property name. Every tag in an xml constraint file (except the root tag which is unused) must be either a constraint name or a property name.- Parameters:
propertyName
- the name of a valid property to be expected in an xml constraints file.
-
loadConstraints
Loads the tree from an xml data contained within an input stream. Note: this method can be called multiple times, with each call appending to the existing tree.- Parameters:
name
- the name of the input source so that decisions can be traced back to the appropriate xml constraints source.stream
- the InputStream from which to read an xml constraints specification.- Throws:
IOException
- if an I/O problem occurs reading from the stream.XmlParseException
- if the XML is not property formatted or a tag that is not a constraint name or property name is encountered.
-
loadConstraints
public void loadConstraints(ResourceFile file) throws FileNotFoundException, IOException, XmlParseException Loads the tree from an xml constraint file. Note: this method can be called multiple times, with each call appending to the existing tree.- Parameters:
file
- the file that contains the xml for the constraint.- Throws:
IOException
- if an I/O problem occurs reading from the stream.XmlParseException
- if the XML is not property formatted or a tag that is not a constraint name or property name is encountered.FileNotFoundException
-