From 650bb7770d08b279c2a7f00e25337618da54f7f3 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Sat, 16 Dec 2017 14:23:20 -0800 Subject: [PATCH] Start adding nullability annotations to Registry class and its dependencies Signed-off-by: Alex Saveau --- .../java/com/bumptech/glide/Registry.java | 98 ++++++++++++------- .../glide/load/data/DataRewinder.java | 6 +- .../glide/load/data/DataRewinderRegistry.java | 13 ++- .../glide/load/data/InputStreamRewinder.java | 4 + .../resource/bytes/ByteBufferRewinder.java | 7 +- .../transcode/TranscoderRegistry.java | 21 ++-- .../glide/provider/EncoderRegistry.java | 11 ++- .../provider/ImageHeaderParserRegistry.java | 4 +- .../provider/ResourceDecoderRegistry.java | 31 +++--- .../provider/ResourceEncoderRegistry.java | 13 ++- 10 files changed, 135 insertions(+), 73 deletions(-) diff --git a/library/src/main/java/com/bumptech/glide/Registry.java b/library/src/main/java/com/bumptech/glide/Registry.java index d531f09713..41e4c84327 100644 --- a/library/src/main/java/com/bumptech/glide/Registry.java +++ b/library/src/main/java/com/bumptech/glide/Registry.java @@ -1,5 +1,6 @@ package com.bumptech.glide; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.util.Pools.Pool; import com.bumptech.glide.load.Encoder; @@ -82,8 +83,9 @@ public Registry() { * @deprecated Use the equivalent {@link #append(Class, Class, ModelLoaderFactory)} method * instead. */ + @NonNull @Deprecated - public Registry register(Class dataClass, Encoder encoder) { + public Registry register(@NonNull Class dataClass, @NonNull Encoder encoder) { return append(dataClass, encoder); } @@ -102,7 +104,8 @@ public Registry register(Class dataClass, Encoder encoder) { * * @see #prepend(Class, Encoder) */ - public Registry append(Class dataClass, Encoder encoder) { + @NonNull + public Registry append(@NonNull Class dataClass, @NonNull Encoder encoder) { encoderRegistry.append(dataClass, encoder); return this; } @@ -118,7 +121,8 @@ public Registry append(Class dataClass, Encoder encoder) { * * @see #append(Class, Encoder) */ - public Registry prepend(Class dataClass, Encoder encoder) { + @NonNull + public Registry prepend(@NonNull Class dataClass, @NonNull Encoder encoder) { encoderRegistry.prepend(dataClass, encoder); return this; } @@ -143,10 +147,11 @@ public Registry prepend(Class dataClass, Encoder encoder) { * {@link com.bumptech.glide.load.resource.gif.GifDrawable} etc). * @param decoder The {@link ResourceDecoder} to register. */ + @NonNull public Registry append( - Class dataClass, - Class resourceClass, - ResourceDecoder decoder) { + @NonNull Class dataClass, + @NonNull Class resourceClass, + @NonNull ResourceDecoder decoder) { append(BUCKET_APPEND_ALL, dataClass, resourceClass, decoder); return this; } @@ -172,11 +177,12 @@ public Registry append( * {@link com.bumptech.glide.load.resource.gif.GifDrawable} etc). * @param decoder The {@link ResourceDecoder} to register. */ + @NonNull public Registry append( - String bucket, - Class dataClass, - Class resourceClass, - ResourceDecoder decoder) { + @NonNull String bucket, + @NonNull Class dataClass, + @NonNull Class resourceClass, + @NonNull ResourceDecoder decoder) { decoderRegistry.append(bucket, decoder, dataClass, resourceClass); return this; } @@ -201,10 +207,11 @@ public Registry append( * {@link com.bumptech.glide.load.resource.gif.GifDrawable} etc). * @param decoder The {@link ResourceDecoder} to register. */ + @NonNull public Registry prepend( - Class dataClass, - Class resourceClass, - ResourceDecoder decoder) { + @NonNull Class dataClass, + @NonNull Class resourceClass, + @NonNull ResourceDecoder decoder) { prepend(BUCKET_PREPEND_ALL, dataClass, resourceClass, decoder); return this; } @@ -230,11 +237,12 @@ public Registry prepend( * {@link com.bumptech.glide.load.resource.gif.GifDrawable} etc). * @param decoder The {@link ResourceDecoder} to register. */ + @NonNull public Registry prepend( - String bucket, - Class dataClass, - Class resourceClass, - ResourceDecoder decoder) { + @NonNull String bucket, + @NonNull Class dataClass, + @NonNull Class resourceClass, + @NonNull ResourceDecoder decoder) { decoderRegistry.prepend(bucket, decoder, dataClass, resourceClass); return this; } @@ -255,7 +263,8 @@ public Registry prepend( * @param buckets The list of bucket identifiers in order from highest priority to least priority. */ // Final to avoid a PMD error. - public final Registry setResourceDecoderBucketPriorityList(List buckets) { + @NonNull + public final Registry setResourceDecoderBucketPriorityList(@NonNull List buckets) { List modifiedBuckets = new ArrayList<>(buckets); modifiedBuckets.add(0, BUCKET_PREPEND_ALL); modifiedBuckets.add(BUCKET_APPEND_ALL); @@ -279,9 +288,10 @@ public final Registry setResourceDecoderBucketPriorityList(List buckets) * * @deprecated Use the equivalent {@link #append(Class, ResourceEncoder)} method instead. */ + @NonNull @Deprecated public Registry register( - Class resourceClass, ResourceEncoder encoder) { + @NonNull Class resourceClass, @NonNull ResourceEncoder encoder) { return append(resourceClass, encoder); } @@ -301,8 +311,9 @@ public Registry register( * * @see #prepend(Class, ResourceEncoder) */ + @NonNull public Registry append( - Class resourceClass, ResourceEncoder encoder) { + @NonNull Class resourceClass, @NonNull ResourceEncoder encoder) { resourceEncoderRegistry.append(resourceClass, encoder); return this; } @@ -319,8 +330,9 @@ public Registry append( * * @see #append(Class, ResourceEncoder) */ + @NonNull public Registry prepend( - Class resourceClass, ResourceEncoder encoder) { + @NonNull Class resourceClass, @NonNull ResourceEncoder encoder) { resourceEncoderRegistry.prepend(resourceClass, encoder); return this; } @@ -329,7 +341,8 @@ public Registry prepend( * Registers a new {@link com.bumptech.glide.load.data.DataRewinder.Factory} to handle a * non-default data type that can be rewind to allow for efficient reads of file headers. */ - public Registry register(DataRewinder.Factory factory) { + @NonNull + public Registry register(@NonNull DataRewinder.Factory factory) { dataRewinderRegistry.register(factory); return this; } @@ -344,8 +357,10 @@ public Registry register(DataRewinder.Factory factory) { * {@link android.graphics.drawable.BitmapDrawable}). * @param transcoder The {@link ResourceTranscoder} to register. */ - public Registry register(Class resourceClass, - Class transcodeClass, ResourceTranscoder transcoder) { + @NonNull + public Registry register( + @NonNull Class resourceClass, @NonNull Class transcodeClass, + @NonNull ResourceTranscoder transcoder) { transcoderRegistry.register(resourceClass, transcodeClass, transcoder); return this; } @@ -354,7 +369,8 @@ public Registry register(Class resourceClass, * Registers a new {@link ImageHeaderParser} that can obtain some basic metadata from an image * header (orientation, type etc). */ - public Registry register(ImageHeaderParser parser) { + @NonNull + public Registry register(@NonNull ImageHeaderParser parser) { imageHeaderParserRegistry.add(parser); return this; } @@ -381,6 +397,7 @@ public Registry register(ImageHeaderParser parser) { * @param dataClass the data class (e.g. {@link java.io.InputStream}, * {@link java.io.FileDescriptor}). */ + @NonNull public Registry append(Class modelClass, Class dataClass, ModelLoaderFactory factory) { modelLoaderRegistry.append(modelClass, dataClass, factory); @@ -410,6 +427,7 @@ public Registry append(Class modelClass, Class dataCl * @param dataClass the data class (e.g. {@link java.io.InputStream}, * {@link java.io.FileDescriptor}). */ + @NonNull public Registry prepend(Class modelClass, Class dataClass, ModelLoaderFactory factory) { modelLoaderRegistry.prepend(modelClass, dataClass, factory); @@ -439,6 +457,7 @@ public Registry prepend(Class modelClass, Class dataC * @param dataClass the data class (e.g. {@link java.io.InputStream}, * {@link java.io.FileDescriptor}). */ + @NonNull public Registry replace( Class modelClass, Class dataClass, @@ -449,7 +468,8 @@ public Registry replace( @Nullable public LoadPath getLoadPath( - Class dataClass, Class resourceClass, Class transcodeClass) { + @NonNull Class dataClass, @NonNull Class resourceClass, + @NonNull Class transcodeClass) { LoadPath result = loadPathCache.get(dataClass, resourceClass, transcodeClass); if (loadPathCache.isEmptyLoadPath(result)) { @@ -471,9 +491,10 @@ public LoadPath getLoad return result; } + @NonNull private List> getDecodePaths( - Class dataClass, Class resourceClass, Class transcodeClass) { - + @NonNull Class dataClass, @NonNull Class resourceClass, + @NonNull Class transcodeClass) { List> decodePaths = new ArrayList<>(); List> registeredResourceClasses = decoderRegistry.getResourceClasses(dataClass, resourceClass); @@ -495,8 +516,10 @@ private List return decodePaths; } + @Nullable public List> getRegisteredResourceClasses( - Class modelClass, Class resourceClass, Class transcodeClass) { + Class modelClass, @NonNull Class resourceClass, + @NonNull Class transcodeClass) { List> result = modelToResourceClassCache.get(modelClass, resourceClass); if (result == null) { @@ -509,7 +532,7 @@ public List> getRegisteredResourceClasses List> registeredTranscodeClasses = transcoderRegistry .getTranscodeClasses(registeredResourceClass, transcodeClass); if (!registeredTranscodeClasses.isEmpty() && !result.contains(registeredResourceClass)) { - result.add(registeredResourceClass); + result.add(registeredResourceClass); } } } @@ -520,11 +543,12 @@ public List> getRegisteredResourceClasses return result; } - public boolean isResourceEncoderAvailable(Resource resource) { + public boolean isResourceEncoderAvailable(@NonNull Resource resource) { return resourceEncoderRegistry.get(resource.getResourceClass()) != null; } - public ResourceEncoder getResultEncoder(Resource resource) + @Nullable + public ResourceEncoder getResultEncoder(@NonNull Resource resource) throws NoResultEncoderAvailableException { ResourceEncoder resourceEncoder = resourceEncoderRegistry.get(resource.getResourceClass()); if (resourceEncoder != null) { @@ -533,8 +557,9 @@ public ResourceEncoder getResultEncoder(Resource resource) throw new NoResultEncoderAvailableException(resource.getResourceClass()); } + @Nullable @SuppressWarnings("unchecked") - public Encoder getSourceEncoder(X data) throws NoSourceEncoderAvailableException { + public Encoder getSourceEncoder(@NonNull X data) throws NoSourceEncoderAvailableException { Encoder encoder = encoderRegistry.getEncoder((Class) data.getClass()); if (encoder != null) { return encoder; @@ -542,11 +567,13 @@ public Encoder getSourceEncoder(X data) throws NoSourceEncoderAvailableEx throw new NoSourceEncoderAvailableException(data.getClass()); } - public DataRewinder getRewinder(X data) { + @NonNull + public DataRewinder getRewinder(@NonNull X data) { return dataRewinderRegistry.build(data); } - public List> getModelLoaders(Model model) { + @NonNull + public List> getModelLoaders(@NonNull Model model) { List> result = modelLoaderRegistry.getModelLoaders(model); if (result.isEmpty()) { throw new NoModelLoaderAvailableException(model); @@ -554,6 +581,7 @@ public DataRewinder getRewinder(X data) { return result; } + @NonNull public List getImageHeaderParsers() { List result = imageHeaderParserRegistry.getParsers(); if (result.isEmpty()) { diff --git a/library/src/main/java/com/bumptech/glide/load/data/DataRewinder.java b/library/src/main/java/com/bumptech/glide/load/data/DataRewinder.java index 65d64706f2..805198ca6e 100644 --- a/library/src/main/java/com/bumptech/glide/load/data/DataRewinder.java +++ b/library/src/main/java/com/bumptech/glide/load/data/DataRewinder.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.data; +import android.support.annotation.NonNull; import java.io.IOException; /** @@ -20,12 +21,14 @@ interface Factory { /** * Returns a new {@link com.bumptech.glide.load.data.DataRewinder} wrapping the given data. */ - DataRewinder build(T data); + @NonNull + DataRewinder build(@NonNull T data); /** * Returns the class of data this factory can produce * {@link com.bumptech.glide.load.data.DataRewinder}s for. */ + @NonNull Class getDataClass(); } @@ -35,6 +38,7 @@ interface Factory { * * @return An object pointing to the wrapped data. */ + @NonNull T rewindAndGet() throws IOException; /** diff --git a/library/src/main/java/com/bumptech/glide/load/data/DataRewinderRegistry.java b/library/src/main/java/com/bumptech/glide/load/data/DataRewinderRegistry.java index 6949c486b9..9aa20bc8f8 100644 --- a/library/src/main/java/com/bumptech/glide/load/data/DataRewinderRegistry.java +++ b/library/src/main/java/com/bumptech/glide/load/data/DataRewinderRegistry.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.data; +import android.support.annotation.NonNull; import com.bumptech.glide.util.Preconditions; import java.util.HashMap; import java.util.Map; @@ -12,23 +13,26 @@ public class DataRewinderRegistry { private final Map, DataRewinder.Factory> rewinders = new HashMap<>(); private static final DataRewinder.Factory DEFAULT_FACTORY = new DataRewinder.Factory() { + @NonNull @Override - public DataRewinder build(Object data) { + public DataRewinder build(@NonNull Object data) { return new DefaultRewinder(data); } + @NonNull @Override public Class getDataClass() { throw new UnsupportedOperationException("Not implemented"); } }; - public synchronized void register(DataRewinder.Factory factory) { + public synchronized void register(@NonNull DataRewinder.Factory factory) { rewinders.put(factory.getDataClass(), factory); } + @NonNull @SuppressWarnings("unchecked") - public synchronized DataRewinder build(T data) { + public synchronized DataRewinder build(@NonNull T data) { Preconditions.checkNotNull(data); DataRewinder.Factory result = (DataRewinder.Factory) rewinders.get(data.getClass()); if (result == null) { @@ -49,10 +53,11 @@ public synchronized DataRewinder build(T data) { private static final class DefaultRewinder implements DataRewinder { private final Object data; - DefaultRewinder(Object data) { + DefaultRewinder(@NonNull Object data) { this.data = data; } + @NonNull @Override public Object rewindAndGet() { return data; diff --git a/library/src/main/java/com/bumptech/glide/load/data/InputStreamRewinder.java b/library/src/main/java/com/bumptech/glide/load/data/InputStreamRewinder.java index dc7ee528fe..9a0766ce7f 100644 --- a/library/src/main/java/com/bumptech/glide/load/data/InputStreamRewinder.java +++ b/library/src/main/java/com/bumptech/glide/load/data/InputStreamRewinder.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.data; +import android.support.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; import com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream; import com.bumptech.glide.util.Synthetic; @@ -22,6 +23,7 @@ public final class InputStreamRewinder implements DataRewinder { bufferedStream.mark(MARK_LIMIT); } + @NonNull @Override public InputStream rewindAndGet() throws IOException { bufferedStream.reset(); @@ -44,11 +46,13 @@ public Factory(ArrayPool byteArrayPool) { this.byteArrayPool = byteArrayPool; } + @NonNull @Override public DataRewinder build(InputStream data) { return new InputStreamRewinder(data, byteArrayPool); } + @NonNull @Override public Class getDataClass() { return InputStream.class; diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bytes/ByteBufferRewinder.java b/library/src/main/java/com/bumptech/glide/load/resource/bytes/ByteBufferRewinder.java index 7bf3faa215..a154faafb7 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bytes/ByteBufferRewinder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bytes/ByteBufferRewinder.java @@ -1,7 +1,7 @@ package com.bumptech.glide.load.resource.bytes; +import android.support.annotation.NonNull; import com.bumptech.glide.load.data.DataRewinder; -import java.io.IOException; import java.nio.ByteBuffer; /** @@ -16,8 +16,9 @@ public ByteBufferRewinder(ByteBuffer buffer) { this.buffer = buffer; } + @NonNull @Override - public ByteBuffer rewindAndGet() throws IOException { + public ByteBuffer rewindAndGet() { buffer.position(0); return buffer; } @@ -32,11 +33,13 @@ public void cleanup() { */ public static class Factory implements DataRewinder.Factory { + @NonNull @Override public DataRewinder build(ByteBuffer data) { return new ByteBufferRewinder(data); } + @NonNull @Override public Class getDataClass() { return ByteBuffer.class; diff --git a/library/src/main/java/com/bumptech/glide/load/resource/transcode/TranscoderRegistry.java b/library/src/main/java/com/bumptech/glide/load/resource/transcode/TranscoderRegistry.java index b632c35ad8..9c907b65f9 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/transcode/TranscoderRegistry.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/transcode/TranscoderRegistry.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.resource.transcode; +import android.support.annotation.NonNull; import com.bumptech.glide.util.Synthetic; import java.util.ArrayList; import java.util.List; @@ -21,8 +22,9 @@ public class TranscoderRegistry { * @param The type of the resource that the transcoder transcodes from. * @param The type of the resource that the transcoder transcodes to. */ - public synchronized void register(Class decodedClass, Class transcodedClass, - ResourceTranscoder transcoder) { + public synchronized void register( + @NonNull Class decodedClass, @NonNull Class transcodedClass, + @NonNull ResourceTranscoder transcoder) { transcoders.add(new Entry<>(decodedClass, transcodedClass, transcoder)); } @@ -35,9 +37,10 @@ public synchronized void register(Class decodedClass, Class transco * @param The type of the resource that the transcoder transcodes from. * @param The type of the resource that the transcoder transcodes to. */ + @NonNull @SuppressWarnings("unchecked") - public synchronized ResourceTranscoder get(Class resourceClass, - Class transcodedClass) { + public synchronized ResourceTranscoder get( + @NonNull Class resourceClass, @NonNull Class transcodedClass) { // For example, there may be a transcoder that can convert a GifDrawable to a Drawable, which // will be caught above. However, if there is no registered transcoder, we can still just use // the UnitTranscoder to return the Drawable because the transcode class (Drawable) is @@ -55,8 +58,9 @@ public synchronized ResourceTranscoder get(Class resourceClass, "No transcoder registered to transcode from " + resourceClass + " to " + transcodedClass); } - public synchronized List> getTranscodeClasses(Class resourceClass, - Class transcodeClass) { + @NonNull + public synchronized List> getTranscodeClasses( + @NonNull Class resourceClass, @NonNull Class transcodeClass) { List> transcodeClasses = new ArrayList<>(); // GifDrawable -> Drawable is just the UnitTranscoder, as is GifDrawable -> GifDrawable. if (transcodeClass.isAssignableFrom(resourceClass)) { @@ -78,7 +82,8 @@ private static final class Entry { private final Class toClass; @Synthetic final ResourceTranscoder transcoder; - Entry(Class fromClass, Class toClass, ResourceTranscoder transcoder) { + Entry(@NonNull Class fromClass, @NonNull Class toClass, + @NonNull ResourceTranscoder transcoder) { this.fromClass = fromClass; this.toClass = toClass; this.transcoder = transcoder; @@ -90,7 +95,7 @@ private static final class Entry { * we can fulfill requests for a more generic parent class (like Drawable). As a result, we * check fromClass and toClass in different orders. */ - public boolean handles(Class fromClass, Class toClass) { + public boolean handles(@NonNull Class fromClass, @NonNull Class toClass) { return this.fromClass.isAssignableFrom(fromClass) && toClass.isAssignableFrom(this.toClass); } } diff --git a/library/src/main/java/com/bumptech/glide/provider/EncoderRegistry.java b/library/src/main/java/com/bumptech/glide/provider/EncoderRegistry.java index 97a5061808..ca5148a0f5 100644 --- a/library/src/main/java/com/bumptech/glide/provider/EncoderRegistry.java +++ b/library/src/main/java/com/bumptech/glide/provider/EncoderRegistry.java @@ -1,5 +1,6 @@ package com.bumptech.glide.provider; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.bumptech.glide.load.Encoder; import com.bumptech.glide.util.Synthetic; @@ -15,7 +16,7 @@ public class EncoderRegistry { @SuppressWarnings("unchecked") @Nullable - public synchronized Encoder getEncoder(Class dataClass) { + public synchronized Encoder getEncoder(@NonNull Class dataClass) { for (Entry entry : encoders) { if (entry.handles(dataClass)) { return (Encoder) entry.encoder; @@ -24,11 +25,11 @@ public synchronized Encoder getEncoder(Class dataClass) { return null; } - public synchronized void append(Class dataClass, Encoder encoder) { + public synchronized void append(@NonNull Class dataClass, @NonNull Encoder encoder) { encoders.add(new Entry<>(dataClass, encoder)); } - public synchronized void prepend(Class dataClass, Encoder encoder) { + public synchronized void prepend(@NonNull Class dataClass, @NonNull Encoder encoder) { encoders.add(0, new Entry<>(dataClass, encoder)); } @@ -36,12 +37,12 @@ private static final class Entry { private final Class dataClass; @Synthetic @SuppressWarnings("WeakerAccess") final Encoder encoder; - Entry(Class dataClass, Encoder encoder) { + Entry(@NonNull Class dataClass, @NonNull Encoder encoder) { this.dataClass = dataClass; this.encoder = encoder; } - boolean handles(Class dataClass) { + boolean handles(@NonNull Class dataClass) { return this.dataClass.isAssignableFrom(dataClass); } } diff --git a/library/src/main/java/com/bumptech/glide/provider/ImageHeaderParserRegistry.java b/library/src/main/java/com/bumptech/glide/provider/ImageHeaderParserRegistry.java index af329320ef..902fc1bd49 100644 --- a/library/src/main/java/com/bumptech/glide/provider/ImageHeaderParserRegistry.java +++ b/library/src/main/java/com/bumptech/glide/provider/ImageHeaderParserRegistry.java @@ -1,5 +1,6 @@ package com.bumptech.glide.provider; +import android.support.annotation.NonNull; import com.bumptech.glide.load.ImageHeaderParser; import java.util.ArrayList; import java.util.List; @@ -10,11 +11,12 @@ public final class ImageHeaderParserRegistry { private final List parsers = new ArrayList<>(); + @NonNull public synchronized List getParsers() { return parsers; } - public synchronized void add(ImageHeaderParser parser) { + public synchronized void add(@NonNull ImageHeaderParser parser) { parsers.add(parser); } } diff --git a/library/src/main/java/com/bumptech/glide/provider/ResourceDecoderRegistry.java b/library/src/main/java/com/bumptech/glide/provider/ResourceDecoderRegistry.java index b7e95fd406..831453779a 100644 --- a/library/src/main/java/com/bumptech/glide/provider/ResourceDecoderRegistry.java +++ b/library/src/main/java/com/bumptech/glide/provider/ResourceDecoderRegistry.java @@ -1,5 +1,6 @@ package com.bumptech.glide.provider; +import android.support.annotation.NonNull; import com.bumptech.glide.load.ResourceDecoder; import com.bumptech.glide.util.Synthetic; import java.util.ArrayList; @@ -16,7 +17,7 @@ public class ResourceDecoderRegistry { private final List bucketPriorityList = new ArrayList<>(); private final Map>> decoders = new HashMap<>(); - public synchronized void setBucketPriorityList(List buckets) { + public synchronized void setBucketPriorityList(@NonNull List buckets) { List previousBuckets = new ArrayList<>(bucketPriorityList); bucketPriorityList.clear(); bucketPriorityList.addAll(buckets); @@ -29,9 +30,10 @@ public synchronized void setBucketPriorityList(List buckets) { } } + @NonNull @SuppressWarnings("unchecked") - public synchronized List> getDecoders(Class dataClass, - Class resourceClass) { + public synchronized List> getDecoders(@NonNull Class dataClass, + @NonNull Class resourceClass) { List> result = new ArrayList<>(); for (String bucket : bucketPriorityList) { List> entries = decoders.get(bucket); @@ -49,9 +51,10 @@ public synchronized List> getDecoders(Class data return result; } + @NonNull @SuppressWarnings("unchecked") - public synchronized List> getResourceClasses(Class dataClass, - Class resourceClass) { + public synchronized List> getResourceClasses(@NonNull Class dataClass, + @NonNull Class resourceClass) { List> result = new ArrayList<>(); for (String bucket : bucketPriorityList) { List> entries = decoders.get(bucket); @@ -67,17 +70,20 @@ public synchronized List> getResourceClasses(Class dataClass, return result; } - public synchronized void append( - String bucket, ResourceDecoder decoder, Class dataClass, Class resourceClass) { + public synchronized void append(@NonNull String bucket, + @NonNull ResourceDecoder decoder, + @NonNull Class dataClass, @NonNull Class resourceClass) { getOrAddEntryList(bucket).add(new Entry<>(dataClass, resourceClass, decoder)); } - public synchronized void prepend( - String bucket, ResourceDecoder decoder, Class dataClass, Class resourceClass) { + public synchronized void prepend(@NonNull String bucket, + @NonNull ResourceDecoder decoder, + @NonNull Class dataClass, @NonNull Class resourceClass) { getOrAddEntryList(bucket).add(0, new Entry<>(dataClass, resourceClass, decoder)); } - private synchronized List> getOrAddEntryList(String bucket) { + @NonNull + private synchronized List> getOrAddEntryList(@NonNull String bucket) { if (!bucketPriorityList.contains(bucket)) { // Add this unspecified bucket as a low priority bucket. bucketPriorityList.add(bucket); @@ -95,13 +101,14 @@ private static class Entry { @Synthetic final Class resourceClass; @Synthetic final ResourceDecoder decoder; - public Entry(Class dataClass, Class resourceClass, ResourceDecoder decoder) { + public Entry(@NonNull Class dataClass, @NonNull Class resourceClass, + ResourceDecoder decoder) { this.dataClass = dataClass; this.resourceClass = resourceClass; this.decoder = decoder; } - public boolean handles(Class dataClass, Class resourceClass) { + public boolean handles(@NonNull Class dataClass, @NonNull Class resourceClass) { return this.dataClass.isAssignableFrom(dataClass) && resourceClass .isAssignableFrom(this.resourceClass); } diff --git a/library/src/main/java/com/bumptech/glide/provider/ResourceEncoderRegistry.java b/library/src/main/java/com/bumptech/glide/provider/ResourceEncoderRegistry.java index 54430423f9..b1bd2977a4 100644 --- a/library/src/main/java/com/bumptech/glide/provider/ResourceEncoderRegistry.java +++ b/library/src/main/java/com/bumptech/glide/provider/ResourceEncoderRegistry.java @@ -1,5 +1,6 @@ package com.bumptech.glide.provider; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.bumptech.glide.load.ResourceEncoder; import com.bumptech.glide.util.Synthetic; @@ -14,17 +15,19 @@ public class ResourceEncoderRegistry { // TODO: this should probably be a put. private final List> encoders = new ArrayList<>(); - public synchronized void append(Class resourceClass, ResourceEncoder encoder) { + public synchronized void append(@NonNull Class resourceClass, + @NonNull ResourceEncoder encoder) { encoders.add(new Entry<>(resourceClass, encoder)); } - public synchronized void prepend(Class resourceClass, ResourceEncoder encoder) { + public synchronized void prepend(@NonNull Class resourceClass, + @NonNull ResourceEncoder encoder) { encoders.add(0, new Entry<>(resourceClass, encoder)); } @SuppressWarnings("unchecked") @Nullable - public synchronized ResourceEncoder get(Class resourceClass) { + public synchronized ResourceEncoder get(@NonNull Class resourceClass) { //noinspection ForLoopReplaceableByForEach to improve perf for (int i = 0, size = encoders.size(); i < size; i++) { Entry entry = encoders.get(i); @@ -40,13 +43,13 @@ private static final class Entry { private final Class resourceClass; @Synthetic final ResourceEncoder encoder; - Entry(Class resourceClass, ResourceEncoder encoder) { + Entry(@NonNull Class resourceClass, @NonNull ResourceEncoder encoder) { this.resourceClass = resourceClass; this.encoder = encoder; } @Synthetic - boolean handles(Class resourceClass) { + boolean handles(@NonNull Class resourceClass) { return this.resourceClass.isAssignableFrom(resourceClass); } }