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

com.bumptech.glide.load.engine.prefill.PreFillQueue 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.engine.prefill;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

final class PreFillQueue {

  private final Map bitmapsPerType;
  private final List keyList;
  private int bitmapsRemaining;
  private int keyIndex;

  public PreFillQueue(Map bitmapsPerType) {
    this.bitmapsPerType = bitmapsPerType;
    // We don't particularly care about the initial order.
    keyList = new ArrayList<>(bitmapsPerType.keySet());

    for (Integer count : bitmapsPerType.values()) {
      bitmapsRemaining += count;
    }
  }

  public PreFillType remove() {
    PreFillType result = keyList.get(keyIndex);

    Integer countForResult = bitmapsPerType.get(result);
    if (countForResult == 1) {
      bitmapsPerType.remove(result);
      keyList.remove(keyIndex);
    } else {
      bitmapsPerType.put(result, countForResult - 1);
    }
    bitmapsRemaining--;

    // Avoid divide by 0.
    keyIndex = keyList.isEmpty() ? 0 : (keyIndex + 1) % keyList.size();

    return result;
  }

  public int getSize() {
    return bitmapsRemaining;
  }

  public boolean isEmpty() {
    return bitmapsRemaining == 0;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy