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

de.gwdg.metadataqa.marc.utils.Counter Maven / Gradle / Ivy

package de.gwdg.metadataqa.marc.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Counter {
  private Map counter = new HashMap<>();

  public void count(T key) {
    add(key, 1);
  }

  public void add(T key, int i) {
    counter.computeIfAbsent(key, s -> 0);
    counter.put(key, counter.get(key) + i);
  }

  public int get(T key) {
    return counter.getOrDefault(key, null);
  }

  public Set keys() {
    return counter.keySet();
  }

  public Set> entrySet() {
    return counter.entrySet();
  }

  public Map getMap() {
    return counter;
  }

  public int total() {
    var total = 0;
    for (int value : counter.values())
      total += value;
    return total;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy