comparison flys-backend/src/main/java/de/intevation/flys/importer/StaFileParser.java @ 195:8d3533a03e10

Second part of parsing/storing main values. Should be finished now. flys-backend/trunk@1534 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 21 Mar 2011 15:06:47 +0000
parents f1fce41347ea
children cce054f27dac
comparison
equal deleted inserted replaced
194:0f0b98ef9b04 195:8d3533a03e10
10 10
11 import java.util.regex.Pattern; 11 import java.util.regex.Pattern;
12 import java.util.regex.Matcher; 12 import java.util.regex.Matcher;
13 13
14 import java.util.HashMap; 14 import java.util.HashMap;
15 import java.util.ArrayList;
15 16
16 import org.apache.log4j.Logger; 17 import org.apache.log4j.Logger;
17 18
18 public class StaFileParser 19 public class StaFileParser
19 { 20 {
97 } 98 }
98 99
99 HashMap<String, ImportMainValueType> types = 100 HashMap<String, ImportMainValueType> types =
100 new HashMap<String, ImportMainValueType>(); 101 new HashMap<String, ImportMainValueType>();
101 102
103 ArrayList<ImportNamedMainValue> namedMainValues =
104 new ArrayList<ImportNamedMainValue>();
105
106 ArrayList<ImportMainValue> mainValues =
107 new ArrayList<ImportMainValue>();
108
102 while ((line = in.readLine()) != null) { 109 while ((line = in.readLine()) != null) {
103 Matcher m = QWTD_.matcher(line); 110 Matcher m = QWTD_.matcher(line);
104 if (m.matches()) { 111 if (m.matches()) {
105 BigDecimal value; 112 BigDecimal value;
106 try { 113 try {
116 ImportMainValueType type = types.get(typeString); 123 ImportMainValueType type = types.get(typeString);
117 if (type == null) { 124 if (type == null) {
118 type = new ImportMainValueType(typeString); 125 type = new ImportMainValueType(typeString);
119 types.put(typeString, type); 126 types.put(typeString, type);
120 } 127 }
128 String name = m.group(1);
129 ImportNamedMainValue namedMainValue =
130 new ImportNamedMainValue(type, name);
131 namedMainValues.add(namedMainValue);
132
133 ImportMainValue mainValue =
134 new ImportMainValue(gauge, namedMainValue, value);
135
136 mainValues.add(mainValue);
121 } 137 }
122 else { 138 else {
123 // TODO: treat as a comment 139 // TODO: treat as a comment
124 } 140 }
125 } 141 }
142 gauge.setMainValueTypes(
143 new ArrayList<ImportMainValueType>(types.values()));
144 gauge.setNamedMainValues(namedMainValues);
145 gauge.setMainValues(mainValues);
126 } 146 }
127 finally { 147 finally {
128 if (in != null) { 148 if (in != null) {
129 in.close(); 149 in.close();
130 } 150 }

http://dive4elements.wald.intevation.org