forked from jasder/antlr
add some useful classes
This commit is contained in:
parent
b80b22e4fa
commit
808d23e6d1
|
@ -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<T> extends Hashtable<T, MutableInt> {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.antlr.v4.misc;
|
||||
|
||||
public class MutableInt extends Number implements Comparable<Number> {
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.antlr.v4.misc;
|
||||
|
||||
public class Pair<A,B> {
|
||||
public A a;
|
||||
public B b;
|
||||
|
||||
public Pair(A a, B b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue