Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/importer/parsers/BundesWasserStrassenParser.java @ 5446:3bd786772798
Removed obsolete imports.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 27 Mar 2013 10:06:49 +0100 |
parents | 3d01658d9c9c |
children |
line wrap: on
line source
package de.intevation.flys.importer.parsers; import java.util.HashMap; import org.apache.log4j.Logger; /** Parse CSV file that contains official numbers for rivers. */ public class BundesWasserStrassenParser extends LineParser { /** Private logger. */ private static final Logger logger = Logger.getLogger(BundesWasserStrassenParser.class); /** Map from rivernames to Official numbers. */ private HashMap<String,Long> numberMap; public BundesWasserStrassenParser() { numberMap = new HashMap<String,Long>(); } /** No need to reset. */ @Override protected void reset() { } /** No action needed on eof. */ @Override protected void finish() { } /** Handle a line of the bwastr-id file. */ @Override protected void handleLine(int lineNum, String line) { String[] vals = line.split(","); // Try both "," and ";" as separator. if (vals.length != 2) { vals = line.split(";"); if (vals.length != 2) { logger.warn("Invalid bwastr-id line:\n" + line); return; } } try { String name = unwrap(vals[0].toLowerCase()); String numberStr = unwrap(vals[1]); Long number = Long.valueOf(numberStr); numberMap.put(name, number); } catch (NumberFormatException e) { logger.warn("Invalid number in bwastr-id line:\n" + line); } } /** Get river -> official number mapping. */ public HashMap<String,Long> getMap() { return numberMap; } /** Remove leading and trailing quotes. */ protected String unwrap(String input) { if (input.startsWith("\"")) { input = input.substring(1); } if (input.endsWith("\"")) { input = input.substring(0, input.length() - 1); } return input; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :