comparison backend/src/main/java/org/dive4elements/river/model/DischargeTable.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-backend/src/main/java/org/dive4elements/river/model/DischargeTable.java@18619c1e7c2a
children 4dd33b86dc61
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.model;
2
3 import java.io.Serializable;
4 import java.util.Date;
5 import java.util.List;
6
7 import javax.persistence.Column;
8 import javax.persistence.Entity;
9 import javax.persistence.GeneratedValue;
10 import javax.persistence.GenerationType;
11 import javax.persistence.Id;
12 import javax.persistence.JoinColumn;
13 import javax.persistence.OneToMany;
14 import javax.persistence.OneToOne;
15 import javax.persistence.OrderBy;
16 import javax.persistence.SequenceGenerator;
17 import javax.persistence.Table;
18
19 @Entity
20 @Table(name = "discharge_tables")
21 public class DischargeTable
22 implements Serializable, Comparable<DischargeTable>
23 {
24 private Integer id;
25 private Gauge gauge;
26 private String description;
27 private String bfgId;
28 private Integer kind;
29 private TimeInterval timeInterval;
30
31 private List<DischargeTableValue> dischargeTableValues;
32
33 public DischargeTable() {
34 kind = 0;
35 }
36
37 public DischargeTable(Gauge gauge) {
38 this(gauge, null, null, 0, null);
39 }
40
41 public DischargeTable(
42 Gauge gauge,
43 String description,
44 String bfgId,
45 Integer kind,
46 TimeInterval timeInterval
47 ) {
48 this.gauge = gauge;
49 this.description = description;
50 this.bfgId = bfgId;
51 this.kind = kind;
52 this.timeInterval = timeInterval;
53 }
54
55 @Id
56 @SequenceGenerator(
57 name = "SEQUENCE_DISCHARGE_TABLES_ID_SEQ",
58 sequenceName = "DISCHARGE_TABLES_ID_SEQ",
59 allocationSize = 1)
60 @GeneratedValue(
61 strategy = GenerationType.SEQUENCE,
62 generator = "SEQUENCE_DISCHARGE_TABLES_ID_SEQ")
63 @Column(name = "id")
64 public Integer getId() {
65 return id;
66 }
67
68 public void setId(Integer id) {
69 this.id = id;
70 }
71
72 @OneToOne
73 @JoinColumn(name = "gauge_id" )
74 public Gauge getGauge() {
75 return gauge;
76 }
77
78 public void setGauge(Gauge gauge) {
79 this.gauge = gauge;
80 }
81
82 @Column(name = "description")
83 public String getDescription() {
84 return description;
85 }
86
87 public void setDescription(String description) {
88 this.description = description;
89 }
90
91 @Column(name = "bfg_id")
92 public String getBfgId() {
93 return bfgId;
94 }
95
96 public void setBfgId(String bfgId) {
97 this.bfgId = bfgId;
98 }
99
100 @Column(name = "kind")
101 public Integer getKind() {
102 return kind;
103 }
104
105 public void setKind(Integer kind) {
106 this.kind = kind;
107 }
108
109 @OneToOne
110 @JoinColumn(name = "time_interval_id" )
111 public TimeInterval getTimeInterval() {
112 return timeInterval;
113 }
114
115 public void setTimeInterval(TimeInterval timeInterval) {
116 this.timeInterval = timeInterval;
117 }
118
119 @OneToMany
120 @JoinColumn(name = "table_id")
121 @OrderBy("q")
122 public List<DischargeTableValue> getDischargeTableValues() {
123 return dischargeTableValues;
124 }
125
126 public void setDischargeTableValues(
127 List<DischargeTableValue> dischargeTableValues
128 ) {
129 this.dischargeTableValues = dischargeTableValues;
130 }
131
132 @Override
133 public int compareTo(DischargeTable o) {
134 if (getKind() == 0 && o.getKind() != 0) {
135 return 1;
136 }
137
138 TimeInterval other = o.getTimeInterval();
139 if (other == null && timeInterval == null) {
140 return 1;
141 }
142 else if (other == null) {
143 return -1;
144 }
145 else if (timeInterval == null) {
146 return 1;
147 }
148
149 Date otherStartTime = other.getStartTime();
150 Date thisStartTime = timeInterval.getStartTime();
151
152 if (otherStartTime == null) {
153 return -1;
154 }
155 else if (thisStartTime == null) {
156 return 1;
157 }
158
159 long otherStart = otherStartTime.getTime();
160 long thisStart = thisStartTime.getTime();
161
162 if (otherStart < thisStart) {
163 return 1;
164 }
165 else if (otherStart > thisStart) {
166 return -1;
167 }
168
169 Date otherStopTime = other.getStopTime();
170 Date thisStopTime = timeInterval.getStopTime();
171
172 if (otherStopTime == null) {
173 return -1;
174 }
175 else if (thisStopTime == null) {
176 return 1;
177 }
178
179 long otherEnd = otherStopTime.getTime();
180 long thisEnd = thisStopTime.getTime();
181
182 if (otherEnd < thisEnd) {
183 return 1;
184 }
185 else if (otherEnd > thisEnd) {
186 return -1;
187 }
188 else {
189 return 0;
190 }
191 }
192 }
193 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org