fr.umlv.tatoo.runtime.util
Class StringCache

java.lang.Object
  extended by fr.umlv.tatoo.runtime.util.StringCache

public final class StringCache
extends Object

Utility class which caches strings obtained from byte buffer.

Version:
$Revision$
Author:
Gilles Roussel

Constructor Summary
StringCache(String charsetName, int size, int len, int maxSize)
          Constructor of an empty string cache.
 
Method Summary
 String add(ByteBuffer bb)
          Add a new string in the cache.
 String add(CharSequence cb)
          Add a new string in the cache.
 String addLowerCase(ByteBuffer bb)
          Add a new string in the cache.
 String addLowerCase(CharBuffer cb)
          Add a new string in the cache.
 void clear()
          Remove all strings from the cache.
static boolean equals(CharSequence cs1, CharSequence cs2)
          Compare the content of a ByteBuffer between position and limit with the content of a string.
 int getMaxStringLength()
          Maximum length of the strings in the cache.
 int getStringNumber()
          The number of strings in the cache.
static int hashcode(CharSequence s)
          Compute hashcode of a char sequence.
 void load(BufferedReader reader)
          Reads the content of the cache from the reader provided as argument.
 void remove(String s)
          Remove a string from the cache.
 void store(PrintWriter out)
          Writes all strings contained in the cache on the writer provided as argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringCache

public StringCache(String charsetName,
                   int size,
                   int len,
                   int maxSize)
Constructor of an empty string cache.

Parameters:
charsetName - the name of charset used in ByteBuffers.
size - initial size of the initial cache.
len - the maximun string length in the cache.
maxSize - the maximum size of the cache.
Method Detail

getMaxStringLength

public int getMaxStringLength()
Maximum length of the strings in the cache.

Returns:
maximum length of strings in the cache.

getStringNumber

public int getStringNumber()
The number of strings in the cache.

Returns:
the number of string in the cache.

clear

public void clear()
Remove all strings from the cache.


remove

public void remove(String s)
Remove a string from the cache.

Parameters:
s - the string to remove from the cache.

add

public String add(ByteBuffer bb)
Add a new string in the cache. The string is decoded from the byte buffer between position and limit. If the string is already in the cache the string only returned.

Parameters:
bb - contains the String to cache between position and limit.
Returns:
the string bound to the bytebuffer in the cache.

add

public String add(CharSequence cb)
Add a new string in the cache. The string is obtained from the char buffer between position and limit. If the string is already in the cache the string only returned.

Parameters:
cb - contains the String to cache between position and limit.
Returns:
the string bound to the charbuffer in the cache.

addLowerCase

public String addLowerCase(ByteBuffer bb)
Add a new string in the cache. The string is decoded from the byte buffer between position and limit putting each letter in lower case if necessary. If the string is already in the cache the string only returned.

Parameters:
bb - a ByteBuffer value
Returns:
a String value

addLowerCase

public String addLowerCase(CharBuffer cb)
Add a new string in the cache. The string is decoded from the char buffer between position and limit putting each letter in lower case if necessary. If the string is already in the cache the string only returned.

Parameters:
cb - a ByteBuffer value
Returns:
a String value

equals

public static boolean equals(CharSequence cs1,
                             CharSequence cs2)
Compare the content of a ByteBuffer between position and limit with the content of a string.

Parameters:
cs1 - the first string to compare.
cs2 - the second string to compare.
Returns:
true if the two arguments contains the same characters.

hashcode

public static int hashcode(CharSequence s)
Compute hashcode of a char sequence.

Parameters:
s - char sequence which hashcode is to compute.
Returns:
the hashcode.

store

public void store(PrintWriter out)
Writes all strings contained in the cache on the writer provided as argument. Each string is separted with a new line.

Parameters:
out - output writer where content must be written.

load

public void load(BufferedReader reader)
          throws IOException
Reads the content of the cache from the reader provided as argument. Each string is considered to be on one line.

Parameters:
reader - the reader where strings are read.
Throws:
IOException