tyrex.util
Class HashIntTable

java.lang.Object
  extended bytyrex.util.HashIntTable

public final class HashIntTable
extends java.lang.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
 int get(java.lang.Object key)
          Get the value of the specified key.
 int increment(java.lang.Object key, int increment)
          Increment the value associated with the specified key by the specified amount.
 java.util.Enumeration keys()
          Return the enumeration of keys.
static void main(java.lang.String[] args)
           
 int put(java.lang.Object key, int value)
          Associate the specified key with the specified value.
 int remove(java.lang.Object key)
          Remove the value for specified key
 int size()
          Return the size of the HashIntTable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

size

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

Returns:
the size of the HashIntTable.

keys

public java.util.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.

get

public int get(java.lang.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

remove

public int remove(java.lang.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.

put

public int put(java.lang.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.

increment

public int increment(java.lang.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

main

public static void main(java.lang.String[] args)


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.