All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bumptech.glide.load.Options Maven / Gradle / Ivy

Go to download

A fast and efficient image loading library for Android focused on smooth scrolling.

There is a newer version: 5.0.0-rc01
Show newest version
package com.bumptech.glide.load;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArrayMap;
import androidx.collection.SimpleArrayMap;
import com.bumptech.glide.util.CachedHashCodeArrayMap;
import java.security.MessageDigest;

/** A set of {@link Option Options} to apply to in memory and disk cache keys. */
public final class Options implements Key {
  private final ArrayMap, Object> values = new CachedHashCodeArrayMap<>();

  public void putAll(@NonNull Options other) {
    values.putAll((SimpleArrayMap, Object>) other.values);
  }

  @NonNull
  public  Options set(@NonNull Option option, @NonNull T value) {
    values.put(option, value);
    return this;
  }

  @Nullable
  @SuppressWarnings("unchecked")
  public  T get(@NonNull Option option) {
    return values.containsKey(option) ? (T) values.get(option) : option.getDefaultValue();
  }

  @Override
  public boolean equals(Object o) {
    if (o instanceof Options) {
      Options other = (Options) o;
      return values.equals(other.values);
    }
    return false;
  }

  @Override
  public int hashCode() {
    return values.hashCode();
  }

  @Override
  public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
    for (int i = 0; i < values.size(); i++) {
      Option key = values.keyAt(i);
      Object value = values.valueAt(i);
      updateDiskCacheKey(key, value, messageDigest);
    }
  }

  @Override
  public String toString() {
    return "Options{" + "values=" + values + '}';
  }

  @SuppressWarnings("unchecked")
  private static  void updateDiskCacheKey(
      @NonNull Option option, @NonNull Object value, @NonNull MessageDigest md) {
    option.update((T) value, md);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy