Scripting API

Home Scripting API Index Class Overview

nlvm.util

Class HashMap


public class HashMap
extends Object

An associative container. It stores key and value entries. Values can be looked up by keys. The lookup time is approximately linear.

The hashCode() method of the key is used to decide where to store the entry. Identical keys are only stored once. One key can only have one value associated. The map allows to store the null key and null values. Two keys are decided to be identical if their hashCode() method return the same result and their equals() method compare to true. Keys must not change while they are stored in the map, so that their hashCode() and equals() methods will return reproduceable results when the map gets rehashed. Implementation details: The map might get rehashed internally, when the number of stored entries reaches a specific limit. An internal load factor (=0.75) is used to decide when that limit is reached. When the number of entries exceeds the load factor multiplied by the capacity, the capacity will be increased and the entire map will get rehashed.

Since:
    2.6.5.7

Constructor Summary

HashMap()
    Constructs an empty map using a default capacity = 16
HashMap(int nCapacity)
    Constructs an empty map using a specific capacity


Method Summary

void clear()
  Removes all key/value pairs
bool containsKey(Object key)
  Checks if there is an identical key in the map.
Object get(Object key)
  Returns a value for a key.
bool isEmpty()
  Returns true if the size of the map is 0
void put(Object key, Object value)
  Stores a key/value pair
void remove(Object key)
  Removes a key/value pair for an identical key.
int size()
  Returns the number of key/value pairs


Constructor Detail


HashMap

public HashMap()

Constructs an empty map using a default capacity = 16


HashMap

public HashMap(int nCapacity)

Constructs an empty map using a specific capacity


Method Detail


clear

public void clear()

Removes all key/value pairs


containsKey

public bool containsKey(Object key)

Checks if there is an identical key in the map.


get

public Object get(Object key)

Returns a value for a key.

Returns null if there is no identical key existing in the map. Since the map allows to store null values, this method might also return null if the stored value was null.


isEmpty

public bool isEmpty()

Returns true if the size of the map is 0


put

public void put(Object key, Object value)

Stores a key/value pair

Replaces any existing value if there was an identical key already existing in the map.


remove

public void remove(Object key)

Removes a key/value pair for an identical key.

Will do nothing if there was no identical key existing in the map.


size

public int size()

Returns the number of key/value pairs