cox.jmatt.java.MathTools.graphing
Class Constraint

java.lang.Object
  extended by cox.jmatt.java.MathTools.graphing.Constraint

public class Constraint
extends java.lang.Object

This class exists to provide assistance and convenience when specifying limits, conditions, or constraints. A Constraint consists of a Requirement and a value against which that requirement is applied. The Requirement is in the form of a Requirement enum constant and the value is an Object.

A Constraint instance can be converted to String by its toString() method (of course!) but this class also contains a static method to parse such a string back into an instance. The format is fairly straightforward but should not be modified or created manually! Nested Constraints are possible, but the innermost MUST have a non-Constraint data Object. There is no toXML() method since the Constraint class does not have a pre-defined and specific place in the structure of a graph. This means implementations are responsible for handling them as needed. That is where the parseFromString() method comes into play: it re-creates a Constraint from its Stringified value.


Nested Class Summary
static class Constraint.Requirement
          This enum is provided as a switch()-able way to designate specific conditions and their targeted value.
 
Constructor Summary
Constraint()
          Create a Constraint in which the Condition is UNKNOWN and the values are null.
Constraint(Constraint.Requirement pCondition, java.lang.Object pValue)
          Create a Constraint in which the Condition and value are both specified.
Constraint(java.lang.String pCondition, java.lang.Object pValue)
          Create a Constraint from a String representation and an Object.
 
Method Summary
static Constraint.Requirement findRequirementByName(java.lang.String pName)
          This method provides a safe way to get a Requirement.
 Constraint.Requirement getRequirementByName(java.lang.String pName)
          Instance version of findRequirementByName().
static Constraint.Requirement match(java.lang.String pCondition)
          Match a Requirement to a String.
 Constraint.Requirement matchRequirement(java.lang.String pCondition)
          Instance version of match().
static Constraint parseFromString(java.lang.String pData)
          This method parses the toString() value from a Constraint and creates a new Constraint from it.
 Constraint.Requirement requirement()
          Fetch the value of this Constraint's Requirement.
 java.lang.String toString()
          Convert this Constraint to a String.
 java.lang.Object value()
          Fetch a reference to the value Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Constraint

public Constraint()
Create a Constraint in which the Condition is UNKNOWN and the values are null.


Constraint

public Constraint(Constraint.Requirement pCondition,
                  java.lang.Object pValue)
Create a Constraint in which the Condition and value are both specified.


Constraint

public Constraint(java.lang.String pCondition,
                  java.lang.Object pValue)
Create a Constraint from a String representation and an Object.

Method Detail

requirement

public Constraint.Requirement requirement()
Fetch the value of this Constraint's Requirement.


value

public java.lang.Object value()
Fetch a reference to the value Object. NOTE: This is a reference to the Object itself! No copies are made.


findRequirementByName

public static Constraint.Requirement findRequirementByName(java.lang.String pName)
This method provides a safe way to get a Requirement. If the String does not match, Requirement.UNKNOWN is returned. Any errors are reported at Debug level.


getRequirementByName

public Constraint.Requirement getRequirementByName(java.lang.String pName)
Instance version of findRequirementByName().


match

public static Constraint.Requirement match(java.lang.String pCondition)
Match a Requirement to a String. Returns Condition.UNKNOWN if no match is found.


matchRequirement

public Constraint.Requirement matchRequirement(java.lang.String pCondition)
Instance version of match().


toString

public java.lang.String toString()
Convert this Constraint to a String. The format is straightforward but must not be altered if the parseFromString() method might be needed. No XML-escaping is done so this should be done manually if it might appear in an XML document or if the value Object's String might contain XML-dangerous content.

Overrides:
toString in class java.lang.Object

parseFromString

public static final Constraint parseFromString(java.lang.String pData)

This method parses the toString() value from a Constraint and creates a new Constraint from it. It should not be used for any other purpose! There is no instance version.

WARNING: This method is brittle! Use only as directed if at all!!