net.sf.molae.pipe.binop
Class AbstractBinaryFunction<S1,S2,T>

java.lang.Object
  extended by net.sf.molae.pipe.binop.AbstractBinaryFunction<S1,S2,T>
All Implemented Interfaces:
BinaryFunction<S1,S2,T>
Direct Known Subclasses:
PermutedFunction, SymmetricBinaryFunction

public abstract class AbstractBinaryFunction<S1,S2,T>
extends Object
implements BinaryFunction<S1,S2,T>

Skeleton implementation of BinaryFunction, that stores the related functions as properties. Only the compute(Object, Object) operation has to be implemented.


Constructor Summary
AbstractBinaryFunction(String name)
          Constructs a new AbstractBinaryFunction from the specified properties.
AbstractBinaryFunction(String name, boolean associative, boolean hasRightIdentityElements, boolean hasLeftSinks)
          Constructs a new AbstractBinaryFunction from the specified properties.
AbstractBinaryFunction(String name, boolean associative, boolean hasRightIdentityElements, boolean hasLeftSinks, boolean hasLeftIdentityElements, boolean hasRightSinks, String nameOfPermuted)
          Constructs a new AbstractBinaryFunction from the specified properties.
 
Method Summary
abstract  T compute(S1 arg1, S2 arg2)
          Performs a computation on the specified arguments and returns the result of that computation.
 BinaryFunction<T,S1,S2> getFirstInverse()
          Returns the first inverse of this function.
 BinaryFunction<S2,S1,T> getPermuted()
          Returns the permuted function of this function.
protected  boolean isAnIdentityElement(Object obj)
          Tests if the specified object is an identity element in at least one function of the circle.
protected  boolean isASink(Object obj)
          Tests if the specified object is a sink in at least one function of the circle.
 boolean isAssociative()
          Indicates if this function is associative.
 boolean isLeftSink(Object obj)
          Tests if the specified element is a left sink of this function.
 boolean isRightIdentityElement(Object obj)
          Tests if the specified element is a right identity element of this function.
 void setFirstInverse(BinaryFunction<T,S1,S2> firstInverse)
          Sets the first inverse of this function.
 void setPermuted(BinaryFunction<S2,S1,T> permuted)
          Specifies the permuted value.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractBinaryFunction

public AbstractBinaryFunction(String name,
                              boolean associative,
                              boolean hasRightIdentityElements,
                              boolean hasLeftSinks)
Constructs a new AbstractBinaryFunction from the specified properties.

Parameters:
name - the result of the toString() method
associative - this value is returned by the isAssociative() method.
hasRightIdentityElements - specifies if this method has one or more right identity elements.
hasLeftSinks - specifies if this method has one or more left sinks.

AbstractBinaryFunction

public AbstractBinaryFunction(String name,
                              boolean associative,
                              boolean hasRightIdentityElements,
                              boolean hasLeftSinks,
                              boolean hasLeftIdentityElements,
                              boolean hasRightSinks,
                              String nameOfPermuted)
Constructs a new AbstractBinaryFunction from the specified properties.

Parameters:
name - the result of the toString() method
associative - this value is returned by the isAssociative() method.
hasRightIdentityElements - specifies if this method has one or more right identity elements.
hasLeftSinks - specifies if this method has one or more left sinks.
hasLeftIdentityElements - specifies if this method has one or more left identity elements.
hasRightSinks - specifies if this method has one or more right sinks.
nameOfPermuted - the name of the associated permuted function.

AbstractBinaryFunction

public AbstractBinaryFunction(String name)
Constructs a new AbstractBinaryFunction from the specified properties.

Parameters:
name - the result of the toString() method
Method Detail

compute

public abstract T compute(S1 arg1,
                          S2 arg2)
Description copied from interface: BinaryFunction
Performs a computation on the specified arguments and returns the result of that computation.

Specified by:
compute in interface BinaryFunction<S1,S2,T>
Parameters:
arg1 - the first argument
arg2 - the second argument
Returns:
the result of the computation

getPermuted

public final BinaryFunction<S2,S1,T> getPermuted()
Description copied from interface: BinaryFunction
Returns the permuted function of this function. The permuted function is a binary function, that performs the same calculation as this function after exchanging the two operands.

Formally, for all a and b where compute is defined:

 compute(a,b).equals(getPermuted().compute(b,a))
 
If the implementing function is commutative, it is expected that equals(getPermuted()) returns true.

Specified by:
getPermuted in interface BinaryFunction<S1,S2,T>
Returns:
the permuted function of this function

setPermuted

public final void setPermuted(BinaryFunction<S2,S1,T> permuted)
Specifies the permuted value.

Parameters:
permuted - the permuted function of this function
Throws:
IllegalStateException - if the permuted function was already set before.
See Also:
getPermuted()

getFirstInverse

public BinaryFunction<T,S1,S2> getFirstInverse()
Description copied from interface: BinaryFunction
Returns the first inverse of this function. The first inverse is a binary function, so that the second operand can be recalculated with the first operand and the result of this function.

Formally, for all a and b where the implementing function is defined:

 compute(a,b).equals(c) ⇔ getFirstInverse().compute(c,a).equals(b)
 

Specified by:
getFirstInverse in interface BinaryFunction<S1,S2,T>
Returns:
the first inverse function of this function null if the first inverse function does not exist or is not defined.

setFirstInverse

public void setFirstInverse(BinaryFunction<T,S1,S2> firstInverse)
Sets the first inverse of this function. If the first inverse of the permuted function of the specified first inverse is not yet set it is set to the permuted function of this function.

Parameters:
firstInverse - the new value of the first inverse.
See Also:
getFirstInverse()

isAssociative

public final boolean isAssociative()
Description copied from interface: BinaryFunction
Indicates if this function is associative. More formally: It returns true if for two objects a and b: compute(a,compute(b,c)).equals(compute(compute(a,b),c)

It is not required that this method returns true, if the method is associative, so if no statement about associativity can be made, false is returned.

Specified by:
isAssociative in interface BinaryFunction<S1,S2,T>
Returns:
true if this function is associative.

isAnIdentityElement

protected boolean isAnIdentityElement(Object obj)
Tests if the specified object is an identity element in at least one function of the circle.

Parameters:
obj - the candidate for an identity element
Returns:
true if the specified object is an identity element in at least one function of the circle.

isRightIdentityElement

public boolean isRightIdentityElement(Object obj)
Tests if the specified element is a right identity element of this function. This implementation checks the hasRightElements property and isAnIdentityElement(Object).

Specified by:
isRightIdentityElement in interface BinaryFunction<S1,S2,T>
Parameters:
obj - the candidate for a right identity element
Returns:
true if the specified object is a right identity element of this function.

isASink

protected boolean isASink(Object obj)
Tests if the specified object is a sink in at least one function of the circle.

Parameters:
obj - the candidate for a sink
Returns:
true if the specified object is a sink in at least one function of the circle.

isLeftSink

public boolean isLeftSink(Object obj)
Tests if the specified element is a left sink of this function. This implementation checks the hasLeftSinks property and isASink(Object).

Specified by:
isLeftSink in interface BinaryFunction<S1,S2,T>
Parameters:
obj - the candidate for a left sink
Returns:
true if the specified object is a left sink of this function.

toString

public String toString()
Overrides:
toString in class Object