de.topicmapslab.majortom.util
Class HashUtil

java.lang.Object
  extended by de.topicmapslab.majortom.util.HashUtil

public class HashUtil
extends java.lang.Object

Utility class to support other hash implementations, like gnu.trove

Author:
Sven Krosse

Field Summary
private static int CAPACITY
           
private static float LOAD_FACTORY
           
private static java.lang.Class<?> mapClass
          the found class used as Map implementation
private static java.lang.Class<?> setClass
          the found class used as Set implementation
 
Constructor Summary
private HashUtil()
          hidden constructor
 
Method Summary
static
<K,V> java.util.Map<K,V>
getHashMap()
          Method try to initialize a gnu.trove.THashMap if the library is located in the class path
static
<K,V> java.util.Map<K,V>
getHashMap(int capacity)
          Method try to initialize a gnu.trove.THashMap if the library is located in the class path
static
<K,V> java.util.Map<K,V>
getHashMap(java.util.Map<? extends K,? extends V> initial)
          Method try to initialize a gnu.trove.THashMap if the library is located in the class path
static
<T> java.util.Set<T>
getHashSet()
          Method try to initialize a gnu.trove.THashSet if the library is located in the class path
static
<T> java.util.Set<T>
getHashSet(java.util.Collection<? extends T> initial)
          Method try to initialize a gnu.trove.THashSet if the library is located in the class path
static
<T> java.util.Set<T>
getHashSet(int capacity)
          Method try to initialize a gnu.trove.THashSet if the library is located in the class path
static
<T> java.util.List<T>
getList()
          Method try to initialize a List.
static
<T> java.util.List<T>
getList(java.util.Collection<? extends T> initial)
          Method try to initialize a List.
private static java.lang.Class<?> getMapClass()
          Returns the map class to use.
private static java.lang.Class<?> getSetClass()
          Returns the set class to use.
static
<K,V> java.util.Map<K,V>
getWeakHashMap()
          Method try to initialize a WeakHashMap.
static
<K,V> java.util.Map<K,V>
getWeakHashMap(java.util.Map<? extends K,? extends V> initial)
          Method try to initialize a WeakHashMap.
static
<T extends java.util.Map<?,?>>
void
overwriteMapImplementationClass(java.lang.Class<T> clazz)
          External access method to overwrite internal map class.
static
<T extends java.util.Set<?>>
void
overwriteSetImplementationClass(java.lang.Class<T> clazz)
          External access method to overwrite internal set class.
static
<X> java.util.List<X>
secureSubList(java.util.List<X> list, int offset, int limit)
          Clears the indexes in context to the given list, to avoid indexes out of range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAPACITY

private static int CAPACITY

LOAD_FACTORY

private static float LOAD_FACTORY

setClass

private static java.lang.Class<?> setClass
the found class used as Set implementation


mapClass

private static java.lang.Class<?> mapClass
the found class used as Map implementation

Constructor Detail

HashUtil

private HashUtil()
hidden constructor

Method Detail

getHashSet

public static <T> java.util.Set<T> getHashSet(int capacity)
Method try to initialize a gnu.trove.THashSet if the library is located in the class path

Type Parameters:
T - the type of elements
Parameters:
capacity - the initial capacity
Returns:
the created set

getHashSet

public static <T> java.util.Set<T> getHashSet()
Method try to initialize a gnu.trove.THashSet if the library is located in the class path

Type Parameters:
T - the type of elements
Returns:
the created set

getHashSet

public static <T> java.util.Set<T> getHashSet(java.util.Collection<? extends T> initial)
Method try to initialize a gnu.trove.THashSet if the library is located in the class path

Type Parameters:
T - the type of elements
Parameters:
initial - the initial set
Returns:
the created set

getSetClass

private static java.lang.Class<?> getSetClass()
Returns the set class to use. If the method is called at the first time, the set class will be located in the class path.

Returns:
the setClass the set class

getHashMap

public static <K,V> java.util.Map<K,V> getHashMap(int capacity)
Method try to initialize a gnu.trove.THashMap if the library is located in the class path

Type Parameters:
K - the key type
V - the value type
Parameters:
capacity - the initial capacity
Returns:
the created map

getHashMap

public static <K,V> java.util.Map<K,V> getHashMap()
Method try to initialize a gnu.trove.THashMap if the library is located in the class path

Type Parameters:
K - the key type
V - the value type
Returns:
the created map

getHashMap

public static <K,V> java.util.Map<K,V> getHashMap(java.util.Map<? extends K,? extends V> initial)
Method try to initialize a gnu.trove.THashMap if the library is located in the class path

Type Parameters:
K - the key type
V - the value type
Parameters:
initial - the initial map
Returns:
the created map

getMapClass

private static java.lang.Class<?> getMapClass()
Returns the map class to use. If the method is called at the first time, the set class will be located in the class path.

Returns:
the setClass the set class

getWeakHashMap

public static <K,V> java.util.Map<K,V> getWeakHashMap()
Method try to initialize a WeakHashMap.

Type Parameters:
K - the key type
V - the value type
Returns:
the created map

getWeakHashMap

public static <K,V> java.util.Map<K,V> getWeakHashMap(java.util.Map<? extends K,? extends V> initial)
Method try to initialize a WeakHashMap.

Type Parameters:
K - the key type
V - the value type
Parameters:
initial - the initial map
Returns:
the created map

getList

public static <T> java.util.List<T> getList()
Method try to initialize a List.

Type Parameters:
T - the type of arguments
Returns:
the created list

getList

public static <T> java.util.List<T> getList(java.util.Collection<? extends T> initial)
Method try to initialize a List.

Type Parameters:
T - the type of arguments
Parameters:
initial - the initial collection
Returns:
the created list

secureSubList

public static final <X> java.util.List<X> secureSubList(java.util.List<X> list,
                                                        int offset,
                                                        int limit)
Clears the indexes in context to the given list, to avoid indexes out of range.

Parameters:
list - the list
offset - the offset
limit - the limit
Returns:
an two-

overwriteSetImplementationClass

public static <T extends java.util.Set<?>> void overwriteSetImplementationClass(java.lang.Class<T> clazz)
External access method to overwrite internal set class.

Parameters:
clazz - the class

overwriteMapImplementationClass

public static <T extends java.util.Map<?,?>> void overwriteMapImplementationClass(java.lang.Class<T> clazz)
External access method to overwrite internal map class.

Parameters:
clazz - the class