1 37 38 package org.jfree.data; 39 40 import java.io.Serializable ; 41 42 47 public class XYDataItem implements Cloneable , Comparable , Serializable { 48 49 50 private Number x; 51 52 53 private Number y; 54 55 61 public XYDataItem(Number x, Number y) { 62 if (x == null) { 63 throw new IllegalArgumentException ("XYDataItem constructor : null x not allowed."); 64 } 65 this.x = x; 66 this.y = y; 67 } 68 69 75 public XYDataItem(double x, double y) { 76 this(new Double (x), new Double (y)); 77 } 78 79 84 public Number getX() { 85 return this.x; 86 } 87 88 93 public Number getY() { 94 return this.y; 95 } 96 97 104 public void setY(Number y) { 105 this.y = y; 106 } 107 108 119 public int compareTo(Object o1) { 120 121 int result; 122 123 if (o1 instanceof XYDataItem) { 126 XYDataItem dataItem = (XYDataItem) o1; 127 double compare = this.x.doubleValue() - dataItem.getX().doubleValue(); 128 if (compare > 0) { 129 result = 1; 130 } 131 else { 132 if (compare < 0) { 133 result = -1; 134 } 135 else { 136 result = 0; 137 } 138 } 139 } 140 141 else { 144 result = 1; 146 } 147 148 return result; 149 150 } 151 152 157 public Object clone() { 158 159 Object clone = null; 160 161 try { 162 clone = super.clone(); 163 } 164 catch (CloneNotSupportedException e) { System.err.println("XYDataItem.clone(): operation not supported."); 166 } 167 168 return clone; 169 170 } 171 172 } 173 | Popular Tags |