T
- The type of the option (Integer
, Bitmap.CompressFormat
etc.), must implement equals(Object)
and
hashCode()
.public final class Option<T> extends Object
DiskCacheStrategy.RESOURCE
.
Implementations must either be unique (usually declared as static final variables), or
implement equals(Object)
and hashCode()
.
Implementations can implement update(Object, MessageDigest)
to make sure that
the disk cache key includes the specific option set.
Modifier and Type | Class and Description |
---|---|
static interface |
Option.CacheKeyUpdater<T>
An interface that updates a
MessageDigest with the given value as part of a process to
generate a disk cache key. |
Modifier and Type | Method and Description |
---|---|
static <T> Option<T> |
disk(String key,
Option.CacheKeyUpdater<T> cacheKeyUpdater)
Returns a new
Option that uses the given Option.CacheKeyUpdater to update disk cache keys. |
static <T> Option<T> |
disk(String key,
T defaultValue,
Option.CacheKeyUpdater<T> cacheKeyUpdater)
Returns a new
Option that uses the given Option.CacheKeyUpdater to update disk cache keys and provides
the given value as the default value. |
boolean |
equals(Object o) |
T |
getDefaultValue()
Returns a reasonable default to use if no other value is set, or
null . |
int |
hashCode() |
static <T> Option<T> |
memory(String key)
Returns a new
Option that does not affect disk cache keys with a null default
value. |
static <T> Option<T> |
memory(String key,
T defaultValue)
Returns a new
Option that does not affect disk cache keys with the given value as the
default value. |
String |
toString() |
void |
update(T value,
MessageDigest messageDigest)
Updates the given
MessageDigest used to construct a cache key with the given
value using the Option.CacheKeyUpdater optionally provided in
the constructor. |
@NonNull public static <T> Option<T> memory(@NonNull String key)
Option
that does not affect disk cache keys with a null
default
value.key
- A unique package prefixed String
that identifies this option (must be
stable across builds, so Class.getName()
should not be used).@NonNull public static <T> Option<T> memory(@NonNull String key, @NonNull T defaultValue)
Option
that does not affect disk cache keys with the given value as the
default value.key
- A unique package prefixed String
that identifies this option (must be
stable across builds, so Class.getName()
should not be used).@NonNull public static <T> Option<T> disk(@NonNull String key, @NonNull Option.CacheKeyUpdater<T> cacheKeyUpdater)
Option
that uses the given Option.CacheKeyUpdater
to update disk cache keys.key
- A unique package prefixed String
that identifies this option (must be
stable across builds, so Class.getName()
should not be used).@NonNull public static <T> Option<T> disk(@NonNull String key, @Nullable T defaultValue, @NonNull Option.CacheKeyUpdater<T> cacheKeyUpdater)
Option
that uses the given Option.CacheKeyUpdater
to update disk cache keys and provides
the given value as the default value.key
- A unique package prefixed String
that identifies this option (must be
stable across builds, so Class.getName()
should not be used).@Nullable public T getDefaultValue()
null
.public void update(@NonNull T value, @NonNull MessageDigest messageDigest)
MessageDigest
used to construct a cache key with the given
value using the Option.CacheKeyUpdater
optionally provided in
the constructor.