Package org.cytoscape.equations
Class AbstractFunction
- java.lang.Object
-
- org.cytoscape.equations.AbstractFunction
-
- All Implemented Interfaces:
Function
public abstract class AbstractFunction extends Object implements Function
Base class for allFunctionimplementations.Module:
equations-apiTo use this in your app, include the following dependency in your POM:
<dependency> <groupId>org.cytoscape</groupId> <artifactId>equations-api</artifactId> </dependency>
Cytoscape Backwards Compatibility (Abstract Class): This class is abstract and meant to be extended by users. This means that we may add methods for minor version updates. Methods will only be removed for major version updates.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractFunction(ArgDescriptor[] argDescriptors)Base class constructor for easy creation ofFunctions from function argument descriptors.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleanargTypesAreValid(Class[] argTypes)Returns true of false if the args passed in had arity of a type mismatch.abstract ObjectevaluateFunction(Object[] args)Used to invoke this function.abstract StringgetFunctionSummary()Used to provide help for users.abstract StringgetName()Used to parse the function string.List<Class<?>>getPossibleArgTypes(Class[] leadingArgs)Used with the equation builder.abstract ClassgetReturnType()Returns the static return type of this function.StringgetUsageDescription()Used to provide help for users.ClassvalidateArgTypes(Class[] argTypes)Returns the return type of this function.
-
-
-
Constructor Detail
-
AbstractFunction
protected AbstractFunction(ArgDescriptor[] argDescriptors)
Base class constructor for easy creation ofFunctions from function argument descriptors.- Parameters:
argDescriptors- an array describing theFunctionargument list
-
-
Method Detail
-
getName
public abstract String getName()
Used to parse the function string. This name is treated in a case-insensitive manner!
-
getFunctionSummary
public abstract String getFunctionSummary()
Used to provide help for users. Unlike getUsageDescription(), this is an informal English description, like "Calculates the sine of its argument."- Specified by:
getFunctionSummaryin interfaceFunction- Returns:
- a description of what this function does
-
getUsageDescription
public final String getUsageDescription()
Used to provide help for users. Unlike getFunctionSummary(), this describes how to call this function, like "Call with SIN(number)."- Specified by:
getUsageDescriptionin interfaceFunction- Returns:
- a description of how to use this function
-
getReturnType
public abstract Class getReturnType()
Returns the static return type of this function. If the static return type is Object.class, the dynamic return type will be one of Double.cLass, String.class, or Boolean.class and will depend on the arguments passed to the function!
Note, this is used by external tools used to filter a list of functions based on what a valid return type might be. In Cytoscape it is used in the attribute browser's formula builder.- Specified by:
getReturnTypein interfaceFunction- Returns:
- the static return type of this function, Object.class, Double.cLass, String.class, or Boolean.class.
-
argTypesAreValid
protected final boolean argTypesAreValid(Class[] argTypes)
Returns true of false if the args passed in had arity of a type mismatch. Note that this is different from getReturnType() in that it will never return the wildcard Object.class. It is used by the parser which knows the actual type of the arguments in any given call to this function.- Parameters:
argTypes- the args to check for wrong arity or a type mismatch.- Returns:
- true or false if the args passed in had the wrong arity or a type mismatch
-
validateArgTypes
public Class validateArgTypes(Class[] argTypes)
Returns the return type of this function. Note that this is different from getReturnType() in that it will never return the wildcard Object.class. It is used by the parser which knows the actual type of the arguments in any given call to this function.- Specified by:
validateArgTypesin interfaceFunction- Parameters:
argTypes- the args to check for wrong arity or a type mismatch.- Returns:
- the return type for this function (Double.class, String.class, or Boolean.class) or null if the args passed in had the wrong arity or a type mismatch
-
evaluateFunction
public abstract Object evaluateFunction(Object[] args) throws FunctionError
Used to invoke this function.- Specified by:
evaluateFunctionin interfaceFunction- Parameters:
args- the function arguments which must correspond in type and number to what getParameterTypes() returns.- Returns:
- the result of the function evaluation. The actual type of the returned object will be what getReturnType() returns.
- Throws:
ArithmeticException- thrown if a numeric error, e.g. a division by zero occurred.IllegalArgumentException- thrown for any error that is not a numeric error, for example if a function only accepts positive numbers and a negative number was passed in.FunctionError
-
getPossibleArgTypes
public final List<Class<?>> getPossibleArgTypes(Class[] leadingArgs)
Used with the equation builder.- Specified by:
getPossibleArgTypesin interfaceFunction- Parameters:
leadingArgs- the types of the arguments that have already been selected by the user.- Returns:
- the set of arguments (must be a collection of String.class, Long.class, Double.class, Boolean.class and List.class) that are candidates for the next argument. A null return indicates that no further arguments are valid. Please note that if the returned set contains a null, this indicates an optional additional argument.
-
-