01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package mx4j.tools.stats;
10:
11: import java.util.Date;
12:
13: /**
14: * Class PointTime encapsulates the time and order of a value. We want to
15: * index the recorded time but in the event of a repeated time, it will
16: * have another index which should be unique. The class is Comparable
17: * and the order is given first by the date and if those are equals by
18: * the index
19: *
20: * @version $Revision: 1.3 $
21: */
22: public class PointTime implements Comparable {
23: private Date date;
24: private long index;
25:
26: public PointTime(Date date, long index) {
27: this .date = date;
28: this .index = index;
29: }
30:
31: public Date getDate() {
32: return date;
33: }
34:
35: public long getIndex() {
36: return index;
37: }
38:
39: public int compareTo(Object o) {
40: PointTime p = (PointTime) o;
41: if (date.equals(p.date)) {
42: return (int) (index - p.index);
43: } else {
44: return date.compareTo(p.date);
45: }
46: }
47:
48: public boolean equals(Object o) {
49: if (o == null) {
50: throw new NullPointerException();
51: }
52: if (!(o instanceof PointTime)) {
53: return false;
54: }
55: PointTime p = (PointTime) o;
56: return p.date.equals(date) && (p.index == index);
57: }
58: }
|