@@ -0,0 +1,2214 @@
+/*%0A * FindBugs - Find Bugs in Java programs%0A * Copyright (C) 2003-2008 University of Maryland%0A * %0A * This library is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU Lesser General Public%0A * License as published by the Free Software Foundation; either%0A * version 2.1 of the License, or (at your option) any later version.%0A * %0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A * Lesser General Public License for more details.%0A * %0A * You should have received a copy of the GNU Lesser General Public%0A * License along with this library; if not, write to the Free Software%0A * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA%0A */%0A%0Apackage edu.umd.cs.findbugs.util;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A%0A/**%0A * @author pugh%0A */%0Apublic abstract class MergeMap%3CK, V%3E %7B%0A%0A%09static class MinMap%3CK, V extends Comparable%3C? super V%3E%3E extends MergeMap%3CK, V%3E %7B%0A%09%09@Override%0A%09%09protected V mergeValues(V oldValue, V newValue) %7B%0A%0A%09%09%09if (oldValue.compareTo(newValue) %3E 0)%0A%09%09%09%09return newValue;%0A%09%09%09return oldValue;%0A%09%09%7D%0A%09%7D%0A%0A%09static class MaxMap%3CK, V extends Comparable%3C? super V%3E%3E extends MergeMap%3CK, V%3E %7B%0A%0A%09%09@Override%0A%09%09protected V mergeValues(V oldValue, V newValue) %7B%0A%0A%09%09%09if (oldValue.compareTo(newValue) %3C 0)%0A%09%09%09%09return newValue;%0A%09%09%09return oldValue;%0A%09%09%7D%0A%09%7D%0A%0A%09final Map%3CK, V%3E map;%0A%0A%09protected abstract V mergeValues(V oldValue, V newValue);%0A%0A%09MergeMap() %7B%0A%09%09map = new HashMap%3CK, V%3E();%0A%09%7D%0A%0A%09MergeMap(Map%3CK, V%3E map) %7B%0A%09%09this.map = map;%0A%09%7D%0A%0A%09V put(K k, V v) %7B%0A%09%09V currentValue = map.get(k);%0A%09%09if (currentValue == null) %7B%0A%09%09%09map.put(k, v);%0A%09%09%09return v;%0A%09%09%7D%0A%09%09V result = mergeValues(currentValue, v);%0A%09%09if (currentValue != result)%0A%09%09%09map.put(k, v);%0A%0A%09%09return result;%0A%09%7D%0A%0A%09V get(K k) %7B%0A%09%09return map.get(k);%0A%09%7D%0A%0A%09Set%3CMap.Entry%3CK, V%3E%3E entrySet() %7B%0A%09%09return map.entrySet();%0A%09%7D%0A%0A%09public static void main(String args%5B%5D) %7B%0A%0A%09%09MergeMap%3CString, Integer%3E m = new MaxMap%3CString, Integer%3E();%0A%0A%09%09m.put(%22a%22, 1);%0A%09%09m.put(%22a%22, 2);%0A%09%09m.put(%22b%22, 2);%0A%09%09m.put(%22b%22, 1);%0A%09%09System.out.println(m.entrySet());%0A%0A%09%7D%0A%0A%7D%0A

Add new utility class