com.sdm.quasar.client.core.data.structure
Class AbstractSimpleComputation

java.lang.Object
  extended bycom.sdm.quasar.client.core.data.structure.AbstractSimpleComputation
All Implemented Interfaces:
Computation
Direct Known Subclasses:
IntegerToStringConversion

public abstract class AbstractSimpleComputation
extends java.lang.Object
implements Computation

A base class for simple cases of computations. This implementation assumes that the computation simply needs the values of all source nodes to compute its own value.

Implementations using this class must implement #computeFromValues(Object[]), {@link Computation#getType()}, and {@link Computation#getSourceTypes()}. If the computation is reversable, {@link #supportsReverse()} and {@link #reverseComputationToValues(Object, Object[])} must be overridden.

Computations that need to manipulate the context or that don't need the values of all source nodes should not be derived from this class but instead implement {@link com.sdm.quasar.client.core.data.structure.Computation} directly.

Version:
1.0
Author:
Thomas Wolf, sd&m AG, Bernd Olleck, sd&m AG

Constructor Summary
AbstractSimpleComputation()
           
 
Method Summary
abstract  java.lang.Object computeFromValues(java.lang.Object[] sourceValues)
          Performs the computation.
 java.util.Set computeIndexSet(ComputationValueAccess sourceValuesAccess, Context context)
          Performs the computation of a Set of the index values.
 java.lang.Object computeValue(ComputationValueAccess sourceValuesAccess, Context context)
          Performs the computation with an context. This implementation retrieves all source values using #getValues(ComputationValueAccess) and passes them on to computeFromValues(Object[]).
 java.lang.Object[] reverseComputationToValues(java.lang.Object targetValue, java.lang.Object[] sourceValues)
          Perform a reverse computation computes the correct source values with respect to the target value.
 void reverseValueComputation(java.lang.Object targetValue, ComputationValueAccess sourceValuesAccess, Context context)
          Perform a reverse computation computes the correct source values with respect to the target value with a context. The resulting new source values must be set using the ComputationValueAccess. This implementation retrieves all source values using #getValues(ComputationValueAccess) and passes them to reverseComputationToValues(Object, Object[]).
 boolean supportsReverse()
          This implementation returns false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sdm.quasar.client.core.data.structure.Computation
getSourceTypes, getType
 

Constructor Detail

AbstractSimpleComputation

public AbstractSimpleComputation()
Method Detail

computeValue

public final java.lang.Object computeValue(ComputationValueAccess sourceValuesAccess,
                                           Context context)
Performs the computation with an context. This implementation retrieves all source values using #getValues(ComputationValueAccess) and passes them on to computeFromValues(Object[]).

Specified by:
computeValue in interface Computation
Parameters:
sourceValuesAccess - the access source values
context - the context to be used
Returns:
the result
See Also:
Computation.computeValue(com.sdm.quasar.client.core.data.structure.ComputationValueAccess, com.sdm.quasar.client.core.data.Context)

reverseValueComputation

public final void reverseValueComputation(java.lang.Object targetValue,
                                          ComputationValueAccess sourceValuesAccess,
                                          Context context)
Perform a reverse computation computes the correct source values with respect to the target value with a context. The resulting new source values must be set using the ComputationValueAccess. This implementation retrieves all source values using #getValues(ComputationValueAccess) and passes them to reverseComputationToValues(Object, Object[]). The result of reverseComputationToValues(Object, Object[]) is set to the ComputationValueAccess.

Specified by:
reverseValueComputation in interface Computation
Parameters:
targetValue - the target value
sourceValuesAccess - the access current source values
context - the context to be used
See Also:
Computation.reverseValueComputation(java.lang.Object, com.sdm.quasar.client.core.data.structure.ComputationValueAccess, com.sdm.quasar.client.core.data.Context)

computeIndexSet

public java.util.Set computeIndexSet(ComputationValueAccess sourceValuesAccess,
                                     Context context)
Description copied from interface: Computation
Performs the computation of a Set of the index values. The method returns null for not indexed nodes.

Specified by:
computeIndexSet in interface Computation
Parameters:
sourceValuesAccess - the access source values
context - the context to be used
Returns:
a Set of the index values or null
See Also:
Computation.computeIndexSet(com.sdm.quasar.client.core.data.structure.ComputationValueAccess, com.sdm.quasar.client.core.data.Context)

computeFromValues

public abstract java.lang.Object computeFromValues(java.lang.Object[] sourceValues)
Performs the computation.

Parameters:
sourceValues - the source values
Returns:
the result

supportsReverse

public boolean supportsReverse()
This implementation returns false. Override this method if your computation is reversible.

Specified by:
supportsReverse in interface Computation
Returns:
true iff the computation supports a reverse computation
See Also:
Computation.supportsReverse()

reverseComputationToValues

public java.lang.Object[] reverseComputationToValues(java.lang.Object targetValue,
                                                     java.lang.Object[] sourceValues)
Perform a reverse computation computes the correct source values with respect to the target value. When passed to the method, the source values will have the current values if available.

This implementation throws an UnsupportedOperationException. Override this method if your computation is reversible.

Parameters:
targetValue - the target value
sourceValues - the current source values
Returns:
the new source values
Throws:
java.lang.UnsupportedOperationException - if the reverse computation is not supported