comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/access/BedHeightAccess.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedHeightAccess.java@cb4cc6414447
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.access;
2
3 import java.util.List;
4
5 import org.dive4elements.artifacts.CallContext;
6
7 import org.dive4elements.river.artifacts.FLYSArtifact;
8 import org.dive4elements.river.artifacts.model.minfo.BedHeight;
9 import org.dive4elements.river.artifacts.model.minfo.BedHeightFactory;
10 import org.dive4elements.river.artifacts.states.SoundingsSelect;
11 import org.dive4elements.river.model.BedHeightSingle;
12 import org.dive4elements.river.model.BedHeightSingleValue;
13
14 import gnu.trove.TIntArrayList;
15
16 import org.apache.log4j.Logger;
17
18
19 public class BedHeightAccess
20 extends RangeAccess
21 {
22
23 private static final Logger logger = Logger.getLogger(BedHeightAccess.class);
24
25 private int[] singleIDs;
26 private int[] epochIDs;
27
28 private String time;
29
30 public BedHeightAccess(FLYSArtifact artifact, CallContext context) {
31 super(artifact, context);
32 }
33
34
35 public Double getLowerKM() {
36 // TODO update callers
37 return getFrom();
38 }
39
40
41 public Double getUpperKM() {
42 // TODO update callers
43 return getTo();
44 }
45
46
47 public int[] getBedHeightSingleIDs() {
48 if (singleIDs == null) {
49 String data = getString("soundings");
50
51 if (data == null) {
52 logger.warn("No 'soundings' parameter specified!");
53 return null;
54 }
55 else {
56 logger.debug("getBedHeightSingleIDs(): data=" + data);
57 }
58
59 String[] parts = data.split(";");
60
61 TIntArrayList ids = new TIntArrayList();
62
63 for (String part: parts) {
64 if (part.indexOf(SoundingsSelect.PREFIX_SINGLE) >= 0) {
65 String tmp = part.replace(SoundingsSelect.PREFIX_SINGLE, "");
66
67 try {
68 int i = Integer.parseInt(tmp);
69 if (!ids.contains(i)) {
70 ids.add(i);
71 }
72 }
73 catch (NumberFormatException nfe) {
74 logger.warn("Cannot parse int from string: '" + tmp + "'");
75 }
76 }
77 }
78
79 singleIDs = ids.toNativeArray();
80 }
81
82 return singleIDs;
83 }
84
85
86 public String getYearEpoch() {
87 if (time == null) {
88 time = getString("ye_select");
89 }
90 return time;
91 }
92
93
94 public int[] getBedHeightEpochIDs() {
95 if (epochIDs == null) {
96 String data = getString("soundings");
97
98 if (data == null) {
99 logger.warn("No 'soundings' parameter specified!");
100 return null;
101 }
102
103 String[] parts = data.split(";");
104
105 TIntArrayList ids = new TIntArrayList();
106
107 for (String part: parts) {
108 if (part.indexOf(SoundingsSelect.PREFIX_EPOCH) >= 0) {
109 String tmp = part.replace(SoundingsSelect.PREFIX_EPOCH, "");
110
111 try {
112 ids.add(Integer.parseInt(tmp));
113 }
114 catch (NumberFormatException nfe) {
115 logger.warn("Cannot parse int from string: '" + tmp + "'");
116 }
117 }
118 }
119
120 epochIDs = ids.toNativeArray();
121 }
122
123 return epochIDs;
124 }
125
126 /**
127 * Return the {@link BedHeight} at the height_id and time of the artifact
128 * @return {@link BedHeight}
129 */
130 public BedHeight getHeight() {
131 logger.debug("getHeight");
132 return BedHeightFactory.getHeight(
133 artifact.getDataAsString("type"),
134 Integer.parseInt(artifact.getDataAsString("height_id")),
135 Integer.parseInt(artifact.getDataAsString("time")));
136 }
137
138 /**
139 * Return a {@link List} of {@link BedHeightSingleValue}s
140 * at the range of the artifact
141 * @return List of {@link BedHeightSingleValue}s
142 */
143 public List<BedHeightSingleValue> getSingleValues() {
144 logger.debug("getSingleValues");
145 BedHeightSingle single = BedHeightSingle.getBedHeightSingleById(
146 artifact.getDataAsInteger("height_id"));
147 return BedHeightSingleValue.getBedHeightSingleValues(single,
148 getFrom(),
149 getTo());
150 }
151 }
152 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org