tyrex.util

Class HashIntTable

public final class HashIntTable extends Object

This class provides unsynchronized hash get, put, remove and increment of int values. If multiple threads are accessing the table then access to the table must be synchronized.

Author: Riad Mohammed

Constructor Summary
HashIntTable()
Create the HashIntTable using the default size
HashIntTable(int size, int defaultValue)
Create the HashIntTable with the specified size.
Method Summary
intget(Object key)
Get the value of the specified key.
intincrement(Object key, int increment)
Increment the value associated with the specified key by the specified amount.
Enumerationkeys()
Return the enumeration of keys.
static voidmain(String[] args)
intput(Object key, int value)
Associate the specified key with the specified value.
intremove(Object key)
Remove the value for specified key
intsize()
Return the size of the HashIntTable.

Constructor Detail

HashIntTable

public HashIntTable()
Create the HashIntTable using the default size

HashIntTable

public HashIntTable(int size, int defaultValue)
Create the HashIntTable with the specified size.

Parameters: size the size (must be greater than zero)

Method Detail

get

public int get(Object key)
Get the value of the specified key. If the key does not exist in the table return the default value.

Parameters: key the key. Cannot be null.

Returns: the value of the key in the table

increment

public int increment(Object key, int increment)
Increment the value associated with the specified key by the specified amount. If key does not exist in the table then increment the default value and store the result

Parameters: key the key. Cannot be null increment the increment

Returns: the incremented value

keys

public Enumeration keys()
Return the enumeration of keys.

If the size of the HashIntTable changes (via put, remove, increment) while the keys are being enuemrated a ConcurrentModificationException is thrown by the enumeration.

Returns: the enumeration of keys.

main

public static void main(String[] args)

put

public int put(Object key, int value)
Associate the specified key with the specified value.

Parameters: key the key. Cannot be null value the new value

Returns: the existing value. If the key does not exist in the table return the default value.

remove

public int remove(Object key)
Remove the value for specified key

Parameters: key the key. Cannot be null.

Returns: the old value. If the key does not exist in the table return the default value.

size

public int size()
Return the size of the HashIntTable.

Returns: the size of the HashIntTable.

Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.