1 47 48 package org.jfree.data.time; 49 50 import java.io.Serializable ; 51 import java.util.Calendar ; 52 import java.util.Date ; 53 54 59 public class FixedMillisecond extends RegularTimePeriod 60 implements Serializable { 61 62 63 private static final long serialVersionUID = 7867521484545646931L; 64 65 66 private Date time; 67 68 71 public FixedMillisecond() { 72 this(new Date ()); 73 } 74 75 80 public FixedMillisecond(long millisecond) { 81 this(new Date (millisecond)); 82 } 83 84 89 public FixedMillisecond(Date time) { 90 this.time = time; 91 } 92 93 98 public Date getTime() { 99 return this.time; 100 } 101 102 107 public RegularTimePeriod previous() { 108 RegularTimePeriod result = null; 109 long t = this.time.getTime(); 110 if (t != Long.MIN_VALUE) { 111 result = new FixedMillisecond(t - 1); 112 } 113 return result; 114 } 115 116 121 public RegularTimePeriod next() { 122 RegularTimePeriod result = null; 123 long t = this.time.getTime(); 124 if (t != Long.MAX_VALUE) { 125 result = new FixedMillisecond(t + 1); 126 } 127 return result; 128 } 129 130 137 public boolean equals(Object object) { 138 if (object instanceof FixedMillisecond) { 139 FixedMillisecond m = (FixedMillisecond) object; 140 return this.time.equals(m.getTime()); 141 } 142 else { 143 return false; 144 } 145 146 } 147 148 153 public int hashCode() { 154 return this.time.hashCode(); 155 } 156 157 166 public int compareTo(Object o1) { 167 168 int result; 169 long difference; 170 171 if (o1 instanceof FixedMillisecond) { 174 FixedMillisecond t1 = (FixedMillisecond) o1; 175 difference = this.time.getTime() - t1.time.getTime(); 176 if (difference > 0) { 177 result = 1; 178 } 179 else { 180 if (difference < 0) { 181 result = -1; 182 } 183 else { 184 result = 0; 185 } 186 } 187 } 188 189 else if (o1 instanceof RegularTimePeriod) { 192 result = 0; 194 } 195 196 else { 199 result = 1; 201 } 202 203 return result; 204 205 } 206 207 212 public long getFirstMillisecond() { 213 return this.time.getTime(); 214 } 215 216 217 224 public long getFirstMillisecond(Calendar calendar) { 225 return this.time.getTime(); 226 } 227 228 233 public long getLastMillisecond() { 234 return this.time.getTime(); 235 } 236 237 244 public long getLastMillisecond(Calendar calendar) { 245 return this.time.getTime(); 246 } 247 248 253 public long getMiddleMillisecond() { 254 return this.time.getTime(); 255 } 256 257 264 public long getMiddleMillisecond(Calendar calendar) { 265 return this.time.getTime(); 266 } 267 268 273 public long getSerialIndex() { 274 return this.time.getTime(); 275 } 276 277 } 278 | Popular Tags |