comparison flys-backend/src/main/java/de/intevation/flys/model/Range.java @ 5743:80b9218ac007

Add containsTolerant to Range.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 17 Apr 2013 14:52:19 +0200
parents 7b1c5fe4ebf3
children
comparison
equal deleted inserted replaced
5742:a4a894b15c35 5743:80b9218ac007
17 @Entity 17 @Entity
18 @Table(name = "ranges") 18 @Table(name = "ranges")
19 public class Range 19 public class Range
20 implements Serializable 20 implements Serializable
21 { 21 {
22 public static final double EPSILON = 1e-5;
22 private Integer id; 23 private Integer id;
23 private BigDecimal a; 24 private BigDecimal a;
24 private BigDecimal b; 25 private BigDecimal b;
25 26
26 private River river; 27 private River river;
69 return b; 70 return b;
70 } 71 }
71 72
72 public void setB(BigDecimal b) { 73 public void setB(BigDecimal b) {
73 this.b = b; 74 this.b = b;
75 }
76
77 public boolean containsTolerant(double x) {
78 return containsTolerant(x, EPSILON);
79 }
80
81 public boolean containsTolerant(double x, double tolerance) {
82 BigDecimal b = this.b != null ? this.b : a;
83 double av = a.doubleValue();
84 double bv = b.doubleValue();
85 if (av > bv) {
86 double t = av;
87 av = bv;
88 bv = t;
89 }
90 return x+tolerance >= av && x-tolerance <= bv;
74 } 91 }
75 92
76 public boolean contains(double x) { 93 public boolean contains(double x) {
77 BigDecimal b = this.b != null ? this.b : a; 94 BigDecimal b = this.b != null ? this.b : a;
78 double av = a.doubleValue(); 95 double av = a.doubleValue();

http://dive4elements.wald.intevation.org