|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectptolemy.data.expr.UtilityFunctions
This class provides additional functions for use in the Ptolemy II expression language. All of the methods in this class are static and return an instance of Token. The expression language identifies the appropriate method to use by using reflection, matching the types of the arguments.
| Red (cxh) |
| Yellow (eal) |
| Constructor Summary | |
UtilityFunctions()
|
|
| Method Summary | |
static java.lang.String |
asURL(java.lang.String fileName)
Convert the argument from a fileName to a URL that begins with "file:". |
static Token |
cast(Token token1,
Token token2)
Convert the second token to the type of the first. |
static RecordToken |
constants()
Return a record token that contains the names of all the constants and their values. |
static java.lang.String |
findFile(java.lang.String name)
Find a file or directory. |
static LongToken |
freeMemory()
Return the approximate number of bytes available for future object allocation. |
static DoubleToken |
gaussian(double mean,
double standardDeviation)
Return a Gaussian random number. |
static ArrayToken |
gaussian(double mean,
double standardDeviation,
int length)
Return an array of Gaussian random numbers. |
static DoubleMatrixToken |
gaussian(double mean,
double standardDeviation,
int rows,
int columns)
Return a matrix of Gaussian random numbers. |
static java.lang.String |
getProperty(java.lang.String propertyName)
Deprecated. Use StringUtilities.getProperty(String)
instead |
static java.lang.String |
inferType(java.lang.String string)
Infer the type of the given string as an expression in the expression language. |
static Token |
intersect(RecordToken record1,
RecordToken record2)
Find the intersection of two records. |
static ArrayToken |
iterate(FunctionToken function,
int length,
Token initial)
Iterate the specified function to produce an array of the specified length. |
static Type |
iterateReturnType(Type functionType,
Type lengthType,
Type initialType)
Return the return type of the iterate method, given the types of the argument. |
static void |
loadLibrary(java.lang.String library)
Load a library by first using the default platform dependent System.loadLibrary() method. |
static ArrayToken |
map(FunctionToken function,
ArrayToken array)
Apply the specified function to the specified array and return an array with the results. |
static Type |
mapReturnType(Type functionType,
Type arrayTokenType)
Return the return type of the map method, given the types of the argument. |
static ScalarToken |
max(ArrayToken array)
Return the maximum of the contents of the array. |
static UnsignedByteToken |
max(UnsignedByteToken x,
UnsignedByteToken y)
Return the maximum of two unsigned bytes. |
static Type |
maxReturnType(Type type)
Return the (exact) return type of the max function above. |
static ScalarToken |
min(ArrayToken array)
Return the minimum of the contents of the array. |
static UnsignedByteToken |
min(UnsignedByteToken x,
UnsignedByteToken y)
Return the minimum of two unsigned bytes. |
static Type |
minReturnType(Type type)
Return the (exact) return type of the min function above. |
static ObjectToken |
model(java.lang.String classname)
FIXME. |
static StringToken |
property(java.lang.String propertyName)
Get the specified property from the environment. |
static ArrayToken |
random(int length)
Return an array of IID random numbers with value greater than or equal to 0.0 and less than 1.0. |
static DoubleMatrixToken |
random(int rows,
int columns)
Return a matrix of IID random numbers with value greater than or equal to 0.0 and less than 1.0. |
static Type |
randomReturnType(Type type)
Return the (exact) return type of the random function above. |
static StringToken |
readFile(java.lang.String filename)
Get the string text contained in the specified file. |
static DoubleMatrixToken |
readMatrix(java.lang.String filename)
Deprecated. Use eval(readFile()) instead. |
static StringToken |
readResource(java.lang.String name)
Get the string text contained in the specified resource, which is a file that is specified relative to the Java classpath. |
static ArrayToken |
repeat(IntToken numberOfTimes,
Token element)
Create an array that contains the specified element repeated the specified number of times. |
static Type |
repeatReturnType(Type type1,
Type type2)
Return the (exact) return type of the repeat function above. |
static ArrayToken |
sort(ArrayToken array)
Return a new array that is the sorted contents of a specified array, in ascending order. |
static ArrayToken |
sortAscending(ArrayToken array)
Return a new array that is the sorted contents of a specified array, in ascending order. |
static Type |
sortAscendingReturnType(Type type)
Return the (exact) return type of the sortAscending function above. |
static ArrayToken |
sortDescending(ArrayToken array)
Return a new array that is the sorted contents of a specified array, in descending order. |
static Type |
sortDescendingReturnType(Type type)
Return the (exact) return type of the sortDescending function above. |
static Type |
sortReturnType(Type type)
Return the (exact) return type of the sort function above. |
static Token |
sum(ArrayToken array)
Return the sum of the elements in the specified array. |
static Type |
sumReturnType(Type type)
Return the (exact) return type of the sum function above. |
static LongToken |
totalMemory()
Return the approximate number of bytes used by current objects and available for future object allocation. |
static java.lang.String |
traceEvaluation(java.lang.String string)
Evaluate the given string as an expression in the expression language. |
static BooleanToken |
within(Token token1,
Token token2,
double distance)
Return true if the first argument is close in value to the second, where "close" means that it is within the distance given by the third argument. |
static DoubleMatrixToken |
zeroMatrix(int rows,
int columns)
Deprecated. Use zeroMatrixDouble instead. |
static ComplexMatrixToken |
zeroMatrixComplex(int rows,
int columns)
Return a complex zero matrix with the given number of rows and columns. |
static DoubleMatrixToken |
zeroMatrixDouble(int rows,
int columns)
Return a double zero matrix with the given number of rows and columns. |
static IntMatrixToken |
zeroMatrixInt(int rows,
int columns)
Return a int zero matrix with the given number of rows and columns. |
static LongMatrixToken |
zeroMatrixLong(int rows,
int columns)
Return a long zero matrix with the given number of rows and columns. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public UtilityFunctions()
| Method Detail |
public static java.lang.String asURL(java.lang.String fileName)
fileName - The name of the file to be converted.
public static Token cast(Token token1,
Token token2)
throws IllegalActionException
IllegalActionException - If the token cannot be converted.public static RecordToken constants()
public static java.lang.String findFile(java.lang.String name)
name - Path of a file or directory to find.
public static LongToken freeMemory()
totalMemory()
public static DoubleToken gaussian(double mean,
double standardDeviation)
mean - The mean.standardDeviation - The standard deviation.
public static ArrayToken gaussian(double mean,
double standardDeviation,
int length)
mean - The mean.standardDeviation - The standard deviation.length - The length of the array.
public static DoubleMatrixToken gaussian(double mean,
double standardDeviation,
int rows,
int columns)
mean - The mean.standardDeviation - The standard deviation.rows - The number of rows.columns - The number of columns.
public static java.lang.String getProperty(java.lang.String propertyName)
StringUtilities.getProperty(String)
instead
The following properties are handled specially
c:/foo
whereas most of the other methods that operate
on path names return C:/foo.
propertyName - The name of property.
public static java.lang.String inferType(java.lang.String string)
throws IllegalActionException
string - The string to be parsed and evaluated.
IllegalActionException
public static Token intersect(RecordToken record1,
RecordToken record2)
throws IllegalActionException
Example: intersect({a = 1, b = 2}, {a = 3, c = 4}) returns {a = 1}.
record1 - The first record to intersect. The result gets
its values from this record.record2 - The second record to intersect.
IllegalActionException
public static ArrayToken iterate(FunctionToken function,
int length,
Token initial)
throws IllegalActionException
function - A single-argument function to iterate.length - The length of the resulting array.initial - The first element of the result.
IllegalActionException - If the specified function does not
take exactly one argument, or if an error occurs applying the function.
public static Type iterateReturnType(Type functionType,
Type lengthType,
Type initialType)
throws IllegalActionException
functionType - The type of the function to iterate.lengthType - The type of the length argument.initialType - The type of the first element of the result.
IllegalActionException - If the specified function does not
take exactly one argument, or if the type signature of the function
is not compatible with the other arguments.public static void loadLibrary(java.lang.String library)
findFile(String) and if the library is found,
load it using System.load(). If the library is not found
by findFile() and the pathname contains a /
then we call System.loadLibrary() the filename after the last
/. This step is necessary to support native methods under
Webstart, which looks for libraries at the top level.
If all of the above fails, we throw the initial exception.
library - the name of the library to be loaded. The name
should not include the platform dependent suffix.
public static ArrayToken map(FunctionToken function,
ArrayToken array)
throws IllegalActionException
function - A function with at least one argument.array - The array to which to apply the function.
IllegalActionException - If the specified function does not
take at least one argument, or if an error occurs applying the
function, or if the number of arguments does not match the subarray
lengths.
public static Type mapReturnType(Type functionType,
Type arrayTokenType)
throws IllegalActionException
functionType - The type of the function to map.arrayTokenType - The type of array to apply the
specified function on.
IllegalActionException - If the specified function does not
take at least one argument, or if the type signature of the function
is not compatible with the array elements, or if the specified
function has different argument type.
public static UnsignedByteToken max(UnsignedByteToken x,
UnsignedByteToken y)
x - An unsigned byte.y - An unsigned byte.
public static ScalarToken max(ArrayToken array)
throws IllegalActionException
array - An array of scalar tokens.
IllegalActionException - If the array is empty or
it contains tokens that are not scalar or it contains complex tokens.public static Type maxReturnType(Type type)
type - The type of the argument to the corresponding function.
public static UnsignedByteToken min(UnsignedByteToken x,
UnsignedByteToken y)
x - An unsigned byte.y - An unsigned byte.
public static ScalarToken min(ArrayToken array)
throws IllegalActionException
array - An array of scalar tokens.
IllegalActionException - If the array is empty or
it contains tokens that are not scalar or it contains complex tokens.public static Type minReturnType(Type type)
type - The type of the argument to the corresponding function.
public static ObjectToken model(java.lang.String classname)
throws IllegalActionException
IllegalActionExceptionpublic static StringToken property(java.lang.String propertyName)
propertyName - The name of property.
StringUtilities.getProperty(String)public static ArrayToken random(int length)
length - The length of the array.
public static DoubleMatrixToken random(int rows,
int columns)
rows - The number of rows.columns - The number of columns.
public static Type randomReturnType(Type type)
type - The type of the argument to the corresponding function.
public static StringToken readFile(java.lang.String filename)
throws IllegalActionException
eval(readFile("filename"))
Note that readFile() does not work inside applets, use
readResource(String) instead.
filename - The name of the file to read from.
IllegalActionException - If the file cannot be opened.ASTPtFunctionApplicationNode,
readResource(String)
public static DoubleMatrixToken readMatrix(java.lang.String filename)
throws IllegalActionException
filename - The filename.
IllegalActionException - If the file cannot be opened.
public static StringToken readResource(java.lang.String name)
throws IllegalActionException
eval(readFile("filename"))
name - The name of the resource to read from.
IllegalActionException - If the resource cannot be opened.ASTPtFunctionApplicationNode,
readFile(String)
public static ArrayToken repeat(IntToken numberOfTimes,
Token element)
numberOfTimes - The number of times to repeat the element.element - The element to repeat.
public static Type repeatReturnType(Type type1,
Type type2)
type1 - The type of the first argument to the
corresponding function.type2 - The type of the second argument to the
corresponding function.
public static ArrayToken sort(ArrayToken array)
throws IllegalActionException
array - An array of scalar tokens.
IllegalActionException - If the array contains
tokens that are complex or are not scalar or string tokens.public static Type sortReturnType(Type type)
type - The type of the argument to the corresponding function.
public static ArrayToken sortAscending(ArrayToken array)
throws IllegalActionException
array - An array of scalar tokens.
IllegalActionException - If the array contains
tokens that are complex or are not scalar or string tokens.sort(ArrayToken),
sortDescending(ArrayToken)public static Type sortAscendingReturnType(Type type)
type - The type of the argument to the corresponding function.
public static ArrayToken sortDescending(ArrayToken array)
throws IllegalActionException
array - An array of scalar tokens.
IllegalActionException - If the array contains
tokens that are complex or are not scalar or string tokens.public static Type sortDescendingReturnType(Type type)
type - The type of the argument to the corresponding function.
public static final Token sum(ArrayToken array)
throws IllegalActionException
array - An array.
IllegalActionException - If the length of the
array is zero, or if the array elements do not support
addition.public static Type sumReturnType(Type type)
type - The type of the argument to the corresponding function.
public static LongToken totalMemory()
freeMemory()
public static java.lang.String traceEvaluation(java.lang.String string)
throws IllegalActionException
string - The string to be parsed and evaluated.
IllegalActionException
public static BooleanToken within(Token token1,
Token token2,
double distance)
throws IllegalActionException
token1 - The first token.token2 - The second token.distance - The distance criterion.
IllegalActionException - If the first two arguments cannot
be compared.
public static DoubleMatrixToken zeroMatrix(int rows,
int columns)
public static ComplexMatrixToken zeroMatrixComplex(int rows,
int columns)
public static DoubleMatrixToken zeroMatrixDouble(int rows,
int columns)
public static IntMatrixToken zeroMatrixInt(int rows,
int columns)
public static LongMatrixToken zeroMatrixLong(int rows,
int columns)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||