Class FactoryPools


  • public final class FactoryPools
    extends java.lang.Object
    Provides implementations of Pools.Pool never return null, log when new instances are created, and that can use the FactoryPools.Poolable interface to ensure objects aren't used while inside the pool.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  FactoryPools.Factory<T>
      Creates new instances of the given type.
      static interface  FactoryPools.Poolable
      Allows additional verification to catch errors caused by using objects while they are in an object pool.
      static interface  FactoryPools.Resetter<T>
      Resets state when objects are returned to the pool.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends FactoryPools.Poolable>
      androidx.core.util.Pools.Pool<T>
      simple​(int size, FactoryPools.Factory<T> factory)
      Returns a non-thread safe Pools.Pool that never returns null from Pools.Pool.acquire() and that contains objects of the type created by the given FactoryPools.Factory with the given maximum size.
      static <T extends FactoryPools.Poolable>
      androidx.core.util.Pools.Pool<T>
      threadSafe​(int size, FactoryPools.Factory<T> factory)
      Returns a new thread safe Pools.Pool that never returns null from Pools.Pool.acquire() and that contains objects of the type created by the given FactoryPools.Factory with the given maximum size.
      static <T> androidx.core.util.Pools.Pool<java.util.List<T>> threadSafeList()
      Returns a new Pools.Pool that never returns null and that contains Lists of a specific generic type with a standard maximum size of 20.
      static <T> androidx.core.util.Pools.Pool<java.util.List<T>> threadSafeList​(int size)
      Returns a new thread safe Pools.Pool that never returns null and that contains Lists of a specific generic type with the given maximum size.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • simple

        @NonNull
        public static <T extends FactoryPools.Poolable> androidx.core.util.Pools.Pool<T> simple​(int size,
                                                                                                @NonNull
                                                                                                FactoryPools.Factory<T> factory)
        Returns a non-thread safe Pools.Pool that never returns null from Pools.Pool.acquire() and that contains objects of the type created by the given FactoryPools.Factory with the given maximum size.

        If the pool is empty when Pools.Pool.acquire() is called, the given FactoryPools.Factory will be used to create a new instance.

        Type Parameters:
        T - The type of object the pool will contains.
      • threadSafe

        @NonNull
        public static <T extends FactoryPools.Poolable> androidx.core.util.Pools.Pool<T> threadSafe​(int size,
                                                                                                    @NonNull
                                                                                                    FactoryPools.Factory<T> factory)
        Returns a new thread safe Pools.Pool that never returns null from Pools.Pool.acquire() and that contains objects of the type created by the given FactoryPools.Factory with the given maximum size.

        If the pool is empty when Pools.Pool.acquire() is called, the given FactoryPools.Factory will be used to create a new instance.

        Type Parameters:
        T - The type of object the pool will contains.
      • threadSafeList

        @NonNull
        public static <T> androidx.core.util.Pools.Pool<java.util.List<T>> threadSafeList()
        Returns a new Pools.Pool that never returns null and that contains Lists of a specific generic type with a standard maximum size of 20.

        If the pool is empty when Pools.Pool.acquire() is called, a new List will be created.

        Type Parameters:
        T - The type of object that the Lists will contain.
      • threadSafeList

        @NonNull
        public static <T> androidx.core.util.Pools.Pool<java.util.List<T>> threadSafeList​(int size)
        Returns a new thread safe Pools.Pool that never returns null and that contains Lists of a specific generic type with the given maximum size.

        If the pool is empty when Pools.Pool.acquire() is called, a new List will be created.

        Type Parameters:
        T - The type of object that the Lists will contain.