Пример #1
0
 /** Counts the object, increasing its total count by 1. */
 public int count(T obj) {
   int count = counts.get(obj);
   count++;
   counts.put(obj, count);
   sum++;
   return count;
 }
Пример #2
0
 /**
  * Adds the counts from the provided {@code Counter} to the current counts, adding new elements as
  * needed.
  */
 public void add(Counter<? extends T> counter) {
   for (Map.Entry<? extends T, Integer> e : counter) {
     T t = e.getKey();
     Integer cur = counts.get(t);
     counts.put(t, (cur == null) ? e.getValue() : cur + e.getValue());
   }
 }
Пример #3
0
 /**
  * Counts the object, increasing its total count by the specified positive amount.
  *
  * @param count a positive value for the number of times the object occurred
  * @throws IllegalArgumentException if {@code count} is not a positive value.
  */
 public int count(T obj, int count) {
   if (count < 1) throw new IllegalArgumentException("Count must be positive: " + count);
   int oldCount = counts.get(obj);
   int newCount = count + oldCount;
   counts.put(obj, newCount);
   sum += count;
   return newCount;
 }
Пример #4
0
 public boolean equals(Object o) {
   if (o instanceof Counter) {
     Counter<?> c = (Counter<?>) o;
     if (counts.size() != c.size() || sum != c.sum()) return false;
     for (Map.Entry<?, Integer> e : c) {
       int i = counts.get(e.getKey());
       if (i != e.getValue()) return false;
     }
     return true;
   }
   return false;
 }
Пример #5
0
 /**
  * Returns the index associated to the attribute name, or -1 if no attribute has the name.
  *
  * @param name The name to lookup
  * @return The index, or -1 if no attribute has the name
  */
 public int getAttributeIndex(String name) {
   return nameToIndex.get(name);
 }
Пример #6
0
 /** Returns the number of times the specified object has been seen by this counter. */
 public int getCount(T obj) {
   return counts.get(obj);
 }
Пример #7
0
 /**
  * Returns the value of the specified property.
  *
  * @param prop
  * @return value of property
  */
 public int getProperty(WindowProperty prop) {
   return properties.get(prop);
 }