Package org.projog.core.math
Class ArithmeticOperators
- java.lang.Object
-
- org.projog.core.math.ArithmeticOperators
-
public final class ArithmeticOperators extends java.lang.ObjectMaintains a collection ofArithmeticOperatorinstances.This class provides a mechanism for "plugging in" or "injecting" implementations of
ArithmeticOperatorat runtime. This mechanism provides an easy way to configure and extend the arithmetic operations supported by Projog.Each
KnowledgeBasehas a single uniqueArithmeticOperatorsinstance.
-
-
Field Summary
Fields Modifier and Type Field Description private KnowledgeBasekbprivate java.lang.Objectlockprivate java.util.Map<PredicateKey,java.lang.String>operatorClassNamesprivate java.util.Map<PredicateKey,ArithmeticOperator>operatorInstances
-
Constructor Summary
Constructors Constructor Description ArithmeticOperators(KnowledgeBase kb)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddArithmeticOperator(PredicateKey key, java.lang.String operatorClassName)Associates aArithmeticOperatorwith thisKnowledgeBase.voidaddArithmeticOperator(PredicateKey key, ArithmeticOperator operator)Associates aArithmeticOperatorwith thisKnowledgeBase.private Numericcalculate(Term term, Term[] args)ArithmeticOperatorgetArithmeticOperator(PredicateKey key)NumericgetNumeric(Term t)Returns the result of evaluating the specified arithmetic expression.private ArithmeticOperatorgetPreprocessedArithmeticOperator(PredicateKey key, Term argument)ArithmeticOperatorgetPreprocessedArithmeticOperator(Term argument)private ArithmeticOperatorinstantiateArithmeticOperator(java.lang.String className)private ArithmeticOperatorinstantiateArithmeticOperator(PredicateKey key)
-
-
-
Field Detail
-
kb
private final KnowledgeBase kb
-
lock
private final java.lang.Object lock
-
operatorClassNames
private final java.util.Map<PredicateKey,java.lang.String> operatorClassNames
-
operatorInstances
private final java.util.Map<PredicateKey,ArithmeticOperator> operatorInstances
-
-
Constructor Detail
-
ArithmeticOperators
public ArithmeticOperators(KnowledgeBase kb)
-
-
Method Detail
-
addArithmeticOperator
public void addArithmeticOperator(PredicateKey key, ArithmeticOperator operator)
Associates aArithmeticOperatorwith thisKnowledgeBase.- Parameters:
key- The name and arity to associate theArithmeticOperatorwith.operator- The instance ofArithmeticOperatorto be associated withkey.- Throws:
ProjogException- if there is already aArithmeticOperatorassociated with thePredicateKey
-
addArithmeticOperator
public void addArithmeticOperator(PredicateKey key, java.lang.String operatorClassName)
Associates aArithmeticOperatorwith thisKnowledgeBase.- Parameters:
key- The name and arity to associate theArithmeticOperatorwith.operatorClassName- The class name of theArithmeticOperatorto be associated withkey.- Throws:
ProjogException- if there is already aArithmeticOperatorassociated with thePredicateKey
-
getNumeric
public Numeric getNumeric(Term t)
Returns the result of evaluating the specified arithmetic expression.- Parameters:
t- aTermthat can be evaluated as an arithmetic expression (e.g. aStructureof the form+(1,2)or aNumeric)- Returns:
- the result of evaluating the specified arithmetic expression
- Throws:
ProjogException- if the specified term does not represent an arithmetic expression
-
getPreprocessedArithmeticOperator
public ArithmeticOperator getPreprocessedArithmeticOperator(Term argument)
- Returns:
- null if not found
-
getPreprocessedArithmeticOperator
private ArithmeticOperator getPreprocessedArithmeticOperator(PredicateKey key, Term argument)
-
getArithmeticOperator
public ArithmeticOperator getArithmeticOperator(PredicateKey key)
- Throws:
ProjogException- if not found
-
instantiateArithmeticOperator
private ArithmeticOperator instantiateArithmeticOperator(PredicateKey key)
-
instantiateArithmeticOperator
private ArithmeticOperator instantiateArithmeticOperator(java.lang.String className)
-
-