Class AbstractFunction

  • All Implemented Interfaces:
    Function

    public abstract class AbstractFunction
    extends Object
    implements Function
    Base class for all Function implementations.

    Module: equations-api

    To 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 Detail

      • AbstractFunction

        protected AbstractFunction​(ArgDescriptor[] argDescriptors)
        Base class constructor for easy creation of Functions from function argument descriptors.
        Parameters:
        argDescriptors - an array describing the Function argument list
    • Method Detail

      • getName

        public abstract String getName()
        Used to parse the function string. This name is treated in a case-insensitive manner!
        Specified by:
        getName in interface Function
        Returns:
        the name by which you must call the function when used in an attribute equation.
      • 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:
        getFunctionSummary in interface Function
        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:
        getUsageDescription in interface Function
        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:
        getReturnType in interface Function
        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:
        validateArgTypes in interface Function
        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:
        evaluateFunction in interface Function
        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:
        getPossibleArgTypes in interface Function
        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.