AnyLogic
Expand
Font size
Type Parameters:
K - Key type
V - 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 execute() method or on first call of any data-retrieving method
The 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 Summary

ConstructorDescription
KeyValueTable(String name, Database database, String tableName, String keyColumn, String valueColumn)
Creates KeyValueTable based on the table with given tableName

Method Summary

Modifier and TypeMethodDescription
booleancontainsKey(Object key)
Returns true if this KeyValueTable contains a mapping for the specified key.
booleancontainsValue(Object value)
Returns true if this KeyValueTable maps one or more keys to the specified value.
voidexecute()
Loads (reloads) Key-Value mappings from database table
This method is automatically invoked if data is not loaded on first data-retrieving method call
Vget(K key)
Returns the value to which the specified key is mapped, or null if this KeyValueTable contains no mapping for the key.
booleanisEmpty()
Returns true if this KeyValueTable contains no key-value mappings.
Set<K>keySet()
Returns a Set view of the keys contained in this table.
intsize()
Returns the number of key-value mappings in this KeyValueTable.
Collection<V>values()
Returns a Collection view of the values contained in this KeyValueTable.

Methods inherited from class com.anylogic.engine.connectivity.ConnectivityBase

destroy, getName, toString

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Details

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 to
tableName - name of table with Key-Value mappings
keyColumn - Key column name in the table
valueColumn - Value column name in the table

Method Details

execute

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

get

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 this KeyValueTable contains no mapping for the key

keySet

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

containsKey

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 this KeyValueTable is to be tested
Returns:
true if this KeyValueTable contains a mapping for the specified key

containsValue

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 this KeyValueTable is to be tested
Returns:
true if this KeyValueTable maps one or more keys to the specified value

isEmpty

public boolean isEmpty()
Returns true if this KeyValueTable contains no key-value mappings.
Returns:
true if this KeyValueTable contains no key-value mappings

size

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

values

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