Package org.projog.core.math
Class AbstractArithmeticOperator
- java.lang.Object
-
- org.projog.core.math.AbstractArithmeticOperator
-
- All Implemented Interfaces:
KnowledgeBaseConsumer,ArithmeticOperator,PreprocessableArithmeticOperator
- Direct Known Subclasses:
AbstractBinaryArithmeticOperator,AbstractBinaryIntegerArithmeticOperator,AbstractUnaryArithmeticOperator,Divide,Max,Min,Random,Round
public abstract class AbstractArithmeticOperator extends java.lang.Object implements PreprocessableArithmeticOperator, KnowledgeBaseConsumer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAbstractArithmeticOperator.PreprocessedBinaryOperatorprivate classAbstractArithmeticOperator.PreprocessedUnaryOperator
-
Field Summary
Fields Modifier and Type Field Description private ArithmeticOperatorsoperators
-
Constructor Summary
Constructors Constructor Description AbstractArithmeticOperator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Numericcalculate(Numeric n)protected Numericcalculate(Numeric n1, Numeric n2)Numericcalculate(Term[] args)Returns the result of the calculation using the specified arguments.private java.lang.IllegalArgumentExceptioncreateWrongNumberOfArgumentsException(int numberOfArguments)protected booleanisPure()Indicates if this operator is pure and so can be preprocessed.ArithmeticOperatorpreprocess(Term expression)private ArithmeticOperatorpreprocessBinaryOperator(Term argument1, Term argument2)private ArithmeticOperatorpreprocessUnaryOperator(Term argument)voidsetKnowledgeBase(KnowledgeBase kb)Provides a reference to aKnowledgeBase.
-
-
-
Field Detail
-
operators
private ArithmeticOperators operators
-
-
Method Detail
-
setKnowledgeBase
public final void setKnowledgeBase(KnowledgeBase kb)
Provides a reference to aKnowledgeBase.Meaning this object will always have access to a
KnowledgeBaseby the time itscalculatemethod is invoked.- Specified by:
setKnowledgeBasein interfaceKnowledgeBaseConsumer
-
calculate
public final Numeric calculate(Term[] args)
Description copied from interface:ArithmeticOperatorReturns the result of the calculation using the specified arguments.- Specified by:
calculatein interfaceArithmeticOperator- Parameters:
args- the arguments to use in the calculation- Returns:
- the result of the calculation using the specified arguments
-
createWrongNumberOfArgumentsException
private java.lang.IllegalArgumentException createWrongNumberOfArgumentsException(int numberOfArguments)
-
preprocess
public final ArithmeticOperator preprocess(Term expression)
- Specified by:
preprocessin interfacePreprocessableArithmeticOperator
-
isPure
protected boolean isPure()
Indicates if this operator is pure and so can be preprocessed.An operator is pure if multiple calls with identical arguments always produce the same result.
- Returns:
- true if pure and so can be preprocessed, else false
-
preprocessUnaryOperator
private ArithmeticOperator preprocessUnaryOperator(Term argument)
-
preprocessBinaryOperator
private ArithmeticOperator preprocessBinaryOperator(Term argument1, Term argument2)
-
-