/** * 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(); } }); }
public DecodePath(Class<DataType> dataClass, Class<ResourceType> resourceClass, Class<Transcode> transcodeClass, List<? extends ResourceDecoder<DataType, ResourceType>> decoders, ResourceTranscoder<ResourceType, Transcode> transcoder, Pool<List<Exception>> listPool) { this.dataClass = dataClass; this.decoders = decoders; this.transcoder = transcoder; this.listPool = listPool; failureMessage = "Failed DecodePath{" + dataClass.getSimpleName() + "->" + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; }
public LoadPath(Class<Data> dataClass, Class<ResourceType> resourceClass, Class<Transcode> transcodeClass, List<DecodePath<Data, ResourceType, Transcode>> decodePaths, Pool<List<Exception>> listPool) { this.dataClass = dataClass; this.listPool = listPool; this.decodePaths = Preconditions.checkNotEmpty(decodePaths); failureMessage = "Failed LoadPath{" + dataClass.getSimpleName() + "->" + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; }
/** * 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 DecodePath(Class<DataType> dataClass, Class<ResourceType> resourceClass, Class<Transcode> transcodeClass, List<? extends ResourceDecoder<DataType, ResourceType>> decoders, ResourceTranscoder<ResourceType, Transcode> transcoder, Pool<List<Throwable>> listPool) { this.dataClass = dataClass; this.decoders = decoders; this.transcoder = transcoder; this.listPool = listPool; failureMessage = "Failed DecodePath{" + dataClass.getSimpleName() + "->" + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; }
public LoadPath(Class<Data> dataClass, Class<ResourceType> resourceClass, Class<Transcode> transcodeClass, List<DecodePath<Data, ResourceType, Transcode>> decodePaths, Pool<List<Throwable>> listPool) { this.dataClass = dataClass; this.listPool = listPool; this.decodePaths = Preconditions.checkNotEmpty(decodePaths); failureMessage = "Failed LoadPath{" + dataClass.getSimpleName() + "->" + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; }
public ModelLoaderRegistry(Pool<List<Exception>> exceptionListPool) { this(new MultiModelLoaderFactory(exceptionListPool)); }
public MultiModelLoaderFactory(Pool<List<Exception>> exceptionListPool) { this(exceptionListPool, DEFAULT_FACTORY); }
MultiModelLoaderFactory(Pool<List<Exception>> exceptionListPool, Factory factory) { this.exceptionListPool = exceptionListPool; this.factory = factory; }
public <Model, Data> MultiModelLoader<Model, Data> build( List<ModelLoader<Model, Data>> modelLoaders, Pool<List<Exception>> exceptionListPool) { return new MultiModelLoader<>(modelLoaders, exceptionListPool); }
MultiModelLoader(List<ModelLoader<Model, Data>> modelLoaders, Pool<List<Exception>> exceptionListPool) { this.modelLoaders = modelLoaders; this.exceptionListPool = exceptionListPool; }
MultiFetcher(List<DataFetcher<Data>> fetchers, Pool<List<Exception>> exceptionListPool) { this.exceptionListPool = exceptionListPool; Preconditions.checkNotEmpty(fetchers); this.fetchers = fetchers; currentIndex = 0; }
private static <T extends Poolable> Pool<T> build(Pool<T> pool, Factory<T> factory) { return build(pool, factory, FactoryPools.<T>emptyResetter()); }
private static <T> Pool<T> build(Pool<T> pool, Factory<T> factory, Resetter<T> resetter) { return new FactoryPool<>(pool, factory, resetter); }
FactoryPool(Pool<T> pool, Factory<T> factory, Resetter<T> resetter) { this.pool = pool; this.factory = factory; this.resetter = resetter; }
public ModelLoaderRegistry(Pool<List<Throwable>> throwableListPool) { this(new MultiModelLoaderFactory(throwableListPool)); }
public MultiModelLoaderFactory(Pool<List<Throwable>> throwableListPool) { this(throwableListPool, DEFAULT_FACTORY); }
@VisibleForTesting MultiModelLoaderFactory(Pool<List<Throwable>> throwableListPool, Factory factory) { this.throwableListPool = throwableListPool; this.factory = factory; }
public <Model, Data> MultiModelLoader<Model, Data> build( List<ModelLoader<Model, Data>> modelLoaders, Pool<List<Throwable>> throwableListPool) { return new MultiModelLoader<>(modelLoaders, throwableListPool); }
MultiModelLoader(List<ModelLoader<Model, Data>> modelLoaders, Pool<List<Throwable>> exceptionListPool) { this.modelLoaders = modelLoaders; this.exceptionListPool = exceptionListPool; }
MultiFetcher(List<DataFetcher<Data>> fetchers, Pool<List<Throwable>> throwableListPool) { this.throwableListPool = throwableListPool; Preconditions.checkNotEmpty(fetchers); this.fetchers = fetchers; currentIndex = 0; }
/** * Returns a non-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> simple(int size, Factory<T> factory) { return build(new SimplePool<T>(size), factory); }
/** * 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); }
/** * Returns a new {@link Pool} that never returns {@code null} and that contains {@link List Lists} * of a specific generic type with a standard maximum size of 20. * * <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() { return threadSafeList(DEFAULT_POOL_SIZE); }