ariba.util.core
Class InternCharToString

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by ariba.util.core.GrowOnlyHashtable
          extended by ariba.util.core.InternCharToString
All Implemented Interfaces:
java.util.Map

public class InternCharToString
extends GrowOnlyHashtable

This class implements an instance of a GrowOnlyHashtable with the following properties: -- implements a version of intern() that does not have the small size limitations of the native intern() methods on at least hp and nt. -- unlike all current implementations of intern, it does not require any synchronization for the usual case of a get() -- exposes methods to intern a string and "intern" a char[] and retrieve a string. -- exposes a method to calculate the hashCode of a char[] as though it were a string. (there is a varient for the sun and the standard implementations of hashCode() The code dynamically determines which to use) This could be modified to allow a subrange of a char[] to be interned. Typically the static methods should be used, which will intern the strings to a single shared table. Only create a new instance of this class if for some reason you want a separate pool of strings.


Nested Class Summary
 
Nested classes/interfaces inherited from class ariba.util.core.GrowOnlyHashtable
GrowOnlyHashtable.IdentityMap<K,V>
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class ariba.util.core.GrowOnlyHashtable
ClassName
 
Constructor Summary
InternCharToString(int initialCapacity)
          Constructs an InternCharToString hashtable capable of holding at least initialCapacity elements before needing to grow.
 
Method Summary
static int hashCodeForChars(char[] val)
          Private method that calculates the hash code for the char[] val using the appropriate hash function.
static java.lang.String intern(char[] chars)
          Public method that interns the specified char[] chars.
static java.lang.String intern(java.lang.String s)
          Public method that interns the specified String s.
 java.lang.String internUnshared(char[] chars)
          Public method that interns the specified char[] chars.
 java.lang.String internUnshared(java.lang.String s)
          Public method that interns the specified String s.
static int jdk12HashCode(java.lang.String s)
           
static void main(java.lang.String[] args)
           
 
Methods inherited from class ariba.util.core.GrowOnlyHashtable
capacity, contains, containsKey, count, elementsArray, entrySet, get, isEmpty, keysArray, keysList, put, size, toString
 
Methods inherited from class java.util.AbstractMap
clear, containsValue, equals, hashCode, keySet, putAll, remove, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InternCharToString

public InternCharToString(int initialCapacity)
Constructs an InternCharToString hashtable capable of holding at least initialCapacity elements before needing to grow. It also determines which is the correct hash function to use from the two standards. Most uses of this class should just call the static intern methods, which will make use of a single, shared table of strings. Only use this constructor if you want to make a separate pool of objects for some unusual reason.

Method Detail

jdk12HashCode

public static final int jdk12HashCode(java.lang.String s)

hashCodeForChars

public static final int hashCodeForChars(char[] val)
Private method that calculates the hash code for the char[] val using the appropriate hash function. Love those standards)


intern

public static java.lang.String intern(java.lang.String s)
Public method that interns the specified String s. This will not provide objects that compare pointer equals with the native String.intern() method as that method is too slow and can not accomidate moderate numbers of interned strings.


intern

public static java.lang.String intern(char[] chars)
Public method that interns the specified char[] chars. This method is identical to the previous method which uses a String as an argument, except that it does not require the caller to construct a temporary String for lookup.


internUnshared

public java.lang.String internUnshared(java.lang.String s)
Public method that interns the specified String s. This will not provide objects that compare pointer equals with the native String.intern() method as that method is too slow and can not accomidate moderate numbers of interned strings.


internUnshared

public java.lang.String internUnshared(char[] chars)
Public method that interns the specified char[] chars. This method is identical to the previous method which uses a String as an argument, except that it does not require the caller to construct a temporary String for lookup.


main

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


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.