bluegammon
Class RmsFacade

java.lang.Object
  extended bybluegammon.RmsFacade

public class RmsFacade
extends java.lang.Object

A facade for the RMS functionality, wrapping it in a key-property manner. This facade adds an overhead to the RMS of (numberOfKeys * 2) bytes comprising the lookup table for key-value / rms-value.

Keys are given as integers, but are masked to an unsigned 16-bit integer in the lookup table. This implies that only keys with values 0 to 65535 are unique. E.g., keys 1 and 65537 are the same, keys 65535 and -1 are the same.

Author:
Peter Andersson

Method Summary
static byte[] get(int key)
          Returns data for a specified key.
static boolean getBoolean(int key)
          Returns the value of a key as a boolean.
static char[] getChars(int key)
          Returns the value of a key as a char array.
static int getInt(int key)
          Returns the value of a key as an int.
static long getLong(int key)
          Returns the value of a key as a long.
static boolean init(int maxNbrOfKeys)
          Starts up the RMS facade.
static void set(int key, byte[] data)
          Sets a key to specified data.
static void setBoolean(int key, boolean b)
          Sets the value of a key as a boolean.
static void setChars(int key, char[] txt)
          Sets the value of a key as a char array.
static void setInt(int key, int i)
          Sets the value of a key as an int.
static void setLong(int key, long l)
          Sets the value of a key as a long.
static void shutdown()
          Closes and frees resources of the RMS facade
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

shutdown

public static void shutdown()
Closes and frees resources of the RMS facade


init

public static boolean init(int maxNbrOfKeys)
Starts up the RMS facade. If the max number of keys specified as an argument is different from the one stored in RMS from a previous invokation, all values are deleted and a new database is created. The bigger the maximum number of keys are, the bigger the overhead in the rms will be - (maxNbrOfKeys * 2) bytes.

Parameters:
maxNbrOfKeys - Maximum number of keys, 1 to 65533.
Returns:
true on success, false otherwise

getChars

public static char[] getChars(int key)
Returns the value of a key as a char array.

Parameters:
key - The key.
Returns:
The char array value of the key.

setChars

public static void setChars(int key,
                            char[] txt)
Sets the value of a key as a char array.

Parameters:
key - The key.
txt - The char array.

getBoolean

public static boolean getBoolean(int key)
Returns the value of a key as a boolean.

Parameters:
key - The key.
Returns:
The boolean value of the key.

setBoolean

public static void setBoolean(int key,
                              boolean b)
Sets the value of a key as a boolean.

Parameters:
key - The key.
b - The boolean value.

getLong

public static long getLong(int key)
Returns the value of a key as a long. If the data does not match a long, 0 is returned.

Parameters:
key - The key.
Returns:
The long value of the key.

setLong

public static void setLong(int key,
                           long l)
Sets the value of a key as a long.

Parameters:
key - The key.
l - The long value.

getInt

public static int getInt(int key)
Returns the value of a key as an int. If the data does not match an integer, 0 is returned.

Parameters:
key - The key.
Returns:
The int value of the key.

setInt

public static void setInt(int key,
                          int i)
Sets the value of a key as an int.

Parameters:
key - The key.
i - The int value.

get

public static byte[] get(int key)
Returns data for a specified key. If key has not been set before, null is returned.

Parameters:
key - The key.
Returns:
The data or null if no data is set.

set

public static void set(int key,
                       byte[] data)
Sets a key to specified data.

Parameters:
key - The key.
data - The data.