com.tensegrity.generic.constraint
Class ConstraintPool

java.lang.Object
  extended bycom.tensegrity.generic.constraint.ConstraintPool

public class ConstraintPool
extends java.lang.Object

All constraints that a ConstraintParser creates are pooled. This means that parsing the same Constraint expressions more than once will have the effect of the parser returning the same reference for each distinct Constraint expression. This is a beneficial mechanism if particular constraints get reused frequently and their references are attached to a lot of different objects. In such a scenario, the memory footprint is greatly minimized by the pooling feature implemented in this class.

This class offers methods to manage constraint objects efficiently. The constraint objects are placed in an object pool (a HashMap).

This resembles the flyweight pattern. Constraint support the pooling functionality well, since their toString() methods return canonical textual representations of the constraint.

Version:
$Id: ConstraintPool.java,v 1.24 2006/01/26 17:11:06 MichaelKegel Exp $
Author:
M. Kegel, Stepan Rutz

Method Summary
static void clear()
          Clears the constraint pool by deleting all pooled items.
static void dump()
          Prints a dump of this pool to the standard-error output.
static void dump(java.io.PrintStream stream)
          Prints a dump of this pool to the specified PrintStream.
static Constraint get(java.lang.String constraintDescription)
          This method is called to get an instance of a pooled constraint
static void pool(Constraint constraint)
          This method is called to pool a constraint.
static int size()
          Returns the count of pooled constraints.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static final Constraint get(java.lang.String constraintDescription)
This method is called to get an instance of a pooled constraint

Parameters:
constraintDescription - the canonical description of the constraint to return.
Notice:The given argument may not be null.
Returns:
the corresponding constraint.

pool

public static final void pool(Constraint constraint)
This method is called to pool a constraint.

Parameters:
constraint - the constraint to be pooled. It is not allowed to specify null as an argument.
Throws:
InvalidArgumentException - if null is given as an argument.

dump

public static final void dump()
Prints a dump of this pool to the standard-error output.


dump

public static final void dump(java.io.PrintStream stream)
Prints a dump of this pool to the specified PrintStream.

Parameters:
stream - the PrintStream instance to use for output.

clear

public static final void clear()
Clears the constraint pool by deleting all pooled items.


size

public static final int size()
Returns the count of pooled constraints.

Returns:
the count of pooled constraints.


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