Class Option<T>

  • Type Parameters:
    T - The type of the option (Integer, Bitmap.CompressFormat etc.), must implement equals(Object) and hashCode().

    public final class Option<T>
    extends java.lang.Object
    Defines available component (decoders, encoders, model loaders etc.) options with optional default values and the ability to affect the resource disk cache key used by 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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class 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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> Option<T> disk​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String key)
      Returns a new Option that does not affect disk cache keys with a null default value.
      static <T> Option<T> memory​(java.lang.String key, T defaultValue)
      Returns a new Option that does not affect disk cache keys with the given value as the default value.
      java.lang.String toString()  
      void update​(T value, java.security.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.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • memory

        @NonNull
        public static <T> Option<T> memory​(@NonNull
                                           java.lang.String key)
        Returns a new Option that does not affect disk cache keys with a null default value.
        Parameters:
        key - A unique package prefixed String that identifies this option (must be stable across builds, so Class.getName() should not be used).
      • memory

        @NonNull
        public static <T> Option<T> memory​(@NonNull
                                           java.lang.String key,
                                           @NonNull
                                           T defaultValue)
        Returns a new Option that does not affect disk cache keys with the given value as the default value.
        Parameters:
        key - A unique package prefixed String that identifies this option (must be stable across builds, so Class.getName() should not be used).
      • disk

        @NonNull
        public static <T> Option<T> disk​(@NonNull
                                         java.lang.String key,
                                         @NonNull
                                         Option.CacheKeyUpdater<T> cacheKeyUpdater)
        Returns a new Option that uses the given Option.CacheKeyUpdater to update disk cache keys.
        Parameters:
        key - A unique package prefixed String that identifies this option (must be stable across builds, so Class.getName() should not be used).
      • disk

        @NonNull
        public static <T> Option<T> disk​(@NonNull
                                         java.lang.String key,
                                         @Nullable
                                         T defaultValue,
                                         @NonNull
                                         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.
        Parameters:
        key - A unique package prefixed String that identifies this option (must be stable across builds, so Class.getName() should not be used).
      • getDefaultValue

        @Nullable
        public T getDefaultValue()
        Returns a reasonable default to use if no other value is set, or null.
      • update

        public void update​(@NonNull
                           T value,
                           @NonNull
                           java.security.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.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object