comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportRange.java @ 189:bc3747a371cc

First part of parsing main values. flys-backend/trunk@1520 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 18 Mar 2011 16:12:24 +0000
parents 003ac16812dd
children 3169b559ca3c
comparison
equal deleted inserted replaced
188:003ac16812dd 189:bc3747a371cc
15 public class ImportRange 15 public class ImportRange
16 implements Comparable<ImportRange> 16 implements Comparable<ImportRange>
17 { 17 {
18 private static Logger log = Logger.getLogger(ImportRange.class); 18 private static Logger log = Logger.getLogger(ImportRange.class);
19 19
20 protected Double from; 20 protected BigDecimal a;
21 protected Double to; 21 protected BigDecimal b;
22 22
23 protected Range peer; 23 protected Range peer;
24 24
25 public ImportRange() { 25 public ImportRange() {
26 } 26 }
27 27
28 public ImportRange(Double from, Double to) { 28 public ImportRange(BigDecimal a, BigDecimal b) {
29 this.from = from; 29 this.a = a;
30 this.to = to; 30 this.b = b;
31 } 31 }
32 32
33 private static final int compare(Double a, Double b) { 33 private static final int compare(BigDecimal a, BigDecimal b) {
34 if (a == null && b == null) { 34 if (a == null && b == null) {
35 return 0; 35 return 0;
36 } 36 }
37 if (a == null && b != null) { 37 if (a == null && b != null) {
38 return -1; 38 return -1;
42 } 42 }
43 return a.compareTo(b); 43 return a.compareTo(b);
44 } 44 }
45 45
46 public int compareTo(ImportRange other) { 46 public int compareTo(ImportRange other) {
47 int cmp = compare(from, other.from); 47 int cmp = compare(a, other.a);
48 if (cmp != 0) return cmp; 48 if (cmp != 0) return cmp;
49 return compare(to, other.to); 49 return compare(b, other.b);
50 } 50 }
51 51
52 public Double getFrom() { 52 public BigDecimal getA() {
53 return from; 53 return a;
54 } 54 }
55 55
56 public void setFrom(Double from) { 56 public void setA(BigDecimal a) {
57 this.from = from; 57 this.a = a;
58 } 58 }
59 59
60 public Double getTo() { 60 public BigDecimal getB() {
61 return to; 61 return b;
62 } 62 }
63 63
64 public void setTo(Double to) { 64 public void setB(BigDecimal b) {
65 this.to = to; 65 this.b = b;
66 } 66 }
67 67
68 public Range getPeer(River river) { 68 public Range getPeer(River river) {
69 if (peer == null) { 69 if (peer == null) {
70 Session session = Importer.sessionHolder.get(); 70 Session session = Importer.sessionHolder.get();
71 Query query = session.createQuery( 71 Query query = session.createQuery(
72 "from Range where a=:a and b=:b and river.id=:river"); 72 "from Range where a=:a and b=:b and river.id=:river");
73 BigDecimal a = from != null ? BigDecimal.valueOf(from) : null;
74 BigDecimal b = to != null ? BigDecimal.valueOf(to) : null;
75 query.setParameter("a", a); 73 query.setParameter("a", a);
76 query.setParameter("b", b); 74 query.setParameter("b", b);
77 query.setParameter("river", river.getId()); 75 query.setParameter("river", river.getId());
78 List<Range> ranges = query.list(); 76 List<Range> ranges = query.list();
79 if (ranges.isEmpty()) { 77 if (ranges.isEmpty()) {

http://dive4elements.wald.intevation.org