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 37 public class UsedComparator implements Comparator { 38 39 private static final Log log = LogFactory.getLog( UsedComparator.class ); 40 41 44 public int compare(final Object o1, final Object o2) { 45 int retval = 0; 46 47 if ( o1 instanceof Map.Entry && o2 instanceof Map.Entry ) { 48 49 final Item lh = (Item) ((Map.Entry ) o1).getValue(); 50 final Item rh = (Item) ((Map.Entry ) o2).getValue(); 51 52 if ( lh != null && rh != null ) { 53 54 if ( lh.getUsed() < rh.getUsed() ) 55 retval = -1; 56 57 if ( lh.getUsed() > rh.getUsed() ) 58 retval = 1; 59 60 } 61 62 } else { 63 log.warn( Messages.getString("UsedComparator.values_were_not_map_entry") ); } 65 return retval; 66 } 67 } | Popular Tags |