|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
MAP - is the generic Map-type.public interface MapFactory<MAP extends Map>
This is the interface for a factory of maps. It allows to
abstract from Map implementations.
A Map instance can be used for different purposes such as a cache or
with different aspects such as a thread-safe map. If you write a generic
component different users of that component may expect different aspects of
your component and therefore the underlying Map.
If you use this interface and allow the user to inject an instance of this interface to override the default, your code will
increase usability.
Why passing a MapFactory rather than a Map instance to the
constructor?
Since java 5 you want to use generics for type-safe code. If these generic
types change slightly over the time of development (e.g. from
Class to Class<?>) you would break
compatibility of the users of your code. Additionally you may want to express
that the Map should be empty and/or NOT shared with others. Anyways
the interface can obviously NOT guarantee this.
HashMapFactory.INSTANCE| Method Summary | ||
|---|---|---|
|
create()
This method creates a new Map instance. |
|
|
create(int capacity)
This method creates a new Map instance with the given
capacity. |
|
MAP |
createGeneric()
This method creates a new instance of the generic Map type
<MAP>. |
|
MAP |
createGeneric(int capacity)
This method creates a new instance of the generic Map type
<MAP>. |
|
Class<? extends MAP> |
getMapImplementation()
This method gets the implementation of the map-interface used by this factory. |
|
Class<MAP> |
getMapInterface()
This method gets the interface of the Map managed by this factory. |
|
| Method Detail |
|---|
Class<MAP> getMapInterface()
Map managed by this factory.
Map interface.Class<? extends MAP> getMapImplementation()
map-interface used by this factory.
Map implementation.<K,V> Map<K,V> create()
Map instance.Map can NOT be bound to the generic
type <MAP> because of limitations in Java's generic type
system. You need to work on the actual sub-interface (e.g.
SortedMapFactory) to get a more specific result type.
K - the type of keys maintained by the map.V - the type of mapped values.
<K,V> Map<K,V> create(int capacity)
Map instance with the given
capacity. For a regular map this will be the initial capacity
while a cache may never grow beyond this capacity limit and if reached
force out entries last recently of frequently used.
K - the type of keys maintained by the map.V - the type of mapped values.capacity - is the capacity of the map to create.
MAP createGeneric()
Map type
<MAP>.
Map instance.MAP createGeneric(int capacity)
Map type
<MAP>.
capacity - is the capacity of the map to create.
Map instance.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||