Class SyncPool<T extends Inlist<?>>

java.lang.Object
org.oscim.utils.pool.SyncPool<T>
Direct Known Subclasses:
TextureItem.TexturePool

public abstract class SyncPool<T extends Inlist<?>> extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final boolean
     
    protected int
     
    protected final int
     
    protected T
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SyncPool(int maxItemsInPool)
     
    SyncPool(int maxItemsInPool, boolean clearItems)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected boolean
    clearItem(T item)
     
    protected abstract T
    Creates the item.
    protected void
    freeItem(T item)
     
    get()
    Gets an 'item' from pool, if pool is empty a new item will be created by createItem().
    int
     
    void
    init(int items)
    To be implemented by subclass.
    release(T item)
    Release 'item' to pool.
    releaseAll(T item)
    Release 'list' to pool.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mMaxFill

      protected final int mMaxFill
    • mClearItems

      protected final boolean mClearItems
    • mFill

      protected int mFill
    • mPool

      protected T extends Inlist<?> mPool
  • Constructor Details

    • SyncPool

      public SyncPool(int maxItemsInPool)
    • SyncPool

      public SyncPool(int maxItemsInPool, boolean clearItems)
  • Method Details

    • getFill

      public int getFill()
    • init

      public void init(int items)
      To be implemented by subclass.
      Parameters:
      items - number of initial items
    • clear

      public void clear()
    • clearItem

      protected boolean clearItem(T item)
      Parameters:
      item - set initial state
      Returns:
      'true' when item should be added back to pool, 'false' when freeItem should be called.
    • freeItem

      protected void freeItem(T item)
      Parameters:
      item - release resources
    • createItem

      protected abstract T createItem()
      Creates the item. To be implemented by subclass.
      Returns:
      the item
    • release

      @CheckReturnValue public T release(T item)
      Release 'item' to pool.

      Usage item = pool.release(item), to ensure to not keep a reference to item!

    • releaseAll

      @CheckReturnValue public T releaseAll(T item)
      Release 'list' to pool.

      Usage list = pool.releaseAll(list), to ensure to not keep a reference to list!

    • get

      public T get()
      Gets an 'item' from pool, if pool is empty a new item will be created by createItem().
      Returns:
      the item