annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java @ 2149:b5f3b29544ea

Added cache definition for hyks. flys-artifacts/trunk@3731 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 20 Jan 2012 08:30:50 +0000
parents 8124ca1ecaaa
children da7cf0e3ccaa
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
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.List;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.ArrayList;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.io.Serializable;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import org.apache.log4j.Logger;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import gnu.trove.TDoubleArrayList;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
12 import de.intevation.flys.utils.DoubleUtil;
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
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 public String toString() {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 StringBuilder sb = new StringBuilder("Segment: [");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 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
45 .append(to)
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
46 .append("; ref: ").append(referencePoint)
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
47 .append("; values: (");
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 for (int i = 0; i < values.length; ++i) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 if (i > 0) sb.append(", ");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 sb.append(values[i]);
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 sb.append(")]");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 return sb.toString();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
56 public void setFrom(double from) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
57 this.from = from;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
58 }
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 public void backup() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
61 backup = (double [])values.clone();
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
62 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
63
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
64 public double getFrom() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
65 return from;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
68 public void setTo(double to) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
69 this.to = to;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
72 public double getTo() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
73 return to;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
76 public void setValues(double [] values) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
77 this.values = values;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
80 public double [] getValues() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
81 return values;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
84 public void setReferencePoint(double referencePoint) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
85 this.referencePoint = referencePoint;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
88 public double getReferencePoint() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
89 return referencePoint;
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
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 public static List<Segment> parseSegments(String input) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 ArrayList<Segment> segments = new ArrayList<Segment>();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 TDoubleArrayList vs = new TDoubleArrayList();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 for (String segmentStr: input.split(":")) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 String [] parts = segmentStr.split(";");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 if (parts.length < 3) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 logger.warn("invalid segment: '" + segmentStr + "'");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 continue;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 try {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 double from = Double.parseDouble(parts[0].trim());
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 double to = Double.parseDouble(parts[1].trim());
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 vs.clear();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 for (String valueStr: parts[2].split(",")) {
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
111 vs.add(DoubleUtil.round(
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
112 Double.parseDouble(valueStr.trim())));
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 double [] values = vs.toNativeArray();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 segments.add(new Segment(from, to, values));
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 catch (NumberFormatException nfe) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 logger.warn("invalid segment: '" + segmentStr + "'");
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 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 return segments;
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org