1 44 45 package org.jfree.data.xy; 46 47 import java.io.Serializable ; 48 49 import org.jfree.util.ObjectUtilities; 50 51 54 public class XYDataItem implements Cloneable , Comparable , Serializable { 55 56 private static final long serialVersionUID = 2751513470325494890L; 57 58 59 private Number x; 60 61 62 private Number y; 63 64 70 public XYDataItem(Number x, Number y) { 71 if (x == null) { 72 throw new IllegalArgumentException ("Null 'x' argument."); 73 } 74 this.x = x; 75 this.y = y; 76 } 77 78 84 public XYDataItem(double x, double y) { 85 this(new Double (x), new Double (y)); 86 } 87 88 93 public Number getX() { 94 return this.x; 95 } 96 97 102 public Number getY() { 103 return this.y; 104 } 105 106 112 public void setY(double y) { 113 setY(new Double (y)); 114 } 115 116 122 public void setY(Number y) { 123 this.y = y; 124 } 125 126 138 public int compareTo(Object o1) { 139 140 int result; 141 142 if (o1 instanceof XYDataItem) { 145 XYDataItem dataItem = (XYDataItem) o1; 146 double compare = this.x.doubleValue() 147 - dataItem.getX().doubleValue(); 148 if (compare > 0.0) { 149 result = 1; 150 } 151 else { 152 if (compare < 0.0) { 153 result = -1; 154 } 155 else { 156 result = 0; 157 } 158 } 159 } 160 161 else { 164 result = 1; 166 } 167 168 return result; 169 170 } 171 172 180 public Object clone() throws CloneNotSupportedException { 181 return super.clone(); 182 } 183 184 192 public boolean equals(Object obj) { 193 if (obj == this) { 194 return true; 195 } 196 if (!(obj instanceof XYDataItem)) { 197 return false; 198 } 199 XYDataItem that = (XYDataItem) obj; 200 if (!this.x.equals(that.x)) { 201 return false; 202 } 203 if (!ObjectUtilities.equal(this.y, that.y)) { 204 return false; 205 } 206 return true; 207 } 208 209 214 public int hashCode() { 215 int result; 216 result = this.x.hashCode(); 217 result = 29 * result + (this.y != null ? this.y.hashCode() : 0); 218 return result; 219 } 220 221 } 222 | Popular Tags |