add SyncPool.clear()

This commit is contained in:
Hannes Janetzek 2014-04-01 03:42:56 +02:00
parent 82f2070e99
commit e80981e0c5

View File

@ -18,6 +18,7 @@ package org.oscim.utils.pool;
import javax.annotation.CheckReturnValue; import javax.annotation.CheckReturnValue;
@SuppressWarnings({ "rawtypes", "unchecked" })
public abstract class SyncPool<T extends Inlist<?>> { public abstract class SyncPool<T extends Inlist<?>> {
protected final int mMaxFill; protected final int mMaxFill;
protected final boolean mClearItems; protected final boolean mClearItems;
@ -50,6 +51,13 @@ public abstract class SyncPool<T extends Inlist<?>> {
mPool = null; mPool = null;
} }
public synchronized void clear() {
while (mPool != null) {
freeItem(mPool);
mPool = (T) mPool.next;
}
}
/** /**
* @param item * @param item
* set initial state * set initial state
@ -81,7 +89,6 @@ public abstract class SyncPool<T extends Inlist<?>> {
* Usage item = pool.release(item), to ensure to not keep a reference to * Usage item = pool.release(item), to ensure to not keep a reference to
* item! * item!
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" })
@CheckReturnValue @CheckReturnValue
public T release(T item) { public T release(T item) {
if (item == null) if (item == null)
@ -111,7 +118,6 @@ public abstract class SyncPool<T extends Inlist<?>> {
* Usage list = pool.releaseAll(list), to ensure to not keep a reference to * Usage list = pool.releaseAll(list), to ensure to not keep a reference to
* list! * list!
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" })
@CheckReturnValue @CheckReturnValue
public T releaseAll(T item) { public T releaseAll(T item) {
if (item == null) if (item == null)
@ -156,7 +162,6 @@ public abstract class SyncPool<T extends Inlist<?>> {
* *
* @return the item * @return the item
*/ */
@SuppressWarnings("unchecked")
public T get() { public T get() {
synchronized (this) { synchronized (this) {