annotate flys-backend/src/main/java/de/intevation/flys/model/River.java @ 465:c2c3ad4fda58

Added a method to River that returns the min and max distance of the river. flys-backend/trunk@1698 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 14 Apr 2011 13:43:53 +0000
parents 003ac16812dd
children 1e196c75563b
rev   line source
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.model;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.io.Serializable;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
5 import java.math.BigDecimal;
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
6
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
7 import javax.persistence.Entity;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
8 import javax.persistence.Id;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
9 import javax.persistence.Table;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
10 import javax.persistence.GeneratedValue;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
11 import javax.persistence.Column;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
12 import javax.persistence.SequenceGenerator;
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
13 import javax.persistence.OneToMany;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
14 import javax.persistence.JoinColumn;
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
15 import javax.persistence.GenerationType;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
16
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
17 import java.util.List;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
18
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
19 @Entity
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
20 @Table(name = "rivers")
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 public class River
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 implements Serializable
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 {
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
24 private Integer id;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
26 private String name;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
28 private List<Gauge> gauges;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
29
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
30 @Id
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
31 @SequenceGenerator(
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
32 name = "SEQUENCE_RIVERS_ID_SEQ",
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
33 sequenceName = "RIVERS_ID_SEQ",
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
34 allocationSize = 1)
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
35 @GeneratedValue(
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
36 strategy = GenerationType.SEQUENCE,
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 169
diff changeset
37 generator = "SEQUENCE_RIVERS_ID_SEQ")
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
38 @Column(name = "id")
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
39 public Integer getId() {
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
40 return id;
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
41 }
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
42
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
43 public void setId(Integer id) {
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 this.id = id;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
47 @Column(name = "name")
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
48 public String getName() {
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
49 return name;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 public void setName(String name) {
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 this.name = name;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 public River() {
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 }
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
58
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
59 public River(String name) {
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
60 this.name = name;
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
61 }
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
62
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
63 @OneToMany
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
64 @JoinColumn(name="river_id")
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
65 public List<Gauge> getGauges() {
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
66 return gauges;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
67 }
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
68
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
69 public void setGauges(List<Gauge> gauges) {
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
70 this.gauges = gauges;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
71 }
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
72
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
73 public String toString() {
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
74 return name != null ? name : "";
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
75 }
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
76
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
77 /**
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
78 * Returns the min and max distance of this river. The first position in the
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
79 * resulting array contains the min distance, the second position the max
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
80 * distance.
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
81 *
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
82 * @return the min and max distance of this river.
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
83 */
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
84 public double[] determineMinMaxDistance() {
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
85 if (gauges == null) {
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
86 return null;
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
87 }
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
88
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
89 double minmax[] = new double[] { Double.MAX_VALUE, Double.MIN_VALUE };
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
90
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
91 for (Gauge g: gauges) {
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
92 Range r = g.getRange();
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
93
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
94 double a = r.getA().doubleValue();
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
95 minmax[0] = minmax[0] < a ? minmax[0] : a;
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
96
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
97 BigDecimal bigB = r.getB();
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
98 if (bigB != null) {
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
99 double b = bigB.doubleValue();
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
100 minmax[1] = minmax[1] > b ? minmax[1] : b;
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
101 }
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
102 }
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
103
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
104 return minmax;
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
105 }
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org