annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Range.java @ 3436:0d63581c5df1

FLYSArtifact: Prevent NPE in getOutputForState(). Why does this happen? flys-artifacts/trunk@5099 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 23 Jul 2012 08:38:23 +0000
parents 086326be721c
children 51f76225823b
rev   line source
3138
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.io.Serializable;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 public class Range implements Serializable {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 public static final double EPSILON = 1e-5;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 protected double start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 protected double end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 public Range() {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
3401
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
15 public Range(Range other) {
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
16 start = other.start;
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
17 end = other.end;
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
18 }
086326be721c FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3138
diff changeset
19
3138
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public Range(double start, double end) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 this.start = start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 this.end = end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public double getStart() {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 return start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public double getEnd() {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 return end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
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 public boolean disjoint(Range other) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 return start > other.end || other.start > end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 }
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 public boolean intersects(Range other) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 return !disjoint(other);
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 }
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 public void extend(Range other) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 if (other.start < start) start = other.start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 if (other.end > end ) end = other.end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 }
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 public boolean clip(Range other) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 if (disjoint(other)) return false;
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 if (other.start > start) start = other.start;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 if (other.end < end ) end = other.end;
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 return true;
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
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 public boolean inside(double x) {
9c147bbffc36 FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 return x > start-EPSILON && x < end+EPSILON;
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org