de.jstacs.parameters.validation
Class SimpleStaticConstraint

java.lang.Object
  extended by de.jstacs.parameters.validation.SimpleStaticConstraint
All Implemented Interfaces:
Constraint, Storable, Cloneable

public class SimpleStaticConstraint
extends Object
implements Constraint

Class for a Constraint that checks values against static values using the comparison operators defined in the interface Constraint. As long as just an upper and lower bound shall be checked, NumberValidator has the same functionality and is easier to use. Thus it is recommended to use this class for more complex constraints, e.g. multiple allowed ranges or combinations of static and reference-based constraints.

Author:
Jan Grau
See Also:
NumberValidator

Field Summary
 
Fields inherited from interface de.jstacs.parameters.validation.Constraint
EQUALS, GEQ, GT, LEQ, LT
 
Constructor Summary
SimpleStaticConstraint(Number reference, int comparisonOperator)
          Creates a new SimpleStaticConstraint from a Number -reference and a comparison operator as defined in Constraint.
SimpleStaticConstraint(StringBuffer representation)
          The standard constructor for the interface Storable.
SimpleStaticConstraint(String reference, int comparisonOperator)
          Creates a new SimpleStaticConstraint from a String -reference and a comparison operator as defined in Constraint.
 
Method Summary
 boolean check(Object value)
          Checks value for the constraint defined in the Constraint.
 SimpleStaticConstraint clone()
          This method returns a deep copy of the current instance.
 void fromXML(StringBuffer representation)
          Parses a SimpleStaticConstraint from the XML representation as returned by toXML().
 String getErrorMessage()
          Returns the message of the last error (missed constraint) or null if the constraint was fulfilled by the last checked value.
 StringBuffer toXML()
          This method returns an XML representation as StringBuffer of an instance of the implementing class.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleStaticConstraint

public SimpleStaticConstraint(Number reference,
                              int comparisonOperator)
Creates a new SimpleStaticConstraint from a Number -reference and a comparison operator as defined in Constraint.

Parameters:
reference - the Number-reference
comparisonOperator - the comparison operator

SimpleStaticConstraint

public SimpleStaticConstraint(String reference,
                              int comparisonOperator)
Creates a new SimpleStaticConstraint from a String -reference and a comparison operator as defined in Constraint.

Parameters:
reference - the String-reference
comparisonOperator - the comparison operator

SimpleStaticConstraint

public SimpleStaticConstraint(StringBuffer representation)
                       throws NonParsableException
The standard constructor for the interface Storable. Creates a new SimpleStaticConstraint from its XML representation.

Parameters:
representation - the XML representation as StringBuffer
Throws:
NonParsableException - if representation could not be parsed
Method Detail

clone

public SimpleStaticConstraint clone()
                             throws CloneNotSupportedException
Description copied from interface: Constraint
This method returns a deep copy of the current instance.

Specified by:
clone in interface Constraint
Overrides:
clone in class Object
Returns:
a deep copy of the current instance
Throws:
CloneNotSupportedException - if the Constraint could not be cloned
See Also:
Cloneable

check

public boolean check(Object value)
Description copied from interface: Constraint
Checks value for the constraint defined in the Constraint. If the constraint is fulfilled, true is returned.

Specified by:
check in interface Constraint
Parameters:
value - the Object to be checked
Returns:
true if the constraint is fulfilled, false otherwise

toXML

public StringBuffer toXML()
Description copied from interface: Storable
This method returns an XML representation as StringBuffer of an instance of the implementing class.

Specified by:
toXML in interface Storable
Returns:
the XML representation

fromXML

public void fromXML(StringBuffer representation)
             throws NonParsableException
Parses a SimpleStaticConstraint from the XML representation as returned by toXML().

Parameters:
representation - the XML representation
Throws:
NonParsableException - the XML code could not be parsed

getErrorMessage

public String getErrorMessage()
Description copied from interface: Constraint
Returns the message of the last error (missed constraint) or null if the constraint was fulfilled by the last checked value.

Specified by:
getErrorMessage in interface Constraint
Returns:
the message of the last error or null