com.tensegrity.generic.constraint
Interface Constraint

All Known Subinterfaces:
BinaryConstraint, UnaryConstraint
All Known Implementing Classes:
com.tensegrity.generic.constraint.AbstractConstraint, AndConstraint, MetricExpressionConstraint, NegateConstraint, NumberConstraint, OrConstraint, StrokePatternConstraint

public interface Constraint

A Constraint can be used to validate any type of non-primitive Java object. Its use is not reserved for a certain context or set of classes but may be used independently from the rest of the API whenever certain conditions on object values must be checked programmatically.

A Constraint is created by passing a String expression to an instance of class ConstraintParser. After successful parsing, the parser returns a reference to a compiled Constraint instance. This instance is immutable (non-modifiable).

Class Diagram Constraint

All Constraint instances implement the toString() method by returning a String that may be legally parsed again. This means that you can assemble existing constraints without knowing their exact contents by using a logical operator. In the event a parser fails to compile a Constraint instance, an exception of type ConstraintParserException is thrown. Representing constraints by strings is highly beneficial, assembling them is easy and representing them in memory becomes very compact. Constraint instances are also pooled.

Constraints can be concatenated into constraint-trees or constraint- hierarchies. These trees are similiar to expression syntax trees. A single constraint like the AndConstraint can concatenate two or more constraints logically and thereby allowing the user to define almost arbitrary complex restrictions of all possible kinds.

Constraints implement the flyweight pattern. They are sharable objects with no dynamic intrinsic state. All the dynamic state is extrinsic and passed into the Constraint by invoking the validate(Object) method.

Version:
$Id: Constraint.java,v 1.21 2005/06/16 16:14:18 AndreasEbbert Exp $
Author:
S. Rutz, M. Kegel
See Also:
ConstraintParser, Attribute

Method Summary
 Constraint intern()
          This method pools the constraint analogous to the String.intern() method.
 void trace(java.lang.StringBuffer sb)
          This method is called to trace for the last error.
 boolean validate(java.lang.Object value)
          Validates this contraint against a given value.
 

Method Detail

validate

public boolean validate(java.lang.Object value)
Validates this contraint against a given value.
Notice:The given argument may not be null.

Parameters:
value - the object to validate. It is not allowed to pass in null as an argument.
Returns:
true if this value confirms to this constraints and false if it doesn't.
Throws:
InvalidArgumentException - thrown if the input object is null.

trace

public void trace(java.lang.StringBuffer sb)
This method is called to trace for the last error.
Notice:
The given argument may not be null.

Parameters:
sb - the StringBuffer to append the error message to. It is not allowed to pass in null as this argument.

intern

public Constraint intern()
This method pools the constraint analogous to the String.intern() method.

Returns:
the pooled reference for the given constraint.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.