1 42 43 package org.jfree.data; 44 45 import java.io.Serializable ; 46 47 import org.jfree.util.ObjectUtilities; 48 49 55 public class ComparableObjectItem implements Cloneable , Comparable , 56 Serializable { 57 58 private static final long serialVersionUID = 2751513470325494890L; 59 60 61 private Comparable x; 62 63 64 private Object obj; 65 66 72 public ComparableObjectItem(Comparable x, Object y) { 73 if (x == null) { 74 throw new IllegalArgumentException ("Null 'x' argument."); 75 } 76 this.x = x; 77 this.obj = y; 78 } 79 80 85 protected Comparable getComparable() { 86 return this.x; 87 } 88 89 94 protected Object getObject() { 95 return this.obj; 96 } 97 98 104 protected void setObject(Object y) { 105 this.obj = y; 106 } 107 108 120 public int compareTo(Object o1) { 121 122 int result; 123 124 if (o1 instanceof ComparableObjectItem) { 127 ComparableObjectItem that = (ComparableObjectItem) o1; 128 return this.x.compareTo(that.x); 129 } 130 131 else { 134 result = 1; 136 } 137 138 return result; 139 140 } 141 142 150 public Object clone() throws CloneNotSupportedException { 151 return super.clone(); 152 } 153 154 162 public boolean equals(Object obj) { 163 if (obj == this) { 164 return true; 165 } 166 if (!(obj instanceof ComparableObjectItem)) { 167 return false; 168 } 169 ComparableObjectItem that = (ComparableObjectItem) obj; 170 if (!this.x.equals(that.x)) { 171 return false; 172 } 173 if (!ObjectUtilities.equal(this.obj, that.obj)) { 174 return false; 175 } 176 return true; 177 } 178 179 184 public int hashCode() { 185 int result; 186 result = this.x.hashCode(); 187 result = 29 * result + (this.obj != null ? this.obj.hashCode() : 0); 188 return result; 189 } 190 191 } 192 | Popular Tags |