net.sf.mmm.util.collection.api
Interface MapFactory<MAP extends Map>

Type Parameters:
MAP - is the generic Map-type.
All Known Subinterfaces:
ConcurrentMapFactory, SortedMapFactory
All Known Implementing Classes:
AbstractConcurrentMapFactory, AbstractMapFactory, AbstractSortedMapFactory, ConcurrentHashMapFactory, HashMapFactory, TreeMapFactory

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.

Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
HashMapFactory.INSTANCE

Method Summary
<K,V> Map<K,V>
create()
          This method creates a new Map instance.
<K,V> Map<K,V>
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

getMapInterface

Class<MAP> getMapInterface()
This method gets the interface of the Map managed by this factory.

Returns:
the Map interface.

getMapImplementation

Class<? extends MAP> getMapImplementation()
This method gets the implementation of the map-interface used by this factory.

Returns:
the Map implementation.

create

<K,V> Map<K,V> create()
This method creates a new Map instance.
It is explicitly typed and respects the generic key and value type of the map. Therefore the type of the 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.

Type Parameters:
K - the type of keys maintained by the map.
V - the type of mapped values.
Returns:
the new map instance.

create

<K,V> Map<K,V> create(int capacity)
This method creates a new 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.

Type Parameters:
K - the type of keys maintained by the map.
V - the type of mapped values.
Parameters:
capacity - is the capacity of the map to create.
Returns:
the new map instance.

createGeneric

MAP createGeneric()
This method creates a new instance of the generic Map type <MAP>.

Returns:
the new Map instance.

createGeneric

MAP createGeneric(int capacity)
This method creates a new instance of the generic Map type <MAP>.

Parameters:
capacity - is the capacity of the map to create.
Returns:
the new Map instance.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.