Class LruArrayPool

  • All Implemented Interfaces:
    ArrayPool

    public final class LruArrayPool
    extends java.lang.Object
    implements ArrayPool
    A fixed size Array Pool that evicts arrays using an LRU strategy to keep the pool under the maximum byte size.
    • Constructor Summary

      Constructors 
      Constructor Description
      LruArrayPool()  
      LruArrayPool​(int maxSize)
      Constructor for a new pool.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void clearMemory()
      Clears all arrays from the pool.
      <T> T get​(int size, java.lang.Class<T> arrayClass)
      Returns a non-null array of the given type with a length >= to the given size.
      <T> T getExact​(int size, java.lang.Class<T> arrayClass)
      Returns a non-null array of the given type with a length exactly equal to the given size.
      <T> void put​(T array)
      Optionally adds the given array of the given type to the pool.
      <T> void put​(T array, java.lang.Class<T> arrayClass)
      Deprecated.
      void trimMemory​(int level)
      Trims the size to the appropriate level.
      • Methods inherited from class java.lang.Object

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

      • LruArrayPool

        public LruArrayPool()
      • LruArrayPool

        public LruArrayPool​(int maxSize)
        Constructor for a new pool.
        Parameters:
        maxSize - The maximum size in integers of the pool.
    • Method Detail

      • put

        @Deprecated
        public <T> void put​(T array,
                            java.lang.Class<T> arrayClass)
        Deprecated.
        Description copied from interface: ArrayPool
        Optionally adds the given array of the given type to the pool.

        Arrays may be ignored, for example if the array is larger than the maximum size of the pool.

        Specified by:
        put in interface ArrayPool
      • put

        public <T> void put​(T array)
        Description copied from interface: ArrayPool
        Optionally adds the given array of the given type to the pool.

        Arrays may be ignored, for example if the array is larger than the maximum size of the pool.

        Specified by:
        put in interface ArrayPool
      • getExact

        public <T> T getExact​(int size,
                              java.lang.Class<T> arrayClass)
        Description copied from interface: ArrayPool
        Returns a non-null array of the given type with a length exactly equal to the given size.

        If an array of the given size isn't in the pool, a new one will be allocated.

        This class makes no guarantees about the contents of the returned array.

        Specified by:
        getExact in interface ArrayPool
        See Also:
        ArrayPool.get(int, Class)
      • get

        public <T> T get​(int size,
                         java.lang.Class<T> arrayClass)
        Description copied from interface: ArrayPool
        Returns a non-null array of the given type with a length >= to the given size.

        If an array of the given size isn't in the pool, a new one will be allocated.

        This class makes no guarantees about the contents of the returned array.

        Specified by:
        get in interface ArrayPool
        See Also:
        ArrayPool.getExact(int, Class)
      • clearMemory

        public void clearMemory()
        Description copied from interface: ArrayPool
        Clears all arrays from the pool.
        Specified by:
        clearMemory in interface ArrayPool
      • trimMemory

        public void trimMemory​(int level)
        Description copied from interface: ArrayPool
        Trims the size to the appropriate level.
        Specified by:
        trimMemory in interface ArrayPool
        Parameters:
        level - A trim specified in ComponentCallbacks2.