annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java @ 5863:4897a58c8746

River artifacts: Added new copyright headers.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:40:59 +0200
parents 5aa05a7a34b7
children af13ceeba52a
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5636
diff changeset
9 package org.dive4elements.river.artifacts.model;
3138
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.io.Serializable;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
4334
048b3c3acd01 Range: Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3743
diff changeset
13 /** A range from ... to .*/
3138
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 public class Range implements Serializable {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
5636
f7208c190e4a Whitespace cosmetic.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4334
diff changeset
16 public static final double EPSILON = 1e-5;
3138
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 protected double start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 protected double end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 public Range() {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
3401
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
24 public Range(Range other) {
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
25 start = other.start;
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
26 end = other.end;
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
27 }
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
28
3138
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public Range(double start, double end) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 this.start = start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 this.end = end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public double getStart() {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 return start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public double getEnd() {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 return end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
3743
51f76225823b Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3401
diff changeset
42 public boolean disjoint(double ostart, double oend) {
51f76225823b Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3401
diff changeset
43 return start > oend || ostart > end;
51f76225823b Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3401
diff changeset
44 }
51f76225823b Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3401
diff changeset
45
3138
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 public boolean disjoint(Range other) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 return start > other.end || other.start > end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 public boolean intersects(Range other) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 return !disjoint(other);
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public void extend(Range other) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 if (other.start < start) start = other.start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 if (other.end > end ) end = other.end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 public boolean clip(Range other) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 if (disjoint(other)) return false;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 if (other.start > start) start = other.start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 if (other.end < end ) end = other.end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 return true;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67
4334
048b3c3acd01 Range: Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3743
diff changeset
68 /** True if start>x<end (+ some epsilon) . */
3138
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 public boolean inside(double x) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 return x > start-EPSILON && x < end+EPSILON;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org