public abstract class GoloStruct extends java.lang.Object implements java.lang.Iterable<Tuple>, java.lang.Comparable<GoloStruct>
This class defines common behavior. Golo structure classes are final subclasses of this one.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
members
The array of member names, initialized in Golo structure classes constructors.
|
Constructor and Description |
---|
GoloStruct()
Constructor that does nothing beyond calling
super() . |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(GoloStruct other)
Compares this structure with the specified structure for order.
|
abstract GoloStruct |
copy()
Makes a shallow copy.
|
Tuple |
destruct()
Destructuration helper.
|
abstract GoloStruct |
frozenCopy()
Makes a shallow frozen copy where any member value modification attempt will fail with an
IllegalStateException . |
abstract java.lang.Object |
get(java.lang.String member)
Gets a member value by name.
|
abstract boolean |
isFrozen()
Tells whether the instance is frozen or not.
|
java.util.Iterator<Tuple> |
iterator()
Provides an iterator over the structure.
|
Tuple |
members()
Gets the member names as a tuple of strings.
|
abstract GoloStruct |
set(java.lang.String member,
java.lang.Object value)
Sets a member value by name.
|
abstract java.lang.Object[] |
toArray()
Array conversion.
|
Tuple |
values()
Gets the current values, in order of member declaration.
|
protected java.lang.String[] members
public GoloStruct()
super()
.public abstract boolean isFrozen()
true
if frozen, false
otherwise.public Tuple members()
public Tuple values()
public abstract java.lang.Object[] toArray()
public int compareTo(GoloStruct other)
Returns a negative integer, zero, or a positive integer as this structure is less than, equal to, or greater than the specified structure.
Two structures are compared by comparing their values()
, thus the
limitations of Tuple.compareTo(gololang.Tuple)
also apply.
Moreover, two structures are only comparable if they have the same type. For instance, given
struct StructA = {x, y}
struct StructB = {a, b}
let aStructA = StructA(1, 2)
let aStructB = StructB(1, 3)
while aStructA: values() < aStructB: values()
is valid and true since we compare two
2-tuples, comparing directly the structures aStructA < aStructB
throws a
ClassCastException
.compareTo
in interface java.lang.Comparable<GoloStruct>
other
- the structure to be comparedjava.lang.NullPointerException
- if the specified structure is nulljava.lang.IllegalArgumentException
- if the structure are of different type, of if the type of the members prevent them from being compared pairwisepublic abstract java.lang.Object get(java.lang.String member)
member
- the member name.java.lang.IllegalArgumentException
- if there is no such member member
.public abstract GoloStruct set(java.lang.String member, java.lang.Object value)
member
- the member name.value
- the value.java.lang.IllegalArgumentException
- if there is no such member member
.public abstract GoloStruct copy()
public abstract GoloStruct frozenCopy()
IllegalStateException
.