net.sf.molae.pipe.binop
Class AbstractBinaryFunction

java.lang.Object
  |
  +--net.sf.molae.pipe.binop.AbstractBinaryFunction
All Implemented Interfaces:
BinaryFunction
Direct Known Subclasses:
PermutedFunction, SymmetricBinaryFunction

public abstract class AbstractBinaryFunction
extends Object
implements BinaryFunction

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  Object compute(Object arg1, Object arg2)
          Performs a computation on the specified arguments and returns the result of that computation.
 BinaryFunction getFirstInverse()
          Returns the first inverse of this function.
 BinaryFunction 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 firstInverse)
          Sets the first inverse of this function.
 void setPermuted(BinaryFunction 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 Object compute(Object arg1,
                               Object 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
Following copied from interface: net.sf.molae.pipe.binop.BinaryFunction
Parameters:
arg1 - the first argument
arg2 - the second argument
Returns:
the result of the computation
Throws:
IllegalArgumentException - Some aspect of either argument prevents it from being computed.
ClassCastException - if the class of either argument is not accepted by this function.
NullPointerException - if one of the or both arguments are null and the computation does not allow null values.

getPermuted

public final BinaryFunction 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
Following copied from interface: net.sf.molae.pipe.binop.BinaryFunction
Returns:
the permuted function of this function

setPermuted

public final void setPermuted(BinaryFunction 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 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
Following copied from interface: net.sf.molae.pipe.binop.BinaryFunction
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 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
Following copied from interface: net.sf.molae.pipe.binop.BinaryFunction
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
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
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