Package com.anylogic.engine.connectivity
- java.lang.Object
- com.anylogic.engine.connectivity.ConnectivityBase
- com.anylogic.engine.connectivity.DatabaseAccessor
- com.anylogic.engine.connectivity.KeyValueTable<K,
- Type Parameters:
K
- Key typeV
- Value type
- All Implemented Interfaces:
Serializable
public final class KeyValueTable<K,V> extends DatabaseAccessor
An object that maps keys to values. A map cannot contain duplicate keys; each
key can map to at most one value.
Key-Value mappings are loaded from database via
The value mapping for given key can be obtained using
This object is only available in the AnyLogic Professional
Key-Value mappings are loaded from database via
execute()
method or
on first call of any data-retrieving methodThe value mapping for given key can be obtained using
get(Object)
method call This object is only available in the AnyLogic Professional
- Author:
- AnyLogic North America, LLC https://anylogic.com
- See Also:
- Serialized Form
Constructor | Description |
---|---|
KeyValueTable |
Creates
KeyValueTable based on the table with given
tableName |
Modifier and Type | Method | Description |
---|---|---|
boolean | containsKey |
Returns
true if this KeyValueTable contains a mapping
for the specified key. |
boolean | containsValue |
Returns
true if this KeyValueTable maps one or more
keys to the specified value. |
void | execute() |
Loads (reloads) Key-Value mappings from database table
This method is automatically invoked if data is not loaded on first data-retrieving method call |
V | get |
Returns the value to which the specified key is mapped, or
null
if this KeyValueTable contains no mapping for the key. |
boolean | isEmpty() |
Returns
true if this KeyValueTable contains no
key-value mappings. |
Set<K> | keySet() |
Returns a
Set view of the keys contained in this table. |
int | size() |
Returns the number of key-value mappings in this
KeyValueTable . |
Collection<V> | values() |
Returns a
Collection view of the values contained in this
KeyValueTable . |
public KeyValueTable(String name, Database database, String tableName, String keyColumn, String valueColumn)
Creates
KeyValueTable
based on the table with given
tableName
- Parameters:
name
- object name (decoration purpose)database
- database to connect totableName
- name of table with Key-Value mappingskeyColumn
- Key column name in the tablevalueColumn
- Value column name in the table
public void execute()
Loads (reloads) Key-Value mappings from database table
This method is automatically invoked if data is not loaded on first data-retrieving method call
This method is automatically invoked if data is not loaded on first data-retrieving method call
public V get(K key)
Returns the value to which the specified key is mapped, or
null
if this KeyValueTable
contains no mapping for the key.
More formally, if this KeyValueTable
contains a mapping from a
key k
to a value v
such that
(key==null ? k==null : key.equals(k))
, then this method returns
v
; otherwise it returns null
. (There can be at most one
such mapping.)
A return value of null
does not necessarily indicate that
the KeyValueTable
contains no mapping for the key; it's also
possible that the KeyValueTable
explicitly maps the key to
null
. The containsKey
operation may be used
to distinguish these two cases.
- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
null
if thisKeyValueTable
contains no mapping for the key
public Set<K> keySet()
Returns a
Set
view of the keys contained in this table. The set
is unmodifiable.- Returns:
- a set view of the keys contained in this
KeyValueTable
public boolean containsKey(Object key)
Returns
true
if this KeyValueTable
contains a mapping
for the specified key. More formally, returns true
if and only
if this KeyValueTable
contains a mapping for a key k
such that (key==null ? k==null : key.equals(k))
. (There can
be at most one such mapping.)- Parameters:
key
- key whose presence in thisKeyValueTable
is to be tested- Returns:
true
if thisKeyValueTable
contains a mapping for the specified key
public boolean containsValue(Object value)
Returns
true
if this KeyValueTable
maps one or more
keys to the specified value. More formally, returns true
if
and only if this KeyValueTable
contains at least one mapping to a
value v
such that
(value==null ? v==null : value.equals(v))
. This operation
will require time linear in the KeyValueTable
size.- Parameters:
value
- value whose presence in thisKeyValueTable
is to be tested- Returns:
true
if thisKeyValueTable
maps one or more keys to the specified value
public boolean isEmpty()
Returns
true
if this KeyValueTable
contains no
key-value mappings.- Returns:
true
if thisKeyValueTable
contains no key-value mappings
public int size()
Returns the number of key-value mappings in this
KeyValueTable
.
If the KeyValueTable
contains more than
Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.- Returns:
- the number of key-value mappings in this
KeyValueTable
public Collection<V> values()
Returns a
Collection
view of the values contained in this
KeyValueTable
. The collection is unmodifiable.- Returns:
- a collection view of the values contained in this
KeyValueTable