Skip to content

Commit

Permalink
Finish adding nullability annotations to Registry class and its depen…
Browse files Browse the repository at this point in the history
…dencies (#2746)

Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored and sjudd committed Dec 23, 2017
1 parent 0e3172a commit e35a73b
Show file tree
Hide file tree
Showing 40 changed files with 174 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static synchronized <T> WaitModel<T> waitOn(T model) {
return new WaitModel<>(model);
}

@NonNull
@Override
public ModelLoader<WaitModel<Model>, Data> build(
MultiModelLoaderFactory multiFactory) {
Expand All @@ -106,7 +107,7 @@ private static final class WaitFetcher<Data> implements DataFetcher<Data> {
}

@Override
public void loadData(Priority priority, DataCallback<? super Data> callback) {
public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super Data> callback) {
ConcurrencyHelper.waitOnLatch(toWaitOn);
wrapped.loadData(priority, callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public OkHttpStreamFetcher(OkHttpClient client, GlideUrl url) {
}

@Override
public void loadData(Priority priority, final DataCallback<? super InputStream> callback) {
public void loadData(@NonNull Priority priority,
@NonNull final DataCallback<? super InputStream> callback) {
Request.Builder requestBuilder = new Request.Builder().url(url.toStringUrl());
for (Map.Entry<String, String> headerEntry : url.getHeaders().entrySet()) {
String key = headerEntry.getKey();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.integration.okhttp;

import android.support.annotation.NonNull;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.ModelLoader;
Expand All @@ -25,14 +26,14 @@ public OkHttpUrlLoader(OkHttpClient client) {
}

@Override
public boolean handles(GlideUrl url) {
public boolean handles(@NonNull GlideUrl url) {
return true;
}

@SuppressWarnings("deprecation")
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
Options options) {
public LoadData<InputStream> buildLoadData(@NonNull GlideUrl model, int width, int height,
@NonNull Options options) {
return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}

Expand Down Expand Up @@ -70,6 +71,7 @@ public Factory(OkHttpClient client) {
this.client = client;
}

@NonNull
@SuppressWarnings("deprecation")
@Override
public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
/**
* Fetches an {@link InputStream} using the okhttp library.
*/
public class OkHttpStreamFetcher implements DataFetcher<InputStream>,
okhttp3.Callback {
public class OkHttpStreamFetcher implements DataFetcher<InputStream>, okhttp3.Callback {
private static final String TAG = "OkHttpFetcher";
private final Call.Factory client;
private final GlideUrl url;
Expand All @@ -40,7 +39,8 @@ public OkHttpStreamFetcher(Call.Factory client, GlideUrl url) {
}

@Override
public void loadData(Priority priority, final DataCallback<? super InputStream> callback) {
public void loadData(@NonNull Priority priority,
@NonNull final DataCallback<? super InputStream> callback) {
Request.Builder requestBuilder = new Request.Builder().url(url.toStringUrl());
for (Map.Entry<String, String> headerEntry : url.getHeaders().entrySet()) {
String key = headerEntry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.support.annotation.NonNull;
import android.util.Log;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
Expand Down Expand Up @@ -51,7 +50,8 @@ public VolleyStreamFetcher(RequestQueue requestQueue, GlideUrl url,
}

@Override
public void loadData(Priority priority, DataCallback<? super InputStream> callback) {
public void loadData(@NonNull Priority priority,
@NonNull DataCallback<? super InputStream> callback) {
request = requestFactory.create(url.toStringUrl(), callback, glideToVolleyPriority(priority),
url.getHeaders());
requestQueue.add(request);
Expand Down Expand Up @@ -82,7 +82,7 @@ public DataSource getDataSource() {
return DataSource.REMOTE;
}

private static Request.Priority glideToVolleyPriority(Priority priority) {
private static Request.Priority glideToVolleyPriority(@NonNull Priority priority) {
switch (priority) {
case LOW:
return Request.Priority.LOW;
Expand Down Expand Up @@ -119,7 +119,7 @@ public GlideRequest(String url, DataCallback<? super InputStream> callback, Prio
}

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
public Map<String, String> getHeaders() {
return headers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Factory(RequestQueue requestQueue, VolleyRequestFactory requestFactory) {
this.requestQueue = requestQueue;
}

@NonNull
@Override
public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory factory) {
return new VolleyUrlLoader(requestQueue, requestFactory);
Expand Down
29 changes: 16 additions & 13 deletions library/src/main/java/com/bumptech/glide/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ public Registry register(@NonNull ImageHeaderParser parser) {
* {@link java.io.FileDescriptor}).
*/
@NonNull
public <Model, Data> Registry append(Class<Model> modelClass, Class<Data> dataClass,
ModelLoaderFactory<Model, Data> factory) {
public <Model, Data> Registry append(
@NonNull Class<Model> modelClass, @NonNull Class<Data> dataClass,
@NonNull ModelLoaderFactory<Model, Data> factory) {
modelLoaderRegistry.append(modelClass, dataClass, factory);
return this;
}
Expand Down Expand Up @@ -428,8 +429,9 @@ public <Model, Data> Registry append(Class<Model> modelClass, Class<Data> dataCl
* {@link java.io.FileDescriptor}).
*/
@NonNull
public <Model, Data> Registry prepend(Class<Model> modelClass, Class<Data> dataClass,
ModelLoaderFactory<Model, Data> factory) {
public <Model, Data> Registry prepend(
@NonNull Class<Model> modelClass, @NonNull Class<Data> dataClass,
@NonNull ModelLoaderFactory<Model, Data> factory) {
modelLoaderRegistry.prepend(modelClass, dataClass, factory);
return this;
}
Expand Down Expand Up @@ -459,9 +461,9 @@ public <Model, Data> Registry prepend(Class<Model> modelClass, Class<Data> dataC
*/
@NonNull
public <Model, Data> Registry replace(
Class<Model> modelClass,
Class<Data> dataClass,
ModelLoaderFactory<? extends Model, ? extends Data> factory) {
@NonNull Class<Model> modelClass,
@NonNull Class<Data> dataClass,
@NonNull ModelLoaderFactory<? extends Model, ? extends Data> factory) {
modelLoaderRegistry.replace(modelClass, dataClass, factory);
return this;
}
Expand Down Expand Up @@ -518,7 +520,7 @@ private <Data, TResource, Transcode> List<DecodePath<Data, TResource, Transcode>

@Nullable
public <Model, TResource, Transcode> List<Class<?>> getRegisteredResourceClasses(
Class<Model> modelClass, @NonNull Class<TResource> resourceClass,
@NonNull Class<Model> modelClass, @NonNull Class<TResource> resourceClass,
@NonNull Class<Transcode> transcodeClass) {
List<Class<?>> result = modelToResourceClassCache.get(modelClass, resourceClass);

Expand Down Expand Up @@ -597,11 +599,12 @@ public List<ImageHeaderParser> getImageHeaderParsers() {
// Never serialized by Glide.
@SuppressWarnings("serial")
public static class NoModelLoaderAvailableException extends MissingComponentException {
public NoModelLoaderAvailableException(Object model) {
public NoModelLoaderAvailableException(@NonNull Object model) {
super("Failed to find any ModelLoaders for model: " + model);
}

public NoModelLoaderAvailableException(Class<?> modelClass, Class<?> dataClass) {
public NoModelLoaderAvailableException(@NonNull Class<?> modelClass,
@NonNull Class<?> dataClass) {
super("Failed to find any ModelLoaders for model: " + modelClass + " and data: " + dataClass);
}
}
Expand All @@ -612,7 +615,7 @@ public NoModelLoaderAvailableException(Class<?> modelClass, Class<?> dataClass)
// Never serialized by Glide.
@SuppressWarnings("serial")
public static class NoResultEncoderAvailableException extends MissingComponentException {
public NoResultEncoderAvailableException(Class<?> resourceClass) {
public NoResultEncoderAvailableException(@NonNull Class<?> resourceClass) {
super("Failed to find result encoder for resource class: " + resourceClass);
}
}
Expand All @@ -623,7 +626,7 @@ public NoResultEncoderAvailableException(Class<?> resourceClass) {
// Never serialized by Glide.
@SuppressWarnings("serial")
public static class NoSourceEncoderAvailableException extends MissingComponentException {
public NoSourceEncoderAvailableException(Class<?> dataClass) {
public NoSourceEncoderAvailableException(@NonNull Class<?> dataClass) {
super("Failed to find source encoder for data class: " + dataClass);
}
}
Expand All @@ -634,7 +637,7 @@ public NoSourceEncoderAvailableException(Class<?> dataClass) {
// Never serialized by Glide.
@SuppressWarnings("serial")
public static class MissingComponentException extends RuntimeException {
public MissingComponentException(String message) {
public MissingComponentException(@NonNull String message) {
super(message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AssetPathFetcher(AssetManager assetManager, String assetPath) {
}

@Override
public void loadData(Priority priority, DataCallback<? super T> callback) {
public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super T> callback) {
try {
data = loadResource(assetManager, assetPath);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface DataCallback<T> {
*
* @param e a non-null {@link Exception} indicating why the load failed.
*/
void onLoadFailed(Exception e);
void onLoadFailed(@NonNull Exception e);
}

/**
Expand All @@ -63,7 +63,7 @@ interface DataCallback<T> {
* @param callback The callback to use when the request is complete
* @see #cleanup() where the data retuned will be cleaned up
*/
void loadData(Priority priority, DataCallback<? super T> callback);
void loadData(@NonNull Priority priority, @NonNull DataCallback<? super T> callback);

/**
* Cleanup or recycle any resources used by this data fetcher. This method will be called in a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public HttpUrlFetcher(GlideUrl glideUrl, int timeout) {
}

@Override
public void loadData(Priority priority, DataCallback<? super InputStream> callback) {
public void loadData(@NonNull Priority priority,
@NonNull DataCallback<? super InputStream> callback) {
long startTime = LogTime.getLogTime();
final InputStream result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public LocalUriFetcher(ContentResolver contentResolver, Uri uri) {
}

@Override
public final void loadData(Priority priority, DataCallback<? super T> callback) {
public final void loadData(@NonNull Priority priority,
@NonNull DataCallback<? super T> callback) {
try {
data = loadResource(uri, contentResolver);
} catch (FileNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ private static ThumbFetcher build(Context context, Uri uri, ThumbnailQuery query
}

@Override
public void loadData(Priority priority, DataCallback<? super InputStream> callback) {
public void loadData(@NonNull Priority priority,
@NonNull DataCallback<? super InputStream> callback) {
try {
inputStream = openThumbInputStream();
} catch (FileNotFoundException e) {
Expand Down Expand Up @@ -117,11 +118,11 @@ static class VideoThumbnailQuery implements ThumbnailQuery {
}

private static final String[] PATH_PROJECTION = {
MediaStore.Video.Thumbnails.DATA
MediaStore.Video.Thumbnails.DATA
};
private static final String PATH_SELECTION =
MediaStore.Video.Thumbnails.KIND + " = " + MediaStore.Video.Thumbnails.MINI_KIND
+ " AND " + MediaStore.Video.Thumbnails.VIDEO_ID + " = ?";
+ " AND " + MediaStore.Video.Thumbnails.VIDEO_ID + " = ?";

@Override
public Cursor query(Uri uri) {
Expand All @@ -145,11 +146,11 @@ static class ImageThumbnailQuery implements ThumbnailQuery {
}

private static final String[] PATH_PROJECTION = {
MediaStore.Images.Thumbnails.DATA,
MediaStore.Images.Thumbnails.DATA,
};
private static final String PATH_SELECTION =
MediaStore.Images.Thumbnails.KIND + " = " + MediaStore.Images.Thumbnails.MINI_KIND
+ " AND " + MediaStore.Images.Thumbnails.IMAGE_ID + " = ?";
+ " AND " + MediaStore.Images.Thumbnails.IMAGE_ID + " = ?";

@Override
public Cursor query(Uri uri) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine;

import android.support.annotation.NonNull;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.data.DataFetcher;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void onDataReady(Object data) {
}

@Override
public void onLoadFailed(Exception e) {
public void onLoadFailed(@NonNull Exception e) {
cb.onDataFetcherFailed(sourceKey, e, loadData.fetcher, DataSource.DATA_DISK_CACHE);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine;

import android.support.annotation.NonNull;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.Transformation;
Expand Down Expand Up @@ -110,7 +111,7 @@ public void onDataReady(Object data) {
}

@Override
public void onLoadFailed(Exception e) {
public void onLoadFailed(@NonNull Exception e) {
cb.onDataFetcherFailed(currentKey, e, loadData.fetcher, DataSource.RESOURCE_DISK_CACHE);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine;

import android.support.annotation.NonNull;
import android.util.Log;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.Encoder;
Expand Down Expand Up @@ -114,7 +115,7 @@ public void onDataReady(Object data) {
}

@Override
public void onLoadFailed(Exception e) {
public void onLoadFailed(@NonNull Exception e) {
cb.onDataFetcherFailed(originalKey, e, loadData.fetcher, loadData.fetcher.getDataSource());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public StreamFactory(AssetManager assetManager) {
this.assetManager = assetManager;
}

@NonNull
@Override
public ModelLoader<Uri, InputStream> build(MultiModelLoaderFactory multiFactory) {
return new AssetUriLoader<>(assetManager, this);
Expand Down Expand Up @@ -96,6 +97,7 @@ public FileDescriptorFactory(AssetManager assetManager) {
this.assetManager = assetManager;
}

@NonNull
@Override
public ModelLoader<Uri, ParcelFileDescriptor> build(MultiModelLoaderFactory multiFactory) {
return new AssetUriLoader<>(assetManager, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static class Fetcher<Data> implements DataFetcher<Data> {
}

@Override
public void loadData(Priority priority, DataCallback<? super Data> callback) {
public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super Data> callback) {
Data result = converter.convert(model);
callback.onDataReady(result);
}
Expand Down Expand Up @@ -90,6 +90,7 @@ public DataSource getDataSource() {
*/
public static class ByteBufferFactory implements ModelLoaderFactory<byte[], ByteBuffer> {

@NonNull
@Override
public ModelLoader<byte[], ByteBuffer> build(MultiModelLoaderFactory multiFactory) {
return new ByteArrayLoader<>(new Converter<ByteBuffer>() {
Expand All @@ -116,6 +117,7 @@ public void teardown() {
*/
public static class StreamFactory implements ModelLoaderFactory<byte[], InputStream> {

@NonNull
@Override
public ModelLoader<byte[], InputStream> build(MultiModelLoaderFactory multiFactory) {
return new ByteArrayLoader<>(new Converter<InputStream>() {
Expand Down
Loading

0 comments on commit e35a73b

Please sign in to comment.