Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java @ 3432:9c39a25aa849
FixA: Embed german and english translations into the overview stylesheet.
flys-artifacts/trunk@5092 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 21 Jul 2012 12:50:48 +0000 |
parents | da7cf0e3ccaa |
children | cb11919cccf9 |
rev | line source |
---|---|
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
3 import de.intevation.flys.utils.DoubleUtil; |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
4 |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
5 import gnu.trove.TDoubleArrayList; |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.io.Serializable; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
9 import java.util.ArrayList; |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
10 import java.util.List; |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
12 import org.apache.log4j.Logger; |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
13 |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 public class Segment |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 implements Serializable |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 private static Logger logger = Logger.getLogger(Segment.class); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 protected double from; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 protected double to; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 protected double [] values; |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
22 protected double [] backup; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
23 protected double referencePoint; |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 public Segment() { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
28 public Segment(double referencePoint) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
29 this.referencePoint = referencePoint; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
30 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
31 |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public Segment(double from, double to, double [] values) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 this.from = from; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 this.to = to; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 this.values = values; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public boolean isUp() { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 return from < to; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
42 @Override |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public String toString() { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 StringBuilder sb = new StringBuilder("Segment: ["); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 sb.append("from: ").append(from).append("; to: ") |
670
8124ca1ecaaa
Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
655
diff
changeset
|
46 .append(to) |
8124ca1ecaaa
Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
655
diff
changeset
|
47 .append("; ref: ").append(referencePoint) |
8124ca1ecaaa
Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
655
diff
changeset
|
48 .append("; values: ("); |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 for (int i = 0; i < values.length; ++i) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 if (i > 0) sb.append(", "); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 sb.append(values[i]); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 sb.append(")]"); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 return sb.toString(); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
57 public void setFrom(double from) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
58 this.from = from; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
59 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
60 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
61 public void backup() { |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
62 backup = values != null |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
63 ? (double [])values.clone() |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
64 : null; |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
65 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
66 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
67 public double getFrom() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
68 return from; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
69 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
70 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
71 public void setTo(double to) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
72 this.to = to; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
73 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
74 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
75 public double getTo() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
76 return to; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
77 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
78 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
79 public void setValues(double [] values) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
80 this.values = values; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
81 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
82 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
83 public double [] getValues() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
84 return values; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
85 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
86 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
87 public void setReferencePoint(double referencePoint) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
88 this.referencePoint = referencePoint; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
89 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
90 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
91 public double getReferencePoint() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
92 return referencePoint; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
93 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
94 |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 public static List<Segment> parseSegments(String input) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 ArrayList<Segment> segments = new ArrayList<Segment>(); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 TDoubleArrayList vs = new TDoubleArrayList(); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 for (String segmentStr: input.split(":")) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 String [] parts = segmentStr.split(";"); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 if (parts.length < 3) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 logger.warn("invalid segment: '" + segmentStr + "'"); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 continue; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 try { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 double from = Double.parseDouble(parts[0].trim()); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 double to = Double.parseDouble(parts[1].trim()); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 vs.clear(); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 for (String valueStr: parts[2].split(",")) { |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
114 vs.add(DoubleUtil.round( |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
115 Double.parseDouble(valueStr.trim()))); |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 double [] values = vs.toNativeArray(); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 segments.add(new Segment(from, to, values)); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 catch (NumberFormatException nfe) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 logger.warn("invalid segment: '" + segmentStr + "'"); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 return segments; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |