MatchedShortComparator.java
package com.ziesemer.utils.web.compressFilter;
import java.util.Comparator;
import java.util.Map;
/**
* <p>{@link Comparator} that sorts based on the priorities stored by the passed-in {@link Map}.</p>
* @author Mark A. Ziesemer
* <a href="http://www.ziesemer.com"><www.ziesemer.com></a>
*/
class MatchedShortComparator implements Comparator<String>{
protected Map<String, Short> matches;
MatchedShortComparator(final Map<String, Short> matches){
this.matches = matches;
}
public int compare(final String o1, final String o2){
Short c1 = matches.get(o1);
if(c1 == null){
c1 = 0;
}
Short c2 = matches.get(o2);
if(c2 == null){
c2 = 0;
}
return c2.compareTo(c1);
}
}