diff --git a/tool/src/org/antlr/v4/misc/FrequencySet.java b/tool/src/org/antlr/v4/misc/FrequencySet.java new file mode 100644 index 000000000..2923c7ae4 --- /dev/null +++ b/tool/src/org/antlr/v4/misc/FrequencySet.java @@ -0,0 +1,22 @@ +package org.antlr.v4.misc; + +import java.util.Hashtable; + +/** Count how many of each key we have; not thread safe */ +public class FrequencySet extends Hashtable { + public int count(T key) { + MutableInt value = get(key); + if (value == null) return 0; + return value.v; + } + public void add(T key) { + MutableInt value = get(key); + if (value == null) { + value = new MutableInt(1); + put(key, value); + } + else { + value.v++; + } + } +} diff --git a/tool/src/org/antlr/v4/misc/MutableInt.java b/tool/src/org/antlr/v4/misc/MutableInt.java new file mode 100644 index 000000000..9f6fb9409 --- /dev/null +++ b/tool/src/org/antlr/v4/misc/MutableInt.java @@ -0,0 +1,17 @@ +package org.antlr.v4.misc; + +public class MutableInt extends Number implements Comparable { + public int v; + + public MutableInt(int v) { this.v = v; } + @Override public int compareTo(Number o) { return v; } + @Override public int intValue() { return v; } + @Override public long longValue() { return v; } + @Override public float floatValue() { return v; } + @Override public double doubleValue() { return v; } + + @Override + public String toString() { + return String.valueOf(v); + } +} diff --git a/tool/src/org/antlr/v4/misc/Pair.java b/tool/src/org/antlr/v4/misc/Pair.java new file mode 100644 index 000000000..542c5b40e --- /dev/null +++ b/tool/src/org/antlr/v4/misc/Pair.java @@ -0,0 +1,11 @@ +package org.antlr.v4.misc; + +public class Pair { + public A a; + public B b; + + public Pair(A a, B b) { + this.a = a; + this.b = b; + } +}