Class StockPrice
java.lang.Object
com.semedy.reasoner.builtin.functional.StockPrice
- All Implemented Interfaces:
Builtin,DynamicBuiltin,FunctionalBuiltin
The Class StockPriceBuiltin implements the FunctionalBuiltin interface. It contains the Stock-Price-Builtin, which allows to fetch the last price quote of
stock. It stores the last quote in a ConcurrentHashMap and updates the quotes every 10 minutes. After the initial request the cached stock price quotes are
returned.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()frees up allocated resourcesclone the builtinbooleanEvaluate returns the stock price for the given symbol.voidcall back function.String[]get descriptions for the different argumentsintgetArity()get the arity of the builtinget a description for the builtingetName()get the name of the builtingetType()get the type of the builtinlongthe weight of the builtin.voidinitialize the builtinbooleanisEvaluable(BitSet grounds, BitSet variableInstantiations, Object[] args) is builtin evaluable with a certain instantiation of variablesbooleanis it a builtin for internal use onlyobjectGeneratingArguments(BitSet grounds, BitSet variableInstantiations, Object[] args) In which argument position are new objects createdbooleandoes the builtin read the symbol tablevoidsetProperties(Properties arg0) set the sytem propertiesvoidsetSymbolTable(SymbolTable symbols) set the symbol tablebooleandoes the builtin write into the symbol table
-
Constructor Details
-
StockPrice
public StockPrice()
-
-
Method Details
-
evaluate
public boolean evaluate(long[] input, BitSet grounds) throws SemReasonerException, InterruptedException, IOException Evaluate returns the stock price for the given symbol. If the symbol has been already cached, it returns the cached price. If the symbol is new, it requests the price and caches it. Afterwards the cached price is returned, which is updated every 10 minutes.- Specified by:
evaluatein interfaceFunctionalBuiltin- Parameters:
input- the inputgrounds- the grounds- Returns:
- true, if successful
- Throws:
ReasoningException- the reasoning exceptionInterruptedException- the interrupted exceptionIOException- Signals that an I/O exception has occurred.SemReasonerException
-
isEvaluable
public boolean isEvaluable(BitSet grounds, BitSet variableInstantiations, Object[] args) throws BuiltinException Description copied from interface:Builtinis builtin evaluable with a certain instantiation of variables- Specified by:
isEvaluablein interfaceBuiltin- Parameters:
grounds- , which arguments are groundvariableInstantiations- , which variables are instantiatedargs- , the arguments- Returns:
- was it evaluable
- Throws:
BuiltinException
-
init
Description copied from interface:Builtininitialize the builtin- Specified by:
initin interfaceBuiltin- Parameters:
args- , the builtin arguments- Throws:
InterruptedExceptionBuiltinException
-
evaluationFinished
Description copied from interface:Builtincall back function. Is called when the whole evaluation has been finished- Specified by:
evaluationFinishedin interfaceBuiltin- Throws:
BuiltinExceptionInterruptedException
-
getWeight
Description copied from interface:Builtinthe weight of the builtin. Determines when the builtin is executed in a rule -
objectGeneratingArguments
public BitSet objectGeneratingArguments(BitSet grounds, BitSet variableInstantiations, Object[] args) throws BuiltinException Description copied from interface:BuiltinIn which argument position are new objects created- Specified by:
objectGeneratingArgumentsin interfaceBuiltin- Parameters:
grounds- , ground argument positionsvariableInstantiations- , instantiated variablesargs- , arguments of the literal- Returns:
- each bit indicates the argument position where new objects are created
- Throws:
BuiltinException
-
getName
Description copied from interface:Builtinget the name of the builtin -
getArity
public int getArity()Description copied from interface:Builtinget the arity of the builtin -
getType
Description copied from interface:Builtinget the type of the builtin -
isInternal
public boolean isInternal()Description copied from interface:Builtinis it a builtin for internal use only- Specified by:
isInternalin interfaceBuiltin- Returns:
-
getDescription
Description copied from interface:Builtinget a description for the builtin- Specified by:
getDescriptionin interfaceBuiltin- Returns:
- a description of the built-in
-
getArgumentDescriptions
Description copied from interface:Builtinget descriptions for the different arguments- Specified by:
getArgumentDescriptionsin interfaceBuiltin- Returns:
- a description of the arguments of the built-in
-
readsSymbolTable
public boolean readsSymbolTable()Description copied from interface:Builtindoes the builtin read the symbol table- Specified by:
readsSymbolTablein interfaceBuiltin- Returns:
- true if it reads the symbol table
-
writesSymbolTable
public boolean writesSymbolTable()Description copied from interface:Builtindoes the builtin write into the symbol table- Specified by:
writesSymbolTablein interfaceBuiltin- Returns:
- true if it writes to the symbol table
-
cloneBuiltin
Description copied from interface:Builtinclone the builtin- Specified by:
cloneBuiltinin interfaceBuiltin- Returns:
- the cloned built-in
-
clear
public void clear()Description copied from interface:Builtinfrees up allocated resources -
setProperties
Description copied from interface:Builtinset the sytem properties- Specified by:
setPropertiesin interfaceBuiltin- Parameters:
arg0- , properties
-
setSymbolTable
Description copied from interface:Builtinset the symbol table- Specified by:
setSymbolTablein interfaceBuiltin- Parameters:
symbols- , the symbol table
-