Package com.hexaly.modeler
Class HxmMap
java.lang.Object
com.hexaly.modeler.HxmMap
- All Implemented Interfaces:
AutoCloseable,Iterable<HxmMap.Entry>
An HxmMap is a data structure mapping keys to values. A map is both an
associative table and an array. Setting a value to an existing key will
overwrite any value previously set for that key.
When used as an array-like structure, adding a new unkeyed element to an
HxmMap with
addValue(HxmValue) 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,
HxmMap, HxmFunction...) or manipulated with an HxmValue
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.
HxmValue 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.- Since:
- 10.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBool(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.voidAdds the givenHxmClassto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.voidaddDouble(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.voidaddExpression(HxExpression expr) Adds the givenHxExpressionto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.voidaddFunction(HxmFunction function) Adds the givenHxmFunctionto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.voidaddInt(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.voidAdds the givenHxmMapto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.voidAdds the givenHxmModuleto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.voidAdds 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.voidAdds 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.asValue()Returns the map as anHxmValue.voidclear()Erases all elements from the map.voidclose()Releases the reference.longcount()Returns the number of elements in the map.booleanbooleangetBool(long key) Returns the boolean value associated with the given key.booleanReturns the boolean value associated with the given key.booleanReturns the boolean value associated with the given key.getClass(long key) Returns theHxmClassassociated with the given key.Returns theHxmClassassociated with the given key.Returns theHxmClassassociated with the given key.doublegetDouble(long key) Returns the double value associated with the given key.doubleReturns the double value associated with the given key.doubleReturns the double value associated with the given key.getExpression(long key) Returns theHxExpressionassociated with the given key.getExpression(HxmValue key) Returns theHxExpressionassociated with the given key.getExpression(String key) Returns theHxExpressionassociated with the given key.getFunction(long key) Returns theHxmFunctionassociated with the given key.getFunction(HxmValue key) Returns theHxmFunctionassociated with the given key.getFunction(String key) Returns theHxmFunctionassociated with the given key.longgetInt(long key) Returns the integer value associated with the given key.longReturns the integer value associated with the given key.longReturns the integer value associated with the given key.getMap(long key) Returns theHxmMapassociated with the given key.Returns theHxmMapassociated with the given key.Returns theHxmMapassociated with the given key.getModule(long key) Returns theHxmModuleassociated with the given key.Returns theHxmModuleassociated with the given key.Returns theHxmModuleassociated with the given key.getString(long key) Returns the String value associated with the given key.Returns the String value associated with the given key.Returns the String value associated with the given key.getValue(long key) Returns the value associated with the given key as anHxmValue.Returns the value associated with the given key as anHxmValue.Returns the value associated with the given key as anHxmValue.inthashCode()booleanisDefined(int key) Returns true if the given key is defined in the map.booleanReturns true if the given key is defined in the map.booleanReturns true if the given key is defined in the map.iterator()Returns a read-only iterator over the contents of this map.voidsetBool(long key, boolean value) Associates the boolean value to the given key in the map.voidAssociates the boolean value to the given key in the map.voidAssociates the boolean value to the given key in the map.voidAssociates theHxmClassto the given key in the map.voidAssociates theHxmClassto the given key in the map.voidAssociates theHxmClassto the given key in the map.voidsetDouble(long key, double value) Associates the double value to the given key in the map.voidAssociates the double value to the given key in the map.voidAssociates the double value to the given key in the map.voidsetExpression(long key, HxExpression expr) Associates theHxExpressionto the given key in the map.voidsetExpression(HxmValue key, HxExpression expr) Associates theHxExpressionto the given key in the map.voidsetExpression(String key, HxExpression expr) Associates theHxExpressionto the given key in the map.voidsetFunction(long key, HxmFunction function) Associates theHxmFunctionto the given key in the map.voidsetFunction(HxmValue key, HxmFunction function) Associates theHxmFunctionto the given key in the map.voidsetFunction(String key, HxmFunction function) Associates theHxmFunctionto the given key in the map.voidsetInt(long key, long value) Associates the integer value to the given key in the map.voidAssociates the integer value to the given key in the map.voidAssociates the integer value to the given key in the map.voidAssociates theHxmMapto the given key in the map.voidAssociates theHxmMapto the given key in the map.voidAssociates theHxmMapto the given key in the map.voidAssociates theHxmModuleto the given key in the map.voidAssociates theHxmModuleto the given key in the map.voidAssociates theHxmModuleto the given key in the map.voidAssociates the String value to the given key in the map.voidAssociates the String value to the given key in the map.voidAssociates the String value to the given key in the map.voidAssociates theHxmValueto the given key.voidAssociates theHxmValueto the given key in the map.voidAssociates theHxmValueto the given key in the map.voidunset(long key) Unsets the given key in the map if present.voidUnsets the given key in the map if present.voidUnsets the given key in the map if present.Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
close
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.
- Specified by:
closein interfaceAutoCloseable- Since:
- 11.5
-
count
public long count()Returns the number of elements in the map. -
clear
public void clear()Erases all elements from the map. After this call,count()returns zero. -
addValue
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.- Parameters:
value- Value to add in the map.
-
addInt
public 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.- Parameters:
value- Integer value to add in the map.
-
addDouble
public 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.- Parameters:
value- Double value to add in the map.
-
addBool
public 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.- Parameters:
value- Boolean value to add in the map.
-
addExpression
Adds the givenHxExpressionto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.- Parameters:
expr- HxExpression to add in the map.
-
addMap
Adds the givenHxmMapto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.- Parameters:
map- Map to add in the map.
-
addModule
Adds the givenHxmModuleto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.- Parameters:
module- Module to add in the map.
-
addClass
Adds the givenHxmClassto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.- Parameters:
clazz- Class to add in the map.
-
addString
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.- Parameters:
str- String value to add in the map.
-
addFunction
Adds the givenHxmFunctionto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.- Parameters:
function- Function to add in the map.
-
getValue
Returns the value associated with the given key as anHxmValue. If no value is associated with the key, an HxmValue representing nil is returned.- Parameters:
key- String key- Returns:
- HxmValue associated with the key.
-
getInt
Returns the integer value associated with the given key. The value must exist and must be an integer.- Parameters:
key- String key.- Returns:
- Integer value associated with the key.
-
getDouble
Returns the double value associated with the given key. The value must exist and must be a double.- Parameters:
key- String key.- Returns:
- Double value associated with the key.
-
getBool
Returns the boolean value associated with the given key. The value must exist and must be a boolean.- Parameters:
key- String key.- Returns:
- Boolean value associated with the key.
-
getString
Returns the String value associated with the given key. The value must exist and must be a String.- Parameters:
key- String key.- Returns:
- String value associated with the key.
-
getModule
Returns theHxmModuleassociated with the given key. The value must exist and must be a module.- Parameters:
key- String key.- Returns:
- Module associated with the key.
-
getClass
Returns theHxmClassassociated with the given key. The value must exist and must be a class.- Parameters:
key- String key.- Returns:
- Class associated with the key.
-
getFunction
Returns theHxmFunctionassociated with the given key. The value must exist and must be a function.- Parameters:
key- String key.- Returns:
- Function associated with the key.
-
getMap
Returns theHxmMapassociated with the given key. The value must exist and must be a map.- Parameters:
key- String key.- Returns:
- Map associated with the key.
-
getExpression
Returns theHxExpressionassociated with the given key. The value must exist and must be an expression.- Parameters:
key- String key.- Returns:
- Expression associated with the key.
-
setValue
Associates theHxmValueto the given key in the map. If the value is nil, this has the same effect asunset(java.lang.String). If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.value- HxmValue to set.
-
setInt
Associates the integer value to the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.value- Integer value to set.
-
setDouble
Associates the double value to the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.value- Double value to set.
-
setBool
Associates the boolean value to the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.value- Boolean value to set.
-
setString
Associates the String value to the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.str- String value to set.
-
setModule
Associates theHxmModuleto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.module- Module to set.
-
setClass
Associates theHxmClassto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.clazz- Class to set.
-
setFunction
Associates theHxmFunctionto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.function- Function to set.
-
setMap
Associates theHxmMapto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.map- Map to set.
-
setExpression
Associates theHxExpressionto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- String key.expr- Expression to set.
-
getValue
Returns the value associated with the given key as anHxmValue. If no value is associated with the key, an HxmValue representing nil is returned.- Parameters:
key- Integer key- Returns:
- HxmValue associated with the key.
-
getInt
public long getInt(long key) Returns the integer value associated with the given key. The value must exist and must be an integer.- Parameters:
key- Integer key.- Returns:
- Integer value associated with the key.
-
getDouble
public double getDouble(long key) Returns the double value associated with the given key. The value must exist and must be a double.- Parameters:
key- Integer key.- Returns:
- Double value associated with the key.
-
getBool
public boolean getBool(long key) Returns the boolean value associated with the given key. The value must exist and must be a boolean.- Parameters:
key- Integer key.- Returns:
- Boolean value associated with the key.
-
getString
Returns the String value associated with the given key. The value must exist and must be a String.- Parameters:
key- Integer key.- Returns:
- String value associated with the key.
-
getModule
Returns theHxmModuleassociated with the given key. The value must exist and must be a module.- Parameters:
key- Integer key.- Returns:
- Module associated with the key.
-
getClass
Returns theHxmClassassociated with the given key. The value must exist and must be a clazz.- Parameters:
key- Integer key.- Returns:
- Clazz associated with the key.
-
getFunction
Returns theHxmFunctionassociated with the given key. The value must exist and must be a function.- Parameters:
key- Integer key.- Returns:
- Function associated with the key.
-
getMap
Returns theHxmMapassociated with the given key. The value must exist and must be a map.- Parameters:
key- Integer key.- Returns:
- Map associated with the key.
-
getExpression
Returns theHxExpressionassociated with the given key. The value must exist and must be an expression.- Parameters:
key- Integer key.- Returns:
- Expression associated with the key.
-
setValue
Associates theHxmValueto the given key. If the HxmValue is nil, this has the same effect asunset(java.lang.String). If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.value- HxmValue to set.
-
setInt
public void setInt(long key, long value) Associates the integer value to the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.value- Integer value to set.
-
setDouble
public void setDouble(long key, double value) Associates the double value to the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.value- Double value to set.
-
setBool
public void setBool(long key, boolean value) Associates the boolean value to the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.value- Boolean value to set.
-
setString
Associates the String value to the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.str- String value to set.
-
setModule
Associates theHxmModuleto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.module- Module to set.
-
setClass
Associates theHxmClassto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.clazz- Class to set.
-
setFunction
Associates theHxmFunctionto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.function- Function to set.
-
setMap
Associates theHxmMapto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.map- Map to set.
-
setExpression
Associates theHxExpressionto the given key in the map. If the map already contained an association for the key, the previous value is replaced.- Parameters:
key- Integer key.expr- Expression to set.
-
getValue
Returns the value associated with the given key as anHxmValue. If no value is associated with the key, an HxmValue representing nil is returned.- Parameters:
key- HxmValue key- Returns:
- Value associated with the key.
-
getInt
Returns the integer value associated with the given key. The value must exist and must be an integer.- Parameters:
key- HxmValue key.- Returns:
- Integer value associated with the key.
-
getDouble
Returns the double value associated with the given key. The value must exist and must be a double.- Parameters:
key- HxmValue key.- Returns:
- Double value associated with the key.
-
getBool
Returns the boolean value associated with the given key. The value must exist and must be a boolean.- Parameters:
key- HxmValue key.- Returns:
- Boolean value associated with the key.
-
getString
Returns the String value associated with the given key. The value must exist and must be a String.- Parameters:
key- HxmValue key.- Returns:
- String value associated with the key.
-
getModule
Returns theHxmModuleassociated with the given key. The value must exist and must be a module.- Parameters:
key- HxmValue key.- Returns:
- Module associated with the key.
-
getClass
Returns theHxmClassassociated with the given key. The value must exist and must be a class.- Parameters:
key- HxmValue key.- Returns:
- Clazz associated with the key.
-
getFunction
Returns theHxmFunctionassociated with the given key. The value must exist and must be a function.- Parameters:
key- HxmValue key.- Returns:
- Function associated with the key.
-
getMap
Returns theHxmMapassociated with the given key. The value must exist and must be a map.- Parameters:
key- HxmValue key.- Returns:
- Map associated with the key.
-
getExpression
Returns theHxExpressionassociated with the given key. The value must exist and must be an expression.- Parameters:
key- HxmValue key.- Returns:
- Expression associated with the key.
-
setValue
Associates theHxmValueto the given key in the map. If the HxmValue is nil, this has the same effect asunset(java.lang.String). If the map already contained an association for the key, the previous value is replaced. The key must not be nil.- Parameters:
key- HxmValue key.value- HxmValue to set.
-
setInt
Associates the integer value 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.- Parameters:
key- HxmValue key.value- Integer value to set.
-
setDouble
Associates the double value 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.- Parameters:
key- HxmValue key.value- Double value to set.
-
setBool
Associates the boolean value 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.- Parameters:
key- HxmValue key.value- Boolean value to set.
-
setString
Associates the String value 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.- Parameters:
key- HxmValue key.str- String value to set.
-
setModule
Associates theHxmModuleto 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.- Parameters:
key- HxmValue key.module- Module to set.
-
setClass
Associates theHxmClassto 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.- Parameters:
key- HxmValue key.clazz- Class to set.
-
setFunction
Associates theHxmFunctionto 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.- Parameters:
key- HxmValue key.function- Function to set.
-
setMap
Associates theHxmMapto 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.- Parameters:
key- HxmValue key.map- Map to set.
-
setExpression
Associates theHxExpressionto 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.- Parameters:
key- HxmValue key.expr- Expression to set.
-
unset
Unsets the given key in the map if present. If the key doesn't exist in the map do nothing.- Parameters:
key- String key.
-
unset
public void unset(long key) Unsets the given key in the map if present. If the key doesn't exist in the map do nothing.- Parameters:
key- Integer key.
-
unset
Unsets the given key in the map if present. If the key doesn't exist in the map do nothing. The key must not be nil.- Parameters:
key- HxmValue key.
-
isDefined
Returns true if the given key is defined in the map.- Parameters:
key- String key.
-
isDefined
public boolean isDefined(int key) Returns true if the given key is defined in the map.- Parameters:
key- Integer key.
-
isDefined
Returns true if the given key is defined in the map.- Parameters:
key- HxmValue key.
-
iterator
Returns a read-only iterator over the contents of this map. The optional remove() operation is not supported.- Specified by:
iteratorin interfaceIterable<HxmMap.Entry>
-
asValue
Returns the map as anHxmValue. -
hashCode
public int hashCode() -
equals
-