Interface RecyclerFactory


public interface RecyclerFactory
Contract for Recycler factories.
Since:
3.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default <V> Recycler<V>
    create(Supplier<V> supplier)
    Creates a new recycler using the given supplier function for initial instances.
    <V> Recycler<V>
    create(Supplier<V> supplier, Consumer<V> cleaner)
    Creates a new recycler using the given supplier and cleaner functions.
  • Method Details

    • create

      default <V> Recycler<V> create(Supplier<V> supplier)
      Creates a new recycler using the given supplier function for initial instances.
      Type Parameters:
      V - the recyclable type
      Parameters:
      supplier - a function to provide initial instances
      Returns:
      a new recycler
    • create

      <V> Recycler<V> create(Supplier<V> supplier, Consumer<V> cleaner)
      Creates a new recycler using the given supplier and cleaner functions.

      The provided supplier needs to make sure that generated instances are always clean.

      Recycled instances are always guaranteed to be clean. The cleaning of an instance can take place either just before acquisition or prior to admitting it back into the reusable instances pool. The moment when the cleaning will be carried out is implementation dependent. Though a released instance should ideally be cleaned immediately to avoid keeping references to unused objects.

      Type Parameters:
      V - the recyclable type
      Parameters:
      supplier - a function to provide initial (and clean!) instances
      cleaner - function to reset an instance before reuse
      Returns:
      a new recycler