1 17 18 package com.whirlycott.cache.policy; 19 20 import java.util.Comparator ; 21 import java.util.Map ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 import com.whirlycott.cache.Item; 27 import com.whirlycott.cache.Messages; 28 29 36 public class CountComparator implements Comparator { 37 38 private static final Log log = LogFactory.getLog(CountComparator.class); 39 40 43 public int compare(final Object o1, final Object o2) { 44 int retval = 0; 45 46 if (o1 instanceof Map.Entry && o2 instanceof Map.Entry ) { 47 48 final Item lh = (Item) ((Map.Entry )o1).getValue(); 49 final Item rh = (Item) ((Map.Entry )o2).getValue(); 50 51 if (lh != null && rh != null) { 52 53 if (lh.getCount() < rh.getCount()) 54 retval = -1; 55 56 if (lh.getCount() > rh.getCount()) 57 retval = 1; 58 59 } 60 61 } else { 62 log.warn(Messages.getString("CountComparator.values_were_not_map_entry")); } 64 return retval; 65 } 66 } 67 | Popular Tags |