Cytoscape 2.8.0 API

org.cytoscape.equations
Class FunctionUtil

java.lang.Object
  extended by org.cytoscape.equations.FunctionUtil

public class FunctionUtil
extends Object

A collection of static methods that may be useful for the implementation of built-in functions.


Constructor Summary
FunctionUtil()
           
 
Method Summary
static void addScalarArgumentTypes(List<Class> argTypes)
          Adds Double.class, Long.class, String.class and Boolean.class to "argTypes".
static double calcSampleVariance(double[] x)
           
static boolean getArgAsBoolean(Object arg)
          Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "boolean".
static double getArgAsDouble(Object arg)
          Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "double".
static long getArgAsLong(Object arg)
          Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "long".
static String getArgAsString(Object arg)
          Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "double".
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[] getLongs(Object[] args)
          Attempts to convert all arguments, including Lists to a uniform array of longs.
static String getOrdinal(int i)
           
static String[] getStrings(Object[] args)
          Converts all arguments, including Lists to a uniform array of strings.
static boolean isScalarArgType(Class type)
           
static boolean isSomeKindOfList(Class listClassCandidate)
           
static double[] listToArray(List<Double> a)
          Converts a List to a regular double[]
static double numericallySafeSum(double[] a)
          Carefully adds the numbers in "a" minimising loss of precision.
static Object translateObjectType(Object input)
          Tries to map "input" to one of Double, Long, Boolean or String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FunctionUtil

public FunctionUtil()
Method Detail

getArgAsDouble

public static double getArgAsDouble(Object arg)
                             throws IllegalArgumentException
Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "double".

Returns:
the converted argument as a "double"
Throws:
IllegalArgumentException - if the argument cannot be converted to a "double"

getArgAsString

public static String getArgAsString(Object arg)
                             throws IllegalArgumentException
Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "double".

Returns:
the converted argument as a "double"
Throws:
IllegalArgumentException - if the argument cannot be converted to a "double"

getArgAsLong

public static long getArgAsLong(Object arg)
                         throws IllegalArgumentException
Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "long".

Returns:
the converted argument as a "long"
Throws:
IllegalArgumentException - if the argument cannot be converted to a "long"

getArgAsBoolean

public static boolean getArgAsBoolean(Object arg)
                               throws IllegalArgumentException
Assumes that "arg" is a "String", "Boolean", "Long" or a "Double and converts it to "boolean".

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.

Returns:
the sum of the elements of "a"

getOrdinal

public static String getOrdinal(int i)
Returns:
the String representation of the ith ordinal

calcSampleVariance

public static double calcSampleVariance(double[] x)
Returns:
the sample variance of the numbers in x[]

listToArray

public static double[] listToArray(List<Double> a)
Converts a List to a regular double[]


isScalarArgType

public static boolean isScalarArgType(Class type)
Returns:
true, if type is Double.class, Long.class, String.class or Boolean.class, else false

isSomeKindOfList

public static boolean isSomeKindOfList(Class listClassCandidate)
Returns:
true if "listClassCandidate" is an implementer of interface List, else false

addScalarArgumentTypes

public static void addScalarArgumentTypes(List<Class> argTypes)
Adds Double.class, Long.class, String.class and Boolean.class to "argTypes".


getDoubles

public static double[] getDoubles(Object[] args)
                           throws FunctionError
Attempts to convert all arguments, including Lists to a uniform array of doubles.

Throws:
IllegalArgumentException - if any scalar argument cannot be converted to a double or any list argument contains an element that cannot be converted to a number.
FunctionError

getLongs

public static long[] getLongs(Object[] args)
                       throws FunctionError
Attempts to convert all arguments, including Lists to a uniform array of longs.

Throws:
IllegalArgumentException - if any scalar argument cannot be converted to a long or any list argument contains an element that cannot be converted to a number.
FunctionError

getStrings

public static String[] getStrings(Object[] args)
Converts all arguments, including Lists to a uniform array of strings.


getBooleans

public static boolean[] getBooleans(Object[] args)
                             throws FunctionError
Attempts to convert all arguments, including Lists to a uniform array of booleans.

Throws:
IllegalArgumentException - if any scalar argument cannot be converted to a boolean or any list argument contains an element that cannot be converted to a number.
FunctionError

translateObjectType

public static Object translateObjectType(Object input)
Tries to map "input" to one of Double, Long, Boolean or String.

Returns:
null if the translation failed, the input object if no translation was necessary or a new object if a successful translation was possible

Cytoscape 2.8.0 API

Copyright 2010 Cytoscape Consortium. All rights reserved.