Package org.apache.velocity.util
Class MapFactory
- java.lang.Object
-
- org.apache.velocity.util.MapFactory
-
public class MapFactory extends java.lang.Object
Factory class for creating Maps. The main purpose of this class is to take advantage of Java 5 Concurrent classes if they are available. We use reflection to instantiate java.util.concurrent classes to avoid compile time dependency on Java 5. See Issue 607 for more info on this class.- Since:
- 1.6
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.reflect.Constructor
concurrentHashMapConstructor
-
Constructor Summary
Constructors Constructor Description MapFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Map
create(boolean allowNullKeys)
Creates a new instance of a class that implements Map interface using the JDK defaults for initial size, load factor, etc.static java.util.Map
create(int size, float loadFactor, int concurrencyLevel, boolean allowNullKeys)
Creates a new instance of a class that implements Map interface.
-
-
-
Method Detail
-
create
public static java.util.Map create(boolean allowNullKeys)
Creates a new instance of a class that implements Map interface using the JDK defaults for initial size, load factor, etc. Note that there is a small performance penalty because concurrent maps are created using reflection.- Parameters:
allowNullKeys
- if true, the returned Map instance supports null keys- Returns:
- one of ConcurrentHashMap, HashMap, Hashtable
-
create
public static java.util.Map create(int size, float loadFactor, int concurrencyLevel, boolean allowNullKeys)
Creates a new instance of a class that implements Map interface. Note that there is a small performance penalty because concurrent maps are created using reflection.- Parameters:
size
- initial size of the maploadFactor
- smaller value = better performance, larger value = better memory utilizationconcurrencyLevel
- estimated number of writer Threads. If this is smaller than 1, HashMap is always returned which is not threadsafe.allowNullKeys
- if true, the returned Map instance supports null keys- Returns:
- one of ConcurrentHashMap, HashMap, Hashtable
-
-