1 16 package org.apache.commons.collections.comparators; 17 18 import java.io.Serializable ; 19 import java.util.Comparator ; 20 21 33 public class ReverseComparator implements Comparator , Serializable { 34 35 36 private static final long serialVersionUID = 2858887242028539265L; 37 38 39 private Comparator comparator; 40 41 50 public ReverseComparator() { 51 this(null); 52 } 53 54 63 public ReverseComparator(Comparator comparator) { 64 if(comparator != null) { 65 this.comparator = comparator; 66 } else { 67 this.comparator = ComparableComparator.getInstance(); 68 } 69 } 70 71 79 public int compare(Object obj1, Object obj2) { 80 return comparator.compare(obj2, obj1); 81 } 82 83 91 public int hashCode() { 92 return "ReverseComparator".hashCode() ^ comparator.hashCode(); 93 } 94 95 111 public boolean equals(Object object) { 112 if(this == object) { 113 return true; 114 } else if(null == object) { 115 return false; 116 } else if(object.getClass().equals(this.getClass())) { 117 ReverseComparator thatrc = (ReverseComparator)object; 118 return comparator.equals(thatrc.comparator); 119 } else { 120 return false; 121 } 122 } 123 124 } 125 | Popular Tags |