List of usage examples for org.apache.commons.collections15 Bag clear
void clear();
From source file:de.dhke.projects.cutil.collections.BagUtil.java
public static <T> Bag<T> intersectBags(final Bag<T> b0, final Bag<T> b1, final Bag<T> targetBag) { targetBag.clear(); for (T item : b0) { final int count0 = b0.getCount(item); final int count1 = b1.getCount(item); if ((count0 > 0) && (count1 > 0)) { targetBag.add(item, Math.min(count0, count1)); }//from ww w.j a v a 2s.c o m } return targetBag; }
From source file:de.dhke.projects.cutil.collections.BagUtil.java
public static <T> Bag<T> unionBags(final Bag<T> b0, final Bag<T> b1, final Bag<T> targetBag) { targetBag.clear(); for (T item : b0) { final int count0 = b0.getCount(item); final int count1 = b1.getCount(item); targetBag.add(item, Math.max(count0, count1)); }/*w w w.j av a 2s . c om*/ for (T item : b1) { if (!b0.contains(item)) { final int count1 = b1.getCount(item); targetBag.add(item, count1); } } return targetBag; }