Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed Mar 6, 2018
1 parent 413cdff commit 6ce1fa9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ public void invalidate(@NonNull Object data) {
public <T> void registerDataType(@NonNull Class<T> dataClass, @NonNull DataDescriptorFactory<T> descriptorFactory,
@NonNull BitmapLoader<T> bitmapLoader) {
String dataClassName = dataClass.getName();
mDescriptorFactories.put(dataClassName, (DataDescriptorFactory<Object>) descriptorFactory);
mBitmapLoaders.put(dataClassName, (BitmapLoader<Object>) bitmapLoader);
mDescriptorFactories
.put(dataClassName, (DataDescriptorFactory<Object>) InternalUtils.requireNonNull(descriptorFactory));
mBitmapLoaders.put(dataClassName, (BitmapLoader<Object>) InternalUtils.requireNonNull(bitmapLoader));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import android.content.Context;
import android.net.Uri;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

Expand Down Expand Up @@ -59,7 +60,7 @@ public ImageLoaderBuilder memoryCache() {
* Memory cache with specified maximum size
*/
@NonNull
public ImageLoaderBuilder memoryCache(int maxSize) {
public ImageLoaderBuilder memoryCache(@IntRange(from = 0) int maxSize) {
mMemoryCache = new MemoryImageCache(maxSize);
return this;
}
Expand Down Expand Up @@ -88,7 +89,7 @@ public ImageLoaderBuilder storageCache() {
* located in subdirectory of {@link Context#getExternalCacheDir}
*/
@NonNull
public ImageLoaderBuilder storageCache(long maxSize) {
public ImageLoaderBuilder storageCache(@IntRange(from = 0L) long maxSize) {
mStorageCache = new StorageImageCache(mContext, maxSize);
return this;
}
Expand All @@ -100,7 +101,7 @@ public ImageLoaderBuilder storageCache(long maxSize) {
* @see CompressMode
*/
@NonNull
public ImageLoaderBuilder storageCache(@NonNull CompressMode compressMode, long maxSize) {
public ImageLoaderBuilder storageCache(@NonNull CompressMode compressMode, @IntRange(from = 0L) long maxSize) {
mStorageCache = new StorageImageCache(mContext, compressMode, maxSize);
return this;
}
Expand All @@ -118,7 +119,7 @@ public ImageLoaderBuilder storageCache(@NonNull File directory) {
* Storage cache with specified directory and maximum size
*/
@NonNull
public ImageLoaderBuilder storageCache(@NonNull File directory, long maxSize) {
public ImageLoaderBuilder storageCache(@NonNull File directory, @IntRange(from = 0L) long maxSize) {
mStorageCache = new StorageImageCache(directory, maxSize);
return this;
}
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/com/budiyev/android/imageloader/ImageRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ public ImageRequest<T> errorDrawable(@DrawableRes int resId) {
*/
@NonNull
public ImageRequest<T> transform(@NonNull BitmapTransformation transformation) {
checkNonNull(transformation);
transformations().add(transformation);
transformations().add(InternalUtils.requireNonNull(transformation));
return this;
}

Expand All @@ -196,8 +195,7 @@ public ImageRequest<T> transform(@NonNull BitmapTransformation transformation) {
*/
@NonNull
public ImageRequest<T> transform(@NonNull Collection<BitmapTransformation> transformations) {
checkNonNull(transformations);
transformations().addAll(transformations);
transformations().addAll(InternalUtils.requireNonNull(transformations));
return this;
}

Expand All @@ -209,8 +207,7 @@ public ImageRequest<T> transform(@NonNull Collection<BitmapTransformation> trans
*/
@NonNull
public ImageRequest<T> transform(@NonNull BitmapTransformation... transformations) {
checkNonNull(transformations);
Collections.addAll(transformations(), transformations);
Collections.addAll(transformations(), InternalUtils.requireNonNull(transformations));
return this;
}

Expand Down Expand Up @@ -445,10 +442,4 @@ private void checkSize(int width, int height) {
throw new IllegalArgumentException("Width and height should be greater than zero");
}
}

private void checkNonNull(Object value) {
if (value == null) {
throw new NullPointerException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,12 @@ public static Bitmap rotateAndRecycle(@NonNull Bitmap bitmap, int rotation) {
}
return rotated;
}

@NonNull
public static <T> T requireNonNull(@Nullable T value) {
if (value == null) {
throw new NullPointerException();
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public MemoryImageCache() {
}

public MemoryImageCache(int maxSize) {
if (maxSize < 0) {
throw new IllegalArgumentException("Cache size should be greater than or equal to zero");
}
mImages = new LinkedHashMap<>(0, 0.75f, true);
mLock = new ReentrantLock();
mMaxSize = maxSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ public StorageImageCache(@NonNull File directory, long maxSize) {
}

public StorageImageCache(@NonNull File directory, @NonNull CompressMode compressMode, long maxSize) {
mDirectory = directory;
mCompressMode = compressMode;
mDirectory = InternalUtils.requireNonNull(directory);
mCompressMode = InternalUtils.requireNonNull(compressMode);
if (maxSize < 0L) {
throw new IllegalArgumentException("Cache size should be greater than or equal to zero");
}
mMaxSize = maxSize;
}

Expand Down

0 comments on commit 6ce1fa9

Please sign in to comment.