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 35 public class AddedComparator implements Comparator { 36 37 private static final Log log = LogFactory.getLog(AddedComparator.class); 38 39 43 public int compare(Object o1, 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.getAdded() < rh.getAdded()) 54 retval = -1; 55 56 if (lh.getAdded() > rh.getAdded()) 57 retval = 1; 58 59 } 60 61 } else { 62 log.warn(Messages.getString("AddedComparator.values_were_not_map_entry")); } 64 return retval; 65 } 66 } 67 | Popular Tags |