Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/aft/TimeInterval.java @ 4865:1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 24 Jan 2013 16:09:46 +0100 |
parents | b195fede1c3b |
children |
rev | line source |
---|---|
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.aft; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.Date; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 public class TimeInterval |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 implements Comparable<TimeInterval> |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 protected int id; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 protected Date start; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 protected Date stop; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 public TimeInterval() { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
15 public TimeInterval(Date start, Date stop) { |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 this.start = start; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 this.stop = stop; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
20 public TimeInterval(int id, Date start, Date stop) { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
21 this(start, stop); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
22 this.id = id; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
23 } |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
24 |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 protected static int compare(Date d1, Date d2) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 long s1 = d1 != null ? d1.getTime()/1000L : 0L; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 long s2 = d2 != null ? d2.getTime()/1000L : 0L; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 long diff = s1 - s2; |
4736
b195fede1c3b
Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4101
diff
changeset
|
29 return diff < 0L |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 ? -1 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 : diff > 0L ? 1 : 0; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 @Override |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 public int compareTo(TimeInterval other) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 int cmp = compare(start, other.start); |
4736
b195fede1c3b
Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4101
diff
changeset
|
37 return cmp != 0 |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 ? cmp |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 : compare(stop, other.stop); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 public int getId() { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 return id; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 public void setId(int id) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 this.id = id; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 public Date getStart() { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 return start; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 public void setStart(Date start) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 this.start = start; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 public Date getStop() { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 return stop; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 public void setStop(Date stop) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 this.stop = stop; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
4101
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
65 |
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
66 public String toString() { |
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
67 return "[TimeInterval: start=" + start + ", stop=" + stop + "]"; |
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
68 } |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |