 | | Interface Manipulation Package v4.0 (2008-06-25) |  | ©copyright |  |
imp.core
Class Structure
java.lang.Object
imp.core.Value
imp.core.Structure
- All Implemented Interfaces:
- Cloneable, Comparable<Value>
- Direct Known Subclasses:
- Expression, Location, Text
public class Structure
- extends Value
Implements the basic capabilities of a static logical-structure with fields and elements.
A logical-structure is a minimal but general specification of a generic ``semantic'' object containing
symbolic information.
Logical structure : a generic ``semantic'' object. A
logical structure is built of:
- A type. This type defining the logical structure type,
- A set of fields. I.e. parameters, properties or attributes, using a construct of the form:
{ name_1 = value_1, name_2 = value_2, .. name_size = value_size}
labeled by their name, where values are either boolean, number, string or another logical-structure.
Reserved field names.
xml:lang | Defines the language or locale of textual fields or elements |
name | The mirror of the logical-structure name: used to get/set non-standard names. |
value | The logical-structure scalar value: used to define the value when neither field nor element. |
id | The logical-structure unique identifier: used to address a logical-structure. |
.. | The logical-structure parent, if any. |
- A list of elements. I.e. a recursive construct of the form:
[element_1, element_2, .. element_length]
indexed by numerical indexes > 0.
as schematized here:
- the logical structure's length is the number of elements;
- a logical-structure is an atomic value if it has only a name, and the field of name value containing the value represented as a string, but
no other field and no element;
- a logical-structure is a list of elements if it has only elements but no field;
- a logical-structure is a set of strings if it has only fields with true value but no element;
Defining containers. Data structures or data containers are easily defined by
usage conventions of such logical structures:
- Maps. of the form {key = value, .. } i.e. objects that maps ``keys'' to ``values''. This is intrinsically what logical structures
are. Here, key are names, values are logical structures.
- Functional terms. of the form f(arg_1, arg_2, ...) where f is the function name and arg_i its arguments are defined as
logical structures with numerical attributes, i.e.:
{ 0 = f, 1 = arg_1, 2 = arg_2, .. }
- Lists. of the form [ element_1, element_2, .. ] also written null(element_1, element_2, ...) are functional terms without
name i.e.:
{ 1 = element_1, 2 = element_2, .. }
This includes arrays or ``vectors''. Here elements are logical structures.
- Sets. of the form { string_1, string_2, .. } are defined as logical structures which attributes have a unique true
value, i.e.:
{ string_1 = true, string_2 = true, ..}
Here the set elements are names or by extension strings.
Other
data containers (e.g. stacks, sequences, insertion/deletion lists, last-in/first-out list, graphs, trees, etc..) are easily derived from these
conventions.
Fields inherited from class imp.core.Value |
NULL |
Constructor Summary |
Structure(String type)
Constructs an expression of the given type. |
Method Summary |
Structure |
clear()
Clears type, fields and elements of this logical-structure and return this. |
int |
indexOf(Value element)
Searches for the first occurrence of the given element, testing for equality. |
Structure |
setType(String type)
Sets the structure type and return this. |
Structure |
sort(Comparator<Value> comparator,
Merger<Value> merger)
Sorts the elements of this list into ascending order of its elements and return this. |
Methods inherited from class imp.core.Value |
cloneThis, create, get, getWrapping, isCyclic, isName, load, main, save, toString, wrappedObject |
Structure
public Structure(String type)
- Constructs an expression of the given type.
This a simple short-hand for new Expression(type).
- Parameters:
type
- [optional, default is imp:expression] Expression type
clear
public final Structure clear()
- Clears type, fields and elements of this logical-structure and return this.
indexOf
public final int indexOf(Value element)
- Searches for the first occurrence of the given element, testing for equality.
- Parameters:
element
- The searched element.
- Returns:
- The index of the first occurrence of the element is any, or -1 if not found.
setType
public final Structure setType(String type)
- Sets the structure type and return this.
sort
public final Structure sort(Comparator<Value> comparator,
Merger<Value> merger)
- Sorts the elements of this list into ascending order of its elements and return this.
The sorting algorithm is a modified merge-sort, with a n * log(n) performance.
- Parameters:
comparator
- [optional, default is null] Defines how two elements are compared. If null, sorts according to the natural ordering.merger
- [optional, default is null] Defines how two equal elements are merged. If null, equal elements are not merged and not reordered.