KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > tools > stats > PointTime


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.tools.stats;
10
11 import java.util.Date JavaDoc;
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 JavaDoc
23 {
24    private Date JavaDoc date;
25    private long index;
26
27    public PointTime(Date JavaDoc date, long index)
28    {
29       this.date = date;
30       this.index = index;
31    }
32
33    public Date JavaDoc getDate()
34    {
35       return date;
36    }
37
38    public long getIndex()
39    {
40       return index;
41    }
42
43    public int compareTo(Object JavaDoc o)
44    {
45       PointTime p = (PointTime)o;
46       if (date.equals(p.date))
47       {
48          return (int)(index - p.index);
49       }
50       else
51       {
52          return date.compareTo(p.date);
53       }
54    }
55
56    public boolean equals(Object JavaDoc o)
57    {
58       if (o == null)
59       {
60          throw new NullPointerException JavaDoc();
61       }
62       if (!(o instanceof PointTime))
63       {
64          return false;
65       }
66       PointTime p = (PointTime)o;
67       return p.date.equals(date) && (p.index == index);
68    }
69 }
70
Popular Tags