1.getCardinalityMap(): 获取统计出现次数的map
public static Map getCardinalityMap(final Collection coll) {
Map count = new HashMap();
for (Iterator it = coll.iterator(); it.hasNext(); ) {
Object obj = it.next();
Integer c = (Integer) (count.get(obj));
if (c == null) {
count.put(obj, INTEGER_ONE);
} else {
count.put(obj, new Integer(c.intValue() + 1));
}
}
return count;
2.getFreq(): 通过key拿到value(私有方法)
private static final int getFreq(final Object obj, final Map freqMap) {
Integer count = (Integer) freqMap.get(obj);
if (count != null) {
return count.intValue();
}
return 0;
}
3.union(): 合集
public static Collection union(final Collection a, final Collection b) {
ArrayList list = new ArrayList(