Package localsolver.modeler
Class LSPMap
- java.lang.Object
-
- localsolver.modeler.LSPMap
-
- All Implemented Interfaces:
java.lang.AutoCloseable,java.lang.Iterable<LSPMap.Entry>
public class LSPMap extends java.lang.Object implements java.lang.Iterable<LSPMap.Entry>, java.lang.AutoCloseable
An LSPMap 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 LSPMap withaddValue(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 anLSPValuewhich 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.LSPValueshould only be used when you don't know the type of the manipulated value. The iterators returned by the methoditerator()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 Modifier and Type Class Description static classLSPMap.EntryAnLSPMapentry (key, value) pair.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBool(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.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(LSExpression expr)Adds the givenLSExpressionto 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(LSPFunction function)Adds the givenLSPFunctionto 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.voidaddMap(LSPMap map)Adds the givenLSPMapto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.voidaddModule(LSPModule module)Adds the givenLSPModuleto the map with a key corresponding to the largest integer key present in the map plus one, or zero if no integer key exists.voidaddString(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.voidaddValue(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.LSPValueasValue()Returns the map as anLSPValue.voidclear()Erases all elements from the map.voidclose()Releases the reference.longcount()Returns the number of elements in the map.booleanequals(java.lang.Object obj)booleangetBool(long key)Returns the boolean value associated with the given key.booleangetBool(java.lang.String key)Returns the boolean value associated with the given key.booleangetBool(LSPValue key)Returns the boolean value associated with the given key.doublegetDouble(long key)Returns the double value associated with the given key.doublegetDouble(java.lang.String key)Returns the double value associated with the given key.doublegetDouble(LSPValue key)Returns the double value associated with the given key.LSExpressiongetExpression(long key)Returns theLSExpressionassociated with the given key.LSExpressiongetExpression(java.lang.String key)Returns theLSExpressionassociated with the given key.LSExpressiongetExpression(LSPValue key)Returns theLSExpressionassociated with the given key.LSPFunctiongetFunction(long key)Returns theLSPFunctionassociated with the given key.LSPFunctiongetFunction(java.lang.String key)Returns theLSPFunctionassociated with the given key.LSPFunctiongetFunction(LSPValue key)Returns theLSPFunctionassociated with the given key.longgetInt(long key)Returns the integer value associated with the given key.longgetInt(java.lang.String key)Returns the integer value associated with the given key.longgetInt(LSPValue key)Returns the integer value associated with the given key.LSPMapgetMap(long key)Returns theLSPMapassociated with the given key.LSPMapgetMap(java.lang.String key)Returns theLSPMapassociated with the given key.LSPMapgetMap(LSPValue key)Returns theLSPMapassociated with the given key.LSPModulegetModule(long key)Returns theLSPModuleassociated with the given key.LSPModulegetModule(java.lang.String key)Returns theLSPModuleassociated with the given key.LSPModulegetModule(LSPValue key)Returns theLSPModuleassociated with the given key.java.lang.StringgetString(long key)Returns the String value associated with the given key.java.lang.StringgetString(java.lang.String key)Returns the String value associated with the given key.java.lang.StringgetString(LSPValue key)Returns the String value associated with the given key.LSPValuegetValue(long key)Returns the value associated with the given key as anLSPValue.LSPValuegetValue(java.lang.String key)Returns the value associated with the given key as anLSPValue.LSPValuegetValue(LSPValue key)Returns the value associated with the given key as anLSPValue.inthashCode()booleanisDefined(int key)Returns true if the given key is defined in the map.booleanisDefined(java.lang.String key)Returns true if the given key is defined in the map.booleanisDefined(LSPValue 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.voidsetBool(long key, boolean value)Associates the boolean value to the given key in the map.voidsetBool(java.lang.String key, boolean value)Associates the boolean value to the given key in the map.voidsetBool(LSPValue key, boolean value)Associates the boolean value to the given key in the map.voidsetDouble(long key, double value)Associates the double value to the given key in the map.voidsetDouble(java.lang.String key, double value)Associates the double value to the given key in the map.voidsetDouble(LSPValue key, double value)Associates the double value to the given key in the map.voidsetExpression(long key, LSExpression expr)Associates theLSExpressionto the given key in the map.voidsetExpression(java.lang.String key, LSExpression expr)Associates theLSExpressionto the given key in the map.voidsetExpression(LSPValue key, LSExpression expr)Associates theLSExpressionto the given key in the map.voidsetFunction(long key, LSPFunction function)Associates theLSPFunctionto the given key in the map.voidsetFunction(java.lang.String key, LSPFunction function)Associates theLSPFunctionto the given key in the map.voidsetFunction(LSPValue key, LSPFunction function)Associates theLSPFunctionto the given key in the map.voidsetInt(long key, long value)Associates the integer value to the given key in the map.voidsetInt(java.lang.String key, long value)Associates the integer value to the given key in the map.voidsetInt(LSPValue key, long value)Associates the integer value to the given key in the map.voidsetMap(long key, LSPMap map)Associates theLSPMapto the given key in the map.voidsetMap(java.lang.String key, LSPMap map)Associates theLSPMapto the given key in the map.voidsetMap(LSPValue key, LSPMap map)Associates theLSPMapto the given key in the map.voidsetModule(long key, LSPModule module)Associates theLSPModuleto the given key in the map.voidsetModule(java.lang.String key, LSPModule module)Associates theLSPModuleto the given key in the map.voidsetModule(LSPValue key, LSPModule module)Associates theLSPModuleto the given key in the map.voidsetString(long key, java.lang.String str)Associates the String value to the given key in the map.voidsetString(java.lang.String key, java.lang.String str)Associates the String value to the given key in the map.voidsetString(LSPValue key, java.lang.String str)Associates the String value to the given key in the map.voidsetValue(long key, LSPValue value)Associates theLSPValueto the given key.voidsetValue(java.lang.String key, LSPValue value)Associates theLSPValueto the given key in the map.voidsetValue(LSPValue key, LSPValue value)Associates theLSPValueto the given key in the map.voidunset(long key)Unsets the given key in the map if present.voidunset(java.lang.String key)Unsets the given key in the map if present.voidunset(LSPValue key)Unsets the given key in the map if present.
-
-
-
Method Detail
-
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 interfacejava.lang.AutoCloseable- 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
public 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.- 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
public void addExpression(LSExpression expr)
Adds the givenLSExpressionto 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- LSExpression to add in the map.
-
addMap
public void addMap(LSPMap map)
Adds the givenLSPMapto 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
public void addModule(LSPModule module)
Adds the givenLSPModuleto 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.
-
addString
public 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.- Parameters:
str- String value to add in the map.
-
addFunction
public void addFunction(LSPFunction function)
Adds the givenLSPFunctionto 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
public LSPValue getValue(java.lang.String key)
Returns the value associated with the given key as anLSPValue. If no value is associated with the key, an LSPValue representing nil is returned.- Parameters:
key- String key- Returns:
- LSPValue associated with the key.
-
getInt
public long getInt(java.lang.String key)
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
public double getDouble(java.lang.String key)
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
public boolean getBool(java.lang.String key)
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
public java.lang.String getString(java.lang.String key)
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
public LSPModule getModule(java.lang.String key)
Returns theLSPModuleassociated with the given key. The value must exist and must be a module.- Parameters:
key- String key.- Returns:
- Module associated with the key.
-
getFunction
public LSPFunction getFunction(java.lang.String key)
Returns theLSPFunctionassociated with the given key. The value must exist and must be a function.- Parameters:
key- String key.- Returns:
- Function associated with the key.
-
getMap
public LSPMap getMap(java.lang.String key)
Returns theLSPMapassociated with the given key. The value must exist and must be a map.- Parameters:
key- String key.- Returns:
- Map associated with the key.
-
getExpression
public LSExpression getExpression(java.lang.String key)
Returns theLSExpressionassociated with the given key. The value must exist and must be an expression.- Parameters:
key- String key.- Returns:
- Expression associated with the key.
-
setValue
public void setValue(java.lang.String key, LSPValue value)Associates theLSPValueto 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- LSPValue to set.
-
setInt
public void setInt(java.lang.String 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- String key.value- Integer value to set.
-
setDouble
public void setDouble(java.lang.String 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- String key.value- Double value to set.
-
setBool
public void setBool(java.lang.String 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- String key.value- Boolean value to set.
-
setString
public void setString(java.lang.String key, java.lang.String str)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
public void setModule(java.lang.String key, LSPModule module)Associates theLSPModuleto 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.
-
setFunction
public void setFunction(java.lang.String key, LSPFunction function)Associates theLSPFunctionto 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
public void setMap(java.lang.String key, LSPMap map)Associates theLSPMapto 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
public void setExpression(java.lang.String key, LSExpression expr)Associates theLSExpressionto 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
public LSPValue getValue(long key)
Returns the value associated with the given key as anLSPValue. If no value is associated with the key, an LSPValue representing nil is returned.- Parameters:
key- Integer key- Returns:
- LSPValue 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
public java.lang.String getString(long key)
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
public LSPModule getModule(long key)
Returns theLSPModuleassociated with the given key. The value must exist and must be a module.- Parameters:
key- Integer key.- Returns:
- Module associated with the key.
-
getFunction
public LSPFunction getFunction(long key)
Returns theLSPFunctionassociated with the given key. The value must exist and must be a function.- Parameters:
key- Integer key.- Returns:
- Function associated with the key.
-
getMap
public LSPMap getMap(long key)
Returns theLSPMapassociated with the given key. The value must exist and must be a map.- Parameters:
key- Integer key.- Returns:
- Map associated with the key.
-
getExpression
public LSExpression getExpression(long key)
Returns theLSExpressionassociated with the given key. The value must exist and must be an expression.- Parameters:
key- Integer key.- Returns:
- Expression associated with the key.
-
setValue
public void setValue(long key, LSPValue value)Associates theLSPValueto the given key. If the LSPValue 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- LSPValue 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
public void setString(long key, java.lang.String str)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
public void setModule(long key, LSPModule module)Associates theLSPModuleto 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.
-
setFunction
public void setFunction(long key, LSPFunction function)Associates theLSPFunctionto 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
public void setMap(long key, LSPMap map)Associates theLSPMapto 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
public void setExpression(long key, LSExpression expr)Associates theLSExpressionto 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
public LSPValue getValue(LSPValue key)
Returns the value associated with the given key as anLSPValue. If no value is associated with the key, an LSPValue representing nil is returned.- Parameters:
key- LSPValue key- Returns:
- Value associated with the key.
-
getInt
public long getInt(LSPValue key)
Returns the integer value associated with the given key. The value must exist and must be an integer.- Parameters:
key- LSPValue key.- Returns:
- Integer value associated with the key.
-
getDouble
public double getDouble(LSPValue key)
Returns the double value associated with the given key. The value must exist and must be a double.- Parameters:
key- LSPValue key.- Returns:
- Double value associated with the key.
-
getBool
public boolean getBool(LSPValue key)
Returns the boolean value associated with the given key. The value must exist and must be a boolean.- Parameters:
key- LSPValue key.- Returns:
- Boolean value associated with the key.
-
getString
public java.lang.String getString(LSPValue key)
Returns the String value associated with the given key. The value must exist and must be a String.- Parameters:
key- LSPValue key.- Returns:
- String value associated with the key.
-
getModule
public LSPModule getModule(LSPValue key)
Returns theLSPModuleassociated with the given key. The value must exist and must be a module.- Parameters:
key- LSPValue key.- Returns:
- Module associated with the key.
-
getFunction
public LSPFunction getFunction(LSPValue key)
Returns theLSPFunctionassociated with the given key. The value must exist and must be a function.- Parameters:
key- LSPValue key.- Returns:
- Function associated with the key.
-
getMap
public LSPMap getMap(LSPValue key)
Returns theLSPMapassociated with the given key. The value must exist and must be a map.- Parameters:
key- LSPValue key.- Returns:
- Map associated with the key.
-
getExpression
public LSExpression getExpression(LSPValue key)
Returns theLSExpressionassociated with the given key. The value must exist and must be an expression.- Parameters:
key- LSPValue key.- Returns:
- Expression associated with the key.
-
setValue
public void setValue(LSPValue key, LSPValue value)
Associates theLSPValueto the given key in the map. If the LSPValue 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- LSPValue key.value- LSPValue to set.
-
setInt
public void setInt(LSPValue 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. The key must not be nil.- Parameters:
key- LSPValue key.value- Integer value to set.
-
setDouble
public void setDouble(LSPValue 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. The key must not be nil.- Parameters:
key- LSPValue key.value- Double value to set.
-
setBool
public void setBool(LSPValue 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. The key must not be nil.- Parameters:
key- LSPValue key.value- Boolean value to set.
-
setString
public void setString(LSPValue key, java.lang.String str)
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- LSPValue key.str- String value to set.
-
setModule
public void setModule(LSPValue key, LSPModule module)
Associates theLSPModuleto 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- LSPValue key.module- Module to set.
-
setFunction
public void setFunction(LSPValue key, LSPFunction function)
Associates theLSPFunctionto 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- LSPValue key.function- Function to set.
-
setMap
public void setMap(LSPValue key, LSPMap map)
Associates theLSPMapto 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- LSPValue key.map- Map to set.
-
setExpression
public void setExpression(LSPValue key, LSExpression expr)
Associates theLSExpressionto 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- LSPValue key.expr- Expression to set.
-
unset
public void unset(java.lang.String key)
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
public void unset(LSPValue key)
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- LSPValue key.
-
isDefined
public boolean isDefined(java.lang.String key)
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
public boolean isDefined(LSPValue key)
Returns true if the given key is defined in the map.- Parameters:
key- LSPValue key.
-
iterator
public java.util.Iterator<LSPMap.Entry> iterator()
Returns a read-only iterator over the contents of this map. The optional remove() operation is not supported.- Specified by:
iteratorin interfacejava.lang.Iterable<LSPMap.Entry>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-