net.sf.mmm.util.collection.api
Interface CollectionFactory<COLLECTION extends Collection>

Type Parameters:
COLLECTION - is the generic Collection-type.
All Known Subinterfaces:
BlockingQueueFactory, DequeFactory, ListFactory, QueueFactory, SetFactory, SortedSetFactory
All Known Implementing Classes:
AbstractBlockingQueueFactory, AbstractDequeFactory, AbstractListFactory, AbstractQueueFactory, AbstractSetFactory, AbstractSortedSetFactory, ArrayListFactory, ConcurrentLinkedQueueFactory, HashSetFactory, LinkedBlockingQueueFactory, LinkedListDequeFactory, LinkedListQueueFactory, TreeSetFactory

public interface CollectionFactory<COLLECTION extends Collection>

This is the interface for a factory of Collections. It allows to abstract from Collection implementations.
A Collection instance can be used for different purposes such as a set or a list or with different aspects such as a thread-safe collection. If you write a generic component different users of that component may expect different aspects of your component and therefore the underlying Collection.
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 CollectionFactory rather than a Collection 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 Collection 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)

Method Summary
<E> Collection<E>
create()
          This method creates a new Collection instance.
<E> Collection<E>
create(int capacity)
          This method creates a new Collection instance with the given initial capacity.
 COLLECTION createGeneric()
          This method creates a new instance of the generic Collection type <COLLECTION>.
 COLLECTION createGeneric(int capacity)
          This method creates a new instance of the generic Collection type <COLLECTION> with the given initial capacity.
 Class<? extends COLLECTION> getCollectionImplementation()
          This method gets the implementation of the collection-interface used by this factory.
 Class<COLLECTION> getCollectionInterface()
          This method gets the interface of the Collection managed by this factory.
 

Method Detail

getCollectionInterface

Class<COLLECTION> getCollectionInterface()
This method gets the interface of the Collection managed by this factory.

Returns:
the Collection interface.

getCollectionImplementation

Class<? extends COLLECTION> getCollectionImplementation()
This method gets the implementation of the collection-interface used by this factory.

Returns:
the Collection implementation.

createGeneric

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

Returns:
the new collection instance.

createGeneric

COLLECTION createGeneric(int capacity)
This method creates a new instance of the generic Collection type <COLLECTION> with the given initial capacity.

Parameters:
capacity - is the initial capacity of the collection.
Returns:
the new collection instance.

create

<E> Collection<E> create()
This method creates a new Collection instance.
It is explicitly typed and respects the generic element type of the collection. Therefore the type of the Collection can NOT be bound to the generic type <COLLECTION> because of limitations in Java's generic type system. You need to work on the actual sub-interface (e.g. ListFactory) to get the proper result type.

Type Parameters:
E - the type of elements contained in the collection.
Returns:
the new collection instance.
See Also:
createGeneric()

create

<E> Collection<E> create(int capacity)
This method creates a new Collection instance with the given initial capacity.
It is explicitly typed and respects the generic element type of the collection. Therefore the type of the Collection can NOT be bound to the generic type <COLLECTION> because of limitations in Java's generic type system. You need to work on the actual sub-interface (e.g. ListFactory) to get the proper result type.

Type Parameters:
E - the type of elements contained in the collection.
Parameters:
capacity - is the initial capacity of the collection.
Returns:
the new collection instance.
See Also:
createGeneric(int)


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