1 16 17 package org.springframework.core.enums; 18 19 import java.io.Serializable ; 20 import java.util.Comparator ; 21 22 import org.springframework.util.comparator.CompoundComparator; 23 import org.springframework.util.comparator.NullSafeComparator; 24 25 43 public interface LabeledEnum extends Comparable , Serializable { 44 45 48 Class getType(); 49 50 54 Comparable getCode(); 55 56 59 String getLabel(); 60 61 62 64 67 Comparator CODE_ORDER = new Comparator () { 68 public int compare(Object o1, Object o2) { 69 Comparable c1 = ((LabeledEnum) o1).getCode(); 70 Comparable c2 = ((LabeledEnum) o2).getCode(); 71 return c1.compareTo(c2); 72 } 73 }; 74 75 78 Comparator LABEL_ORDER = new Comparator () { 79 public int compare(Object o1, Object o2) { 80 LabeledEnum e1 = (LabeledEnum) o1; 81 LabeledEnum e2 = (LabeledEnum) o2; 82 Comparator comp = new NullSafeComparator(String.CASE_INSENSITIVE_ORDER, true); 83 return comp.compare(e1.getLabel(), e2.getLabel()); 84 } 85 }; 86 87 91 Comparator DEFAULT_ORDER = 92 new CompoundComparator(new Comparator [] { LABEL_ORDER, CODE_ORDER }); 93 94 } 95 | Popular Tags |