Package io.beanmapper.core.collections
Class AbstractCollectionHandler<C>
java.lang.Object
io.beanmapper.core.collections.AbstractCollectionHandler<C>
- All Implemented Interfaces:
CollectionHandler<C>
- Direct Known Subclasses:
ListCollectionHandler
,MapCollectionHandler
,SetCollectionHandler
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
Calls the clear method on the target collectionprotected abstract C
create()
Creates a new instance of the collection classprotected C
int
getTargetCollection
(BeanCollectionUsage collectionUsage, Class<C> preferredCollectionClass, Class<?> collectionElementClass, C targetCollection, CollectionFlusher collectionFlusher, Boolean mustFlush) Retrieves either the target collection or creates a new collection instance.getType()
The type of the collection class.boolean
Check if the sourceClass contains the matching class somewhere in its hierarchymapItem
(BeanMapper beanMapper, Class<?> collectionElementClass, Object source) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.beanmapper.core.collections.CollectionHandler
copy, size
-
Constructor Details
-
AbstractCollectionHandler
protected AbstractCollectionHandler()
-
-
Method Details
-
clear
Calls the clear method on the target collection- Parameters:
target
- the collection to call clear() on
-
create
Creates a new instance of the collection class- Returns:
- new instance of the collection class
-
mapItem
-
getTargetCollection
public C getTargetCollection(BeanCollectionUsage collectionUsage, Class<C> preferredCollectionClass, Class<?> collectionElementClass, C targetCollection, CollectionFlusher collectionFlusher, Boolean mustFlush) Description copied from interface:CollectionHandler
Retrieves either the target collection or creates a new collection instance. If CONSTRUCT is set, it will always create a new instance. For the other two options a new instance will only be created if the target collection is null. If CLEAR is used, the target collection will have its clear() method called.- Specified by:
getTargetCollection
in interfaceCollectionHandler<C>
- Parameters:
collectionUsage
- the type of collection usage to applypreferredCollectionClass
- the class type of the target collectioncollectionElementClass
- the class type of an element within the target collectiontargetCollection
- the actual target collectioncollectionFlusher
- the flusher to call after clear has been called on a filled collectionmustFlush
- whether flush must be called after clear on a collection has been called- Returns:
- the target collection to copy the source collection to
-
getType
Description copied from interface:CollectionHandler
The type of the collection class. This will be used to determine if the source collection contains the type somewhere in its super classes or interfaces- Specified by:
getType
in interfaceCollectionHandler<C>
- Returns:
- the type of the collection class
-
isMatch
Description copied from interface:CollectionHandler
Check if the sourceClass contains the matching class somewhere in its hierarchy- Specified by:
isMatch
in interfaceCollectionHandler<C>
- Parameters:
clazz
- the class to check for the type- Returns:
- true if the class can be upcast to the type
-
create
-
getGenericParameterIndex
public int getGenericParameterIndex()- Specified by:
getGenericParameterIndex
in interfaceCollectionHandler<C>
-