1 46 47 package org.jfree.data.time; 48 49 import java.io.Serializable ; 50 51 76 public class TimeSeriesDataItem implements Cloneable , Comparable , Serializable { 77 78 79 private static final long serialVersionUID = -2235346966016401302L; 80 81 82 private RegularTimePeriod period; 83 84 85 private Number value; 86 87 93 public TimeSeriesDataItem(RegularTimePeriod period, Number value) { 94 if (period == null) { 95 throw new IllegalArgumentException ("Null 'period' argument."); 96 } 97 this.period = period; 98 this.value = value; 99 } 100 101 107 public TimeSeriesDataItem(RegularTimePeriod period, double value) { 108 this(period, new Double (value)); 109 } 110 111 116 public RegularTimePeriod getPeriod() { 117 return this.period; 118 } 119 120 125 public Number getValue() { 126 return this.value; 127 } 128 129 134 public void setValue(Number value) { 135 this.value = value; 136 } 137 138 145 public boolean equals(Object o) { 146 if (this == o) { 147 return true; 148 } 149 if (!(o instanceof TimeSeriesDataItem)) { 150 return false; 151 } 152 TimeSeriesDataItem timeSeriesDataItem = (TimeSeriesDataItem) o; 153 if (this.period != null) { 154 if (!this.period.equals(timeSeriesDataItem.period)) { 155 return false; 156 } 157 } 158 else if (timeSeriesDataItem.period != null) { 159 return false; 160 } 161 162 if (this.value != null) { 163 if (!this.value.equals(timeSeriesDataItem.value)) { 164 return false; 165 } 166 } 167 else if (timeSeriesDataItem.value != null) { 168 return false; 169 } 170 171 return true; 172 } 173 174 179 public int hashCode() { 180 int result; 181 result = (this.period != null ? this.period.hashCode() : 0); 182 result = 29 * result + (this.value != null ? this.value.hashCode() : 0); 183 return result; 184 } 185 186 198 public int compareTo(Object o1) { 199 200 int result; 201 202 if (o1 instanceof TimeSeriesDataItem) { 205 TimeSeriesDataItem datapair = (TimeSeriesDataItem) o1; 206 result = getPeriod().compareTo(datapair.getPeriod()); 207 } 208 209 else { 212 result = 1; 214 } 215 216 return result; 217 218 } 219 220 226 public Object clone() { 227 Object clone = null; 228 try { 229 clone = super.clone(); 230 } 231 catch (CloneNotSupportedException e) { e.printStackTrace(); 233 } 234 return clone; 235 } 236 237 } 238 | Popular Tags |