Package org.cytoscape.equations
Class FunctionUtil
java.lang.Object
org.cytoscape.equations.FunctionUtil
A collection of static methods that may be useful for the implementation of built-in functions.
Cytoscape Backwards Compatibility (Static Class): This class is static and therefore can't be extended by users. This means that we may add methods for minor version updates. Methods will only be removed for major version updates.
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>-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddScalarArgumentTypes(List<Class> argTypes) Adds the scalar types that equations use internally to the argument, i.e.static doublecalcSampleVariance(double[] x) Calculates the sample variance of some numbers.static booleangetArgAsBoolean(Object arg) Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "boolean".static doublegetArgAsDouble(Object arg) Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "double".static longgetArgAsLong(Object arg) Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "long".static StringgetArgAsString(Object arg) Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "String".static boolean[]getBooleans(Object[] args) Attempts to convert all arguments, including Lists to a uniform array of booleans.static double[]getDoubles(Object[] args) Attempts to convert all arguments, including Lists to a uniform array of doubles.static long[]Attempts to convert all arguments, including Lists to a uniform array of longs.static StringgetOrdinal(int i) Converts an integer to an ordinal string.static String[]getStrings(Object[] args) Converts all arguments, including Lists to a uniform array of strings.static booleanisScalarArgType(Class type) Tests whether the argument is one of the scalar types used by equations.static booleanisTypeOfList(Class listClassCandidate) Tests whether the argument is some kind ofList.static double[]listToArray(List<Double> a) Converts a Listto a regular double[] static doublenumericallySafeSum(double[] a) Carefully adds the numbers in "a" minimising loss of precision.static ObjecttranslateObjectType(Object input) Tries to map "input" to one ofDouble,Long,BooleanorString.
-
Method Details
-
getArgAsDouble
Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "double".- Parameters:
arg- the object instance that will be converted to adouble, if possible- Returns:
- the converted argument as a "double"
- Throws:
IllegalArgumentException- if the argument cannot be converted to a "double"
-
getArgAsString
Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "String".- Parameters:
arg- the object instance that will be converted to aString- Returns:
- the converted argument as a "double"
- Throws:
IllegalArgumentException- if the argument cannot be converted to a "double"
-
getArgAsLong
Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "long".- Parameters:
arg- the object instance that will be converted to along, if possible- Returns:
- the converted argument as a "long"
- Throws:
IllegalArgumentException- if the argument cannot be converted to a "long"
-
getArgAsBoolean
Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "boolean".- Parameters:
arg- the object instance that will be converted to aboolean, if possible- Returns:
- the converted argument as a "boolean"
- Throws:
IllegalArgumentException- if the argument cannot be converted to a "boolean"
-
numericallySafeSum
public static double numericallySafeSum(double[] a) Carefully adds the numbers in "a" minimising loss of precision.- Parameters:
a- the numbers that will be summed up- Returns:
- the sum of the elements of "a"
-
getOrdinal
Converts an integer to an ordinal string.- Parameters:
i- the integer that will be converted- Returns:
- the String representation of the ith ordinal
-
calcSampleVariance
public static double calcSampleVariance(double[] x) Calculates the sample variance of some numbers.- Parameters:
x- the numbers whose sample variance will be calculated- Returns:
- the sample variance of the numbers in x[]
-
listToArray
Converts a Listto a regular double[] - Parameters:
a- the list that will be converted- Returns:
- the converted array
-
isScalarArgType
Tests whether the argument is one of the scalar types used by equations.- Parameters:
type- the type that will be tested- Returns:
- true, if type is Double.class, Long.class, String.class or Boolean.class, else false
-
isTypeOfList
Tests whether the argument is some kind ofList.- Parameters:
listClassCandidate- the type that will be tested- Returns:
- true if "listClassCandidate" is an implementer of interface List, else false
-
addScalarArgumentTypes
Adds the scalar types that equations use internally to the argument, i.e. addsDouble.class,Long.class,String.classandBoolean.classto "argTypes".- Parameters:
argTypes- the list that will be augmented
-
getDoubles
Attempts to convert all arguments, including Lists to a uniform array of doubles.- Parameters:
args- the objects that will be converted to doubles, if possible- Returns:
- the converted array
- Throws:
FunctionErrorIllegalArgumentException- if any scalar argument cannot be converted to a double or any list argument contains an element that cannot be converted to a number.
-
getLongs
Attempts to convert all arguments, including Lists to a uniform array of longs.- Parameters:
args- the objects that will be converted to longs, if possible- Returns:
- the converted array
- Throws:
FunctionErrorIllegalArgumentException- if any scalar argument cannot be converted to a long or any list argument contains an element that cannot be converted to a number.
-
getStrings
Converts all arguments, including Lists to a uniform array of strings.- Parameters:
args- the objects that will be converted to Strings- Returns:
- the converted array
-
getBooleans
Attempts to convert all arguments, including Lists to a uniform array of booleans.- Parameters:
args- the objects that will be converted to booleans, if possible- Returns:
- the converted array
- Throws:
FunctionErrorIllegalArgumentException- if any scalar argument cannot be converted to a boolean or any list argument contains an element that cannot be converted to a number.
-
translateObjectType
Tries to map "input" to one ofDouble,Long,BooleanorString.- Parameters:
input- the object that will be mapped to one of the scalar types that are internally supported by equations- Returns:
- null if the translation failed, the input object if no translation was necessary or a new object if a successful translation was possible
-