Class AbstractCollectionHandler<C>

java.lang.Object
io.beanmapper.core.collections.AbstractCollectionHandler<C>
All Implemented Interfaces:
CollectionHandler<C>
Direct Known Subclasses:
ListCollectionHandler, MapCollectionHandler, QueueCollectionHandler, SetCollectionHandler

public abstract class AbstractCollectionHandler<C> extends Object implements CollectionHandler<C>
  • Constructor Details

    • AbstractCollectionHandler

      protected AbstractCollectionHandler()
  • Method Details

    • clear

      protected abstract void clear(C target)
      Calls the clear method on the target collection
      Parameters:
      target - the collection to call clear() on
    • create

      protected abstract C create()
      Creates a new instance of the collection class
      Returns:
      new instance of the collection class
    • mapItem

      public Object mapItem(BeanMapper beanMapper, Class<?> collectionElementClass, Object source)
    • 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 interface CollectionHandler<C>
      Parameters:
      collectionUsage - the type of collection usage to apply
      preferredCollectionClass - the class type of the target collection
      collectionElementClass - the class type of an element within the target collection
      targetCollection - the actual target collection
      collectionFlusher - the flusher to call after clear has been called on a filled collection
      mustFlush - whether flush must be called after clear on a collection has been called
      Returns:
      the target collection to copy the source collection to
    • getType

      public Class<C> 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 interface CollectionHandler<C>
      Returns:
      the type of the collection class
    • isMatch

      public boolean isMatch(Class<?> clazz)
      Description copied from interface: CollectionHandler
      Check if the sourceClass contains the matching class somewhere in its hierarchy
      Specified by:
      isMatch in interface CollectionHandler<C>
      Parameters:
      clazz - the class to check for the type
      Returns:
      true if the class can be upcast to the type
    • create

      protected C create(Class<?> elementClass)
    • getGenericParameterIndex

      public int getGenericParameterIndex()
      Specified by:
      getGenericParameterIndex in interface CollectionHandler<C>