/** * Returns a new thread safe {@link Pool} that never returns {@code null} and that contains * {@link List Lists} of a specific generic type with the given maximum size. * * <p>If the pool is empty when {@link Pool#acquire()} is called, a new {@link List} will be * created. * * @param <T> The type of object that the {@link List Lists} will contain. */ // Public API. @SuppressWarnings("WeakerAccess") public static <T> Pool<List<T>> threadSafeList(int size) { return build(new SynchronizedPool<List<T>>(size), new Factory<List<T>>() { @Override public List<T> create() { return new ArrayList<>(); } }, new Resetter<List<T>>() { @Override public void reset(List<T> object) { object.clear(); } }); }
/** * Returns a new thread safe {@link Pool} that never returns {@code null} and that contains * {@link List Lists} of a specific generic type with the given maximum size. * * <p>If the pool is empty when {@link Pool#acquire()} is called, a new {@link List} will be * created. * * @param <T> The type of object that the {@link List Lists} will contain. */ public static <T> Pool<List<T>> threadSafeList(int size) { return build(new SynchronizedPool<List<T>>(size), new Factory<List<T>>() { @Override public List<T> create() { return new ArrayList<>(); } }, new Resetter<List<T>>() { @Override public void reset(List<T> object) { object.clear(); } }); }
public ArtDecoder(BitmapPool bitmapPool, int maxNumThreads, SynchronizedPool decodeBuffers) { mBitmapPool = bitmapPool; mDecodeBuffers = decodeBuffers; for (int i = 0; i < maxNumThreads; i++) { mDecodeBuffers.release(ByteBuffer.allocate(DECODE_BUFFER_SIZE)); } }
/** * Returns a new thread safe {@link Pool} that never returns {@code null} from * {@link Pool#acquire()} and that contains objects of the type created by the given * {@link Factory} with the given maximum size. * * <p>If the pool is empty when {@link Pool#acquire()} is called, the given {@link Factory} will * be used to create a new instance. * * @param <T> The type of object the pool will contains. */ public static <T extends Poolable> Pool<T> threadSafe(int size, Factory<T> factory) { return build(new SynchronizedPool<T>(size), factory); }