Imp
[using it]
Interface Manipulation Package v4.0 (2008-06-25) a-projector ©copyright Author


imp.core
Class Functions

java.lang.Object
  extended by imp.core.Functions

public class Functions
extends Object

This factory contains core functions implementation.

let(name, value, expression)considers name as a new local variable in the expression and return the expression.
Value interface
is(value, type)returns true if the value is of the given type.
get(value, name-or-index)gets the field or element of the value.
query(value, path)gets all field or element of the value in the given path.
set(value, name-or-index, property)sets the field or element of the value and return the value.
length(value)returns the value length.
eq(value1, value2)returns true or false whether the values are equal or not.


Nested Class Summary
static class Functions.Rule
          Defines a function defined by a pattern-matching rule.
 
Method Summary
static boolean is(Value value, Value type)
          Tests if a value is of a given type.
 Value map(String method, Value value)
          Maps a method on the value fields/elements.
static Value query(Value root, String path)
          Returns all fields/elements of the logical-structure in the given path.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

is

public static final boolean is(Value value,
                               Value type)
Tests if a value is of a given type.

Parameters:
value - The value to test.
type - The type to check.
Returns:
Returns true if the value is of the given type, else false. The value is not evaluated except for type true. Recognized types are
nullif the value is null
trueif the value evaluates to true
nameif the value is valid name in this context
numberif the value parses as a number
stringif the value has a string-value defined (i.e. the stringValue() method).
string(regular-expressionif the value has a string-value matching the given regular-expression
cyclicif the value is cyclic (i.e. if in its field/element tree, there is a reference to itself or to a cyclic value).
anyreturns always true (used to insert side-effect functions in boolean expressions).
or any type-name.
Throws:
IllegalArgumentException - If the type is unknown.

map

public Value map(String method,
                 Value value)
Maps a method on the value fields/elements.

Parameters:
method - The Java full-qualified name of static method of signature Value method(Value) If the method returns the Java null value it is recursively mapped onto each sub fields/elements, else the result is returned.
value - Value to be mapped.
Returns:
The evaluation result.
Throws:
IllegalArgumentException - If not a valid static method name

query

public static Value query(Value root,
                          String path)
Returns all fields/elements of the logical-structure in the given path.

Parameters:
root - The logical-structure to search in. * @param path
Returns:
A (eventually empty) list of fields/elements in the path.
Throws:
IllegalArgumentException - If the path is an illegal construct.