Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/model/Range.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | 4c3ccf2b0304 |
children |
rev | line source |
---|---|
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
9 package org.dive4elements.river.model; |
167
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.io.Serializable; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import java.math.BigDecimal; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
171
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
15 import javax.persistence.Entity; |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
16 import javax.persistence.Id; |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
17 import javax.persistence.Table; |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
18 import javax.persistence.GeneratedValue; |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
19 import javax.persistence.Column; |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
20 import javax.persistence.SequenceGenerator; |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
21 import javax.persistence.GenerationType; |
174
249390dd24e7
Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
172
diff
changeset
|
22 import javax.persistence.JoinColumn; |
249390dd24e7
Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
172
diff
changeset
|
23 import javax.persistence.OneToOne; |
171
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
24 |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
25 @Entity |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
26 @Table(name = "ranges") |
167
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 public class Range |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 implements Serializable |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 { |
5743
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
30 public static final double EPSILON = 1e-5; |
171
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
31 private Integer id; |
167
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 private BigDecimal a; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 private BigDecimal b; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 private River river; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 public Range() { |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
204
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
40 public Range(double a, double b, River river) { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
41 this(new BigDecimal(a), new BigDecimal(b), river); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
42 } |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
43 |
201
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
189
diff
changeset
|
44 public Range(BigDecimal a, BigDecimal b, River river) { |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
189
diff
changeset
|
45 this.a = a; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
189
diff
changeset
|
46 this.b = b; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
189
diff
changeset
|
47 this.river = river; |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
189
diff
changeset
|
48 } |
3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
189
diff
changeset
|
49 |
171
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
50 @Id |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
51 @SequenceGenerator( |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
52 name = "SEQUENCE_RANGES_ID_SEQ", |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
53 sequenceName = "RANGES_ID_SEQ", |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
54 allocationSize = 1) |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
55 @GeneratedValue( |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
56 strategy = GenerationType.SEQUENCE, |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
57 generator = "SEQUENCE_RANGES_ID_SEQ") |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
58 @Column(name = "id") |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
59 public Integer getId() { |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
60 return id; |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
61 } |
4a83e14f40f9
Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
168
diff
changeset
|
62 |
168
86a1bd9cc50e
More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
63 public void setId(Integer id) { |
167
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 this.id = id; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
172
605320b7df94
Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
171
diff
changeset
|
67 @Column(name = "a") // FIXME: type mapping needed? |
605320b7df94
Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
171
diff
changeset
|
68 public BigDecimal getA() { |
605320b7df94
Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
171
diff
changeset
|
69 return a; |
605320b7df94
Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
171
diff
changeset
|
70 } |
605320b7df94
Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
171
diff
changeset
|
71 |
167
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 public void setA(BigDecimal a) { |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 this.a = a; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 } |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
172
605320b7df94
Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
171
diff
changeset
|
76 @Column(name = "b") // FIXME: type mapping needed? |
605320b7df94
Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
171
diff
changeset
|
77 public BigDecimal getB() { |
605320b7df94
Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
171
diff
changeset
|
78 return b; |
167
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 } |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 public void setB(BigDecimal b) { |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 this.b = b; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 } |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
5743
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
85 public boolean containsTolerant(double x) { |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
86 return containsTolerant(x, EPSILON); |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
87 } |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
88 |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
89 public boolean containsTolerant(double x, double tolerance) { |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
90 BigDecimal b = this.b != null ? this.b : a; |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
91 double av = a.doubleValue(); |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
92 double bv = b.doubleValue(); |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
93 if (av > bv) { |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
94 double t = av; |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
95 av = bv; |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
96 bv = t; |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
97 } |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
98 return x+tolerance >= av && x-tolerance <= bv; |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
99 } |
80b9218ac007
Add containsTolerant to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5587
diff
changeset
|
100 |
5587
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
101 public boolean contains(double x) { |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
102 BigDecimal b = this.b != null ? this.b : a; |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
103 double av = a.doubleValue(); |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
104 double bv = b.doubleValue(); |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
105 if (av > bv) { |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
106 double t = av; |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
107 av = bv; |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
108 bv = t; |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
109 } |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
110 return x >= av && x <= bv; |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
111 } |
7b1c5fe4ebf3
Simplified inner loop of water level exporter.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
205
diff
changeset
|
112 |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
113 @OneToOne |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
114 @JoinColumn(name = "river_id") |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
115 public River getRiver() { |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
116 return river; |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
117 } |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
118 |
167
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 public void setRiver(River river) { |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 this.river = river; |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
204
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
122 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
123 public int code() { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
124 int code = 0; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
125 if (a != null) code = 1; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
126 if (b != null) code |= 2; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
127 return code; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
128 } |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
129 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
130 public boolean intersects(BigDecimal c) { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
131 return !(a.compareTo(c) > 0 || b.compareTo(c) < 0); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
132 } |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
133 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
134 public boolean intersects(Range other) { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
135 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
136 int code = code(); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
137 int ocode = other.code(); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
138 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
139 if (code == 0 || ocode == 0) { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
140 return false; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
141 } |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
142 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
143 switch (code) { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
144 case 1: // has a |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
145 switch (ocode) { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
146 case 1: // has a |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
147 return a.compareTo(other.a) == 0; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
148 case 2: // has b |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
149 return a.compareTo(other.b) == 0; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
150 case 3: // has range |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
151 return other.intersects(a); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
152 } |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
153 break; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
154 case 2: // has b |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
155 switch (ocode) { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
156 case 1: // has a |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
157 return b.compareTo(other.a) == 0; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
158 case 2: // has b |
205
697d1faa8217
Forgot to save the last change before commit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
204
diff
changeset
|
159 return b.compareTo(other.b) == 0; |
204
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
160 case 3: // has range |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
161 return other.intersects(b); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
162 } |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
163 break; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
164 case 3: // has range |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
165 switch (ocode) { |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
166 case 1: // has a |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
167 return intersects(other.a); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
168 case 2: // has b |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
169 return intersects(other.b); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
170 case 3: // has range |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
171 return !(other.b.compareTo(a) < 0 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
172 ||other.a.compareTo(b) > 0); |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
173 } |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
174 break; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
175 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
176 } |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
177 |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
178 return false; |
764835268e2b
Added methods to find out if two ranges intersects.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
201
diff
changeset
|
179 } |
167
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
15d515fe15f5
Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |