public class LSPMap extends java.lang.Object implements java.lang.Iterable<LSPMap.Entry>, java.lang.AutoCloseable
addValue(LSPValue)
automatically assigns an integer key to the
element equal to the largest integer key already present plus one, or zero if
no integer key exists.
Most of the functions below exist in multiple versions: Values and
keys can be manipulated through their native type (like int, double, String,
LSPMap
, LSPFunction
...) or manipulated with an LSPValue
which is a container that can hold any type of value. Using
the native type is more convenient and results in less overhead most of the time.
LSPValue
should only be used when you don't know the type of the
manipulated value.
The iterators returned by the method iterator()
follow the fail-fast
convention: if the map is structurally modified after the creation of an iterator
(by using the methods add, set, unset or clear), the iterator will throw an exception.
In other words, you can't modify a map while you are iterating over it.Modifier and Type | Class and Description |
---|---|
static class |
LSPMap.Entry
An
LSPMap entry (key, value) pair. |
Modifier and Type | Method and Description |
---|---|
void |
addBool(boolean value)
Adds the given boolean value to the map with a key corresponding to
the largest integer key present in the map plus one, or zero if no
integer key exists.
|
void |
addDouble(double value)
Adds the given double value to the map with a key corresponding to
the largest integer key present in the map plus one, or zero if no
integer key exists.
|
void |
addExpression(LSExpression expr)
Adds the given
LSExpression to the map with a key corresponding
to the largest integer key present in the map plus one, or zero if no
integer key exists. |
void |
addFunction(LSPFunction function)
Adds the given
LSPFunction to the map with a key corresponding
to the largest integer key present in the map plus one, or zero if no
integer key exists. |
void |
addInt(long value)
Adds the given integer value to the map with a key corresponding to
the largest integer key present in the map plus one, or zero if no
integer key exists.
|
void |
addMap(LSPMap map)
Adds the given
LSPMap to the map with a key corresponding to
the largest integer key present in the map plus one, or zero if no
integer key exists. |
void |
addModule(LSPModule module)
Adds the given
LSPModule to the map with a key corresponding to
the largest integer key present in the map plus one, or zero if no
integer key exists. |
void |
addString(java.lang.String str)
Adds the given String value to the map with a key corresponding to
the largest integer key present in the map plus one, or zero if no
integer key exists.
|
void |
addValue(LSPValue value)
Adds the given value to the map with a key corresponding to the
largest integer key present in the map plus one, or zero if no
integer key exists.
|
LSPValue |
asValue()
Returns the map as an
LSPValue . |
void |
clear()
Erases all elements from the map.
|
void |
close()
Releases the reference.
|
long |
count()
Returns the number of elements in the map.
|
boolean |
equals(java.lang.Object obj) |
boolean |
getBool(long key)
Returns the boolean value associated with the given key.
|
boolean |
getBool(LSPValue key)
Returns the boolean value associated with the given key.
|
boolean |
getBool(java.lang.String key)
Returns the boolean value associated with the given key.
|
double |
getDouble(long key)
Returns the double value associated with the given key.
|
double |
getDouble(LSPValue key)
Returns the double value associated with the given key.
|
double |
getDouble(java.lang.String key)
Returns the double value associated with the given key.
|
LSExpression |
getExpression(long key)
Returns the
LSExpression associated with the given key. |
LSExpression |
getExpression(LSPValue key)
Returns the
LSExpression associated with the given key. |
LSExpression |
getExpression(java.lang.String key)
Returns the
LSExpression associated with the given key. |
LSPFunction |
getFunction(long key)
Returns the
LSPFunction associated with the given key. |
LSPFunction |
getFunction(LSPValue key)
Returns the
LSPFunction associated with the given key. |
LSPFunction |
getFunction(java.lang.String key)
Returns the
LSPFunction associated with the given key. |
long |
getInt(long key)
Returns the integer value associated with the given key.
|
long |
getInt(LSPValue key)
Returns the integer value associated with the given key.
|
long |
getInt(java.lang.String key)
Returns the integer value associated with the given key.
|
LSPMap |
getMap(long key)
Returns the
LSPMap associated with the given key. |
LSPMap |
getMap(LSPValue key)
Returns the
LSPMap associated with the given key. |
LSPMap |
getMap(java.lang.String key)
Returns the
LSPMap associated with the given key. |
LSPModule |
getModule(long key)
Returns the
LSPModule associated with the given key. |
LSPModule |
getModule(LSPValue key)
Returns the
LSPModule associated with the given key. |
LSPModule |
getModule(java.lang.String key)
Returns the
LSPModule associated with the given key. |
java.lang.String |
getString(long key)
Returns the String value associated with the given key.
|
java.lang.String |
getString(LSPValue key)
Returns the String value associated with the given key.
|
java.lang.String |
getString(java.lang.String key)
Returns the String value associated with the given key.
|
LSPValue |
getValue(long key)
Returns the value associated with the given key as an
LSPValue . |
LSPValue |
getValue(LSPValue key)
Returns the value associated with the given key as an
LSPValue . |
LSPValue |
getValue(java.lang.String key)
Returns the value associated with the given key as an
LSPValue . |
int |
hashCode() |
boolean |
isDefined(int key)
Returns true if the given key is defined in the map.
|
boolean |
isDefined(LSPValue key)
Returns true if the given key is defined in the map.
|
boolean |
isDefined(java.lang.String key)
Returns true if the given key is defined in the map.
|
java.util.Iterator<LSPMap.Entry> |
iterator()
Returns a read-only iterator over the contents of this map.
|
void |
setBool(long key,
boolean value)
Associates the boolean value to the given key in the map.
|
void |
setBool(LSPValue key,
boolean value)
Associates the boolean value to the given key in the map.
|
void |
setBool(java.lang.String key,
boolean value)
Associates the boolean value to the given key in the map.
|
void |
setDouble(long key,
double value)
Associates the double value to the given key in the map.
|
void |
setDouble(LSPValue key,
double value)
Associates the double value to the given key in the map.
|
void |
setDouble(java.lang.String key,
double value)
Associates the double value to the given key in the map.
|
void |
setExpression(long key,
LSExpression expr)
Associates the
LSExpression to the given key in the map. |
void |
setExpression(LSPValue key,
LSExpression expr)
Associates the
LSExpression to the given key in the map. |
void |
setExpression(java.lang.String key,
LSExpression expr)
Associates the
LSExpression to the given key in the map. |
void |
setFunction(long key,
LSPFunction function)
Associates the
LSPFunction to the given key in the map. |
void |
setFunction(LSPValue key,
LSPFunction function)
Associates the
LSPFunction to the given key in the map. |
void |
setFunction(java.lang.String key,
LSPFunction function)
Associates the
LSPFunction to the given key in the map. |
void |
setInt(long key,
long value)
Associates the integer value to the given key in the map.
|
void |
setInt(LSPValue key,
long value)
Associates the integer value to the given key in the map.
|
void |
setInt(java.lang.String key,
long value)
Associates the integer value to the given key in the map.
|
void |
setMap(long key,
LSPMap map)
Associates the
LSPMap to the given key in the map. |
void |
setMap(LSPValue key,
LSPMap map)
Associates the
LSPMap to the given key in the map. |
void |
setMap(java.lang.String key,
LSPMap map)
Associates the
LSPMap to the given key in the map. |
void |
setModule(long key,
LSPModule module)
Associates the
LSPModule to the given key in the map. |
void |
setModule(LSPValue key,
LSPModule module)
Associates the
LSPModule to the given key in the map. |
void |
setModule(java.lang.String key,
LSPModule module)
Associates the
LSPModule to the given key in the map. |
void |
setString(long key,
java.lang.String str)
Associates the String value to the given key in the map.
|
void |
setString(LSPValue key,
java.lang.String str)
Associates the String value to the given key in the map.
|
void |
setString(java.lang.String key,
java.lang.String str)
Associates the String value to the given key in the map.
|
void |
setValue(long key,
LSPValue value)
Associates the
LSPValue to the given key. |
void |
setValue(LSPValue key,
LSPValue value)
Associates the
LSPValue to the given key in the map. |
void |
setValue(java.lang.String key,
LSPValue value)
Associates the
LSPValue to the given key in the map. |
void |
unset(long key)
Unsets the given key in the map if present.
|
void |
unset(LSPValue key)
Unsets the given key in the map if present.
|
void |
unset(java.lang.String key)
Unsets the given key in the map if present.
|
public void close()
Releases the reference. If this map was already released, returns immediately and does nothing. Invoking any method on this object after this operation will throw an exception.
Note: Releasing a reference does not necessarily imply that the underlying map object is destroyed. It is only destroyed if no more references point to it.
close
in interface java.lang.AutoCloseable
public long count()
public void clear()
count()
returns zero.public void addValue(LSPValue value)
value
- Value to add in the map.public void addInt(long value)
value
- Integer value to add in the map.public void addDouble(double value)
value
- Double value to add in the map.public void addBool(boolean value)
value
- Boolean value to add in the map.public void addExpression(LSExpression expr)
LSExpression
to the map with a key corresponding
to the largest integer key present in the map plus one, or zero if no
integer key exists.expr
- LSExpression to add in the map.public void addMap(LSPMap map)
LSPMap
to the map with a key corresponding to
the largest integer key present in the map plus one, or zero if no
integer key exists.map
- Map to add in the map.public void addModule(LSPModule module)
LSPModule
to the map with a key corresponding to
the largest integer key present in the map plus one, or zero if no
integer key exists.module
- Module to add in the map.public void addString(java.lang.String str)
str
- String value to add in the map.public void addFunction(LSPFunction function)
LSPFunction
to the map with a key corresponding
to the largest integer key present in the map plus one, or zero if no
integer key exists.function
- Function to add in the map.public LSPValue getValue(java.lang.String key)
LSPValue
.
If no value is associated with the key, an LSPValue representing nil
is returned.key
- String keypublic long getInt(java.lang.String key)
key
- String key.public double getDouble(java.lang.String key)
key
- String key.public boolean getBool(java.lang.String key)
key
- String key.public java.lang.String getString(java.lang.String key)
key
- String key.public LSPModule getModule(java.lang.String key)
LSPModule
associated with the given key.
The value must exist and must be a module.key
- String key.public LSPFunction getFunction(java.lang.String key)
LSPFunction
associated with the given key.
The value must exist and must be a function.key
- String key.public LSPMap getMap(java.lang.String key)
LSPMap
associated with the given key.
The value must exist and must be a map.key
- String key.public LSExpression getExpression(java.lang.String key)
LSExpression
associated with the given key.
The value must exist and must be an expression.key
- String key.public void setValue(java.lang.String key, LSPValue value)
LSPValue
to the given key in the map.
If the value is nil, this has the same effect as unset(java.lang.String)
.
If the map already contained an association for the key, the previous
value is replaced.key
- String key.value
- LSPValue to set.public void setInt(java.lang.String key, long value)
key
- String key.value
- Integer value to set.public void setDouble(java.lang.String key, double value)
key
- String key.value
- Double value to set.public void setBool(java.lang.String key, boolean value)
key
- String key.value
- Boolean value to set.public void setString(java.lang.String key, java.lang.String str)
key
- String key.str
- String value to set.public void setModule(java.lang.String key, LSPModule module)
LSPModule
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced.key
- String key.module
- Module to set.public void setFunction(java.lang.String key, LSPFunction function)
LSPFunction
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced.key
- String key.function
- Function to set.public void setMap(java.lang.String key, LSPMap map)
LSPMap
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced.key
- String key.map
- Map to set.public void setExpression(java.lang.String key, LSExpression expr)
LSExpression
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced.key
- String key.expr
- Expression to set.public LSPValue getValue(long key)
LSPValue
.
If no value is associated with the key, an LSPValue representing nil
is returned.key
- Integer keypublic long getInt(long key)
key
- Integer key.public double getDouble(long key)
key
- Integer key.public boolean getBool(long key)
key
- Integer key.public java.lang.String getString(long key)
key
- Integer key.public LSPModule getModule(long key)
LSPModule
associated with the given key.
The value must exist and must be a module.key
- Integer key.public LSPFunction getFunction(long key)
LSPFunction
associated with the given key.
The value must exist and must be a function.key
- Integer key.public LSPMap getMap(long key)
LSPMap
associated with the given key.
The value must exist and must be a map.key
- Integer key.public LSExpression getExpression(long key)
LSExpression
associated with the given key.
The value must exist and must be an expression.key
- Integer key.public void setValue(long key, LSPValue value)
LSPValue
to the given key.
If the LSPValue is nil, this has the same effect as unset(java.lang.String)
.
If the map already contained an association for the key, the previous
value is replaced.key
- Integer key.value
- LSPValue to set.public void setInt(long key, long value)
key
- Integer key.value
- Integer value to set.public void setDouble(long key, double value)
key
- Integer key.value
- Double value to set.public void setBool(long key, boolean value)
key
- Integer key.value
- Boolean value to set.public void setString(long key, java.lang.String str)
key
- Integer key.str
- String value to set.public void setModule(long key, LSPModule module)
LSPModule
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced.key
- Integer key.module
- Module to set.public void setFunction(long key, LSPFunction function)
LSPFunction
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced.key
- Integer key.function
- Function to set.public void setMap(long key, LSPMap map)
LSPMap
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced.key
- Integer key.map
- Map to set.public void setExpression(long key, LSExpression expr)
LSExpression
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced.key
- Integer key.expr
- Expression to set.public LSPValue getValue(LSPValue key)
LSPValue
.
If no value is associated with the key, an LSPValue representing nil
is returned.key
- LSPValue keypublic long getInt(LSPValue key)
key
- LSPValue key.public double getDouble(LSPValue key)
key
- LSPValue key.public boolean getBool(LSPValue key)
key
- LSPValue key.public java.lang.String getString(LSPValue key)
key
- LSPValue key.public LSPModule getModule(LSPValue key)
LSPModule
associated with the given key.
The value must exist and must be a module.key
- LSPValue key.public LSPFunction getFunction(LSPValue key)
LSPFunction
associated with the given key.
The value must exist and must be a function.key
- LSPValue key.public LSPMap getMap(LSPValue key)
LSPMap
associated with the given key.
The value must exist and must be a map.key
- LSPValue key.public LSExpression getExpression(LSPValue key)
LSExpression
associated with the given key.
The value must exist and must be an expression.key
- LSPValue key.public void setValue(LSPValue key, LSPValue value)
LSPValue
to the given key in the map.
If the LSPValue is nil, this has the same effect as unset(java.lang.String)
.
If the map already contained an association for the key, the previous
value is replaced. The key must not be nil.key
- LSPValue key.value
- LSPValue to set.public void setInt(LSPValue key, long value)
key
- LSPValue key.value
- Integer value to set.public void setDouble(LSPValue key, double value)
key
- LSPValue key.value
- Double value to set.public void setBool(LSPValue key, boolean value)
key
- LSPValue key.value
- Boolean value to set.public void setString(LSPValue key, java.lang.String str)
key
- LSPValue key.str
- String value to set.public void setModule(LSPValue key, LSPModule module)
LSPModule
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced. The key must not be nil.key
- LSPValue key.module
- Module to set.public void setFunction(LSPValue key, LSPFunction function)
LSPFunction
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced. The key must not be nil.key
- LSPValue key.function
- Function to set.public void setMap(LSPValue key, LSPMap map)
LSPMap
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced. The key must not be nil.key
- LSPValue key.map
- Map to set.public void setExpression(LSPValue key, LSExpression expr)
LSExpression
to the given key in the map.
If the map already contained an association for the key, the previous
value is replaced. The key must not be nil.key
- LSPValue key.expr
- Expression to set.public void unset(java.lang.String key)
key
- String key.public void unset(long key)
key
- Integer key.public void unset(LSPValue key)
key
- LSPValue key.public boolean isDefined(java.lang.String key)
key
- String key.public boolean isDefined(int key)
key
- Integer key.public boolean isDefined(LSPValue key)
key
- LSPValue key.public java.util.Iterator<LSPMap.Entry> iterator()
iterator
in interface java.lang.Iterable<LSPMap.Entry>
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object