1 16 17 package org.springframework.util.comparator; 18 19 import java.io.Serializable ; 20 import java.util.Comparator ; 21 22 28 public final class BooleanComparator implements Comparator , Serializable { 29 30 34 public static final BooleanComparator TRUE_LOW = new BooleanComparator(true); 35 36 40 public static final BooleanComparator TRUE_HIGH = new BooleanComparator(false); 41 42 43 private final boolean trueLow; 44 45 46 56 public BooleanComparator(boolean trueLow) { 57 this.trueLow = trueLow; 58 } 59 60 61 public int compare(Object o1, Object o2) { 62 boolean v1 = ((Boolean ) o1).booleanValue(); 63 boolean v2 = ((Boolean ) o2).booleanValue(); 64 return (v1 ^ v2) ? ((v1 ^ this.trueLow) ? 1 : -1) : 0; 65 } 66 67 public boolean equals(Object obj) { 68 if (this == obj) { 69 return true; 70 } 71 if (!(obj instanceof BooleanComparator)) { 72 return false; 73 } 74 return (this.trueLow == ((BooleanComparator) obj).trueLow); 75 } 76 77 public int hashCode() { 78 return (this.trueLow ? -1 : 1) * getClass().hashCode(); 79 } 80 81 public String toString() { 82 return "BooleanComparator: " + (this.trueLow ? "true low" : "true high"); 83 } 84 85 } 86 | Popular Tags |