Skip to content

Commit

Permalink
Add nullability annotations to signature package and its dependencies (
Browse files Browse the repository at this point in the history
…#2748)

Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored and sjudd committed Dec 23, 2017
1 parent 276d4ff commit c310780
Show file tree
Hide file tree
Showing 24 changed files with 55 additions and 39 deletions.
3 changes: 2 additions & 1 deletion library/src/main/java/com/bumptech/glide/load/Key.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load;

import android.support.annotation.NonNull;
import java.nio.charset.Charset;
import java.security.MessageDigest;

Expand All @@ -21,7 +22,7 @@ public interface Key {
* <p> Note - Using {@link java.security.MessageDigest#reset()} inside of this method will result
* in undefined behavior. </p>
*/
void updateDiskCacheKey(MessageDigest messageDigest);
void updateDiskCacheKey(@NonNull MessageDigest messageDigest);

@Override
boolean equals(Object o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
for (Transformation<T> transformation : transformations) {
transformation.updateDiskCacheKey(messageDigest);
}
Expand Down
3 changes: 2 additions & 1 deletion library/src/main/java/com/bumptech/glide/load/Options.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load;

import android.support.annotation.NonNull;
import android.support.v4.util.ArrayMap;
import android.support.v4.util.SimpleArrayMap;
import java.security.MessageDigest;
Expand Down Expand Up @@ -39,7 +40,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
for (int i = 0; i < values.size(); i++) {
Option<?> key = values.keyAt(i);
Object value = values.valueAt(i);
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.Key;
import java.security.MessageDigest;

Expand Down Expand Up @@ -45,7 +46,7 @@ public String toString() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
sourceKey.updateDiskCacheKey(messageDigest);
signature.updateDiskCacheKey(messageDigest);
}
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.Key;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.Transformation;
Expand Down Expand Up @@ -89,7 +90,7 @@ public String toString() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
throw new UnsupportedOperationException();
}
}
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.Key;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.Transformation;
Expand Down Expand Up @@ -72,7 +73,7 @@ public int hashCode() {

// TODO: Include relevant options?
@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
byte[] dimensions = arrayPool.getExact(8, byte[].class);
ByteBuffer.wrap(dimensions).putInt(width).putInt(height).array();
signature.updateDiskCacheKey(messageDigest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
import com.bumptech.glide.load.Key;
Expand Down Expand Up @@ -165,7 +166,7 @@ private static final class UniqueKey implements Key {
UniqueKey() { }

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
throw new UnsupportedOperationException();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bumptech.glide.load.model;

import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import com.bumptech.glide.load.Key;
Expand Down Expand Up @@ -120,7 +121,7 @@ public String toString() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(getCacheKeyBytes());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Resource<T> transform(@NonNull Context context, @NonNull Resource<T> reso
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
// Do nothing.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
Expand Down Expand Up @@ -90,7 +91,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
wrapped.updateDiskCacheKey(messageDigest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
wrapped.updateDiskCacheKey(messageDigest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);

byte[] radiusData = ByteBuffer.allocate(4).putInt(roundingRadius).array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
wrapped.updateDiskCacheKey(messageDigest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import com.bumptech.glide.load.Key;
import java.util.UUID;
Expand All @@ -20,7 +21,8 @@ public final class ApplicationVersionSignature {
* Returns the signature {@link com.bumptech.glide.load.Key} for version code of the Application
* of the given Context.
*/
public static Key obtain(Context context) {
@NonNull
public static Key obtain(@NonNull Context context) {
String packageName = context.getPackageName();
Key result = PACKAGE_NAME_TO_KEY.get(packageName);
if (result == null) {
Expand All @@ -40,7 +42,8 @@ static void reset() {
PACKAGE_NAME_TO_KEY.clear();
}

private static Key obtainVersionSignature(Context context) {
@NonNull
private static Key obtainVersionSignature(@NonNull Context context) {
PackageInfo pInfo = null;
try {
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.signature;

import android.support.annotation.NonNull;
import com.bumptech.glide.load.Key;
import java.security.MessageDigest;

Expand All @@ -9,6 +10,7 @@
public final class EmptySignature implements Key {
private static final EmptySignature EMPTY_KEY = new EmptySignature();

@NonNull
public static EmptySignature obtain() {
return EMPTY_KEY;
}
Expand All @@ -23,7 +25,7 @@ public String toString() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
// Do nothing.
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.bumptech.glide.signature;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.util.Util;
import java.nio.ByteBuffer;
import java.security.MessageDigest;

Expand All @@ -10,7 +11,7 @@
* media store files like edits, rotations, and temporary file replacement.
*/
public class MediaStoreSignature implements Key {
private final String mimeType;
@NonNull private final String mimeType;
private final long dateModified;
private final int orientation;

Expand All @@ -26,8 +27,8 @@ public class MediaStoreSignature implements Key {
* @param orientation The orientation of the media store media. Ok to default to 0. See {@link
* android.provider.MediaStore.Images.ImageColumns#ORIENTATION}.
*/
public MediaStoreSignature(String mimeType, long dateModified, int orientation) {
this.mimeType = mimeType;
public MediaStoreSignature(@Nullable String mimeType, long dateModified, int orientation) {
this.mimeType = mimeType == null ? "" : mimeType;
this.dateModified = dateModified;
this.orientation = orientation;
}
Expand All @@ -50,22 +51,22 @@ public boolean equals(Object o) {
if (orientation != that.orientation) {
return false;
}
if (!Util.bothNullOrEqual(mimeType, that.mimeType)) {
if (!mimeType.equals(that.mimeType)) {
return false;
}
return true;
}

@Override
public int hashCode() {
int result = mimeType != null ? mimeType.hashCode() : 0;
int result = mimeType.hashCode();
result = 31 * result + (int) (dateModified ^ (dateModified >>> 32));
result = 31 * result + orientation;
return result;
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
byte[] data = ByteBuffer.allocate(12).putLong(dateModified).putInt(orientation).array();
messageDigest.update(data);
messageDigest.update(mimeType.getBytes(CHARSET));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.signature;

import android.support.annotation.NonNull;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.util.Preconditions;
import java.security.MessageDigest;
Expand All @@ -16,7 +17,7 @@
public final class ObjectKey implements Key {
private final Object object;

public ObjectKey(Object object) {
public ObjectKey(@NonNull Object object) {
this.object = Preconditions.checkNotNull(object);
}

Expand All @@ -42,7 +43,7 @@ public int hashCode() {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(object.toString().getBytes(CHARSET));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private Resource<?> getResource(int size) {

private static class MockKey implements Key {
@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(toString().getBytes(CHARSET));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertTrue;

import android.support.annotation.NonNull;
import com.bumptech.glide.load.Key;
import java.security.MessageDigest;
import java.util.regex.Matcher;
Expand All @@ -19,7 +20,7 @@ public class SafeKeyGeneratorTest {
private int nextId;

@Before
public void setUp() throws Exception {
public void setUp() {
nextId = 0;
keyGenerator = new SafeKeyGenerator();
}
Expand Down Expand Up @@ -50,7 +51,7 @@ private static final class MockKey implements Key {
}

@Override
public void updateDiskCacheKey(MessageDigest messageDigest) {
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(id.getBytes(CHARSET));
}
}
Expand Down
Loading

0 comments on commit c310780

Please sign in to comment.