Mercurial > dive4elements > river
changeset 4735:94b39073f0f7
Moved EpsilonComparator to utils package becaus its not only useful for TIM parsing. Used EpsilonComparator in DA60 and DA66 case. Maybe TODO: Use in PRF, too.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 01 Jan 2013 13:54:08 +0100 |
parents | 0b4e1a493045 |
children | b195fede1c3b |
files | flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA50Parser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/EpsilonComparator.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/TIMParser.java flys-backend/src/main/java/de/intevation/flys/utils/EpsilonComparator.java |
diffstat | 7 files changed, 61 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Sun Dec 30 10:56:52 2012 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java Tue Jan 01 13:54:08 2013 +0100 @@ -896,10 +896,12 @@ ? new ImportTimeInterval(yearToDate(year)) : null; + Map<Double, List<XY>> data = parser.getData(); + List<ImportCrossSectionLine> lines = - new ArrayList<ImportCrossSectionLine>(); + new ArrayList<ImportCrossSectionLine>(data.size()); - for (Map.Entry<Double, List<XY>> entry: parser.getData().entrySet()) { + for (Map.Entry<Double, List<XY>> entry: data.entrySet()) { Double km = entry.getKey(); List<XY> points = entry.getValue(); lines.add(new ImportCrossSectionLine(km, points));
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA50Parser.java Sun Dec 30 10:56:52 2012 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA50Parser.java Tue Jan 01 13:54:08 2013 +0100 @@ -14,6 +14,8 @@ import de.intevation.artifacts.common.utils.FileTools; +import de.intevation.flys.utils.EpsilonComparator; + /** * To create cross-sections, generate: Map<double,list<xy>> from files @@ -33,7 +35,7 @@ /** Trivial constructor. */ public DA50Parser() { - data = new TreeMap<Double, List<XY>>(); + data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP); }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java Sun Dec 30 10:56:52 2012 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java Tue Jan 01 13:54:08 2013 +0100 @@ -1,22 +1,24 @@ package de.intevation.flys.importer.parsers; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.List; -import java.util.TreeMap; +import de.intevation.artifacts.common.utils.FileTools; -import java.util.regex.Pattern; -import java.util.regex.Matcher; +import de.intevation.flys.importer.XY; + +import de.intevation.flys.utils.EpsilonComparator; import java.io.File; import java.io.IOException; -import org.apache.log4j.Logger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; -import de.intevation.flys.importer.XY; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -import de.intevation.artifacts.common.utils.FileTools; +import org.apache.log4j.Logger; /** @@ -78,7 +80,7 @@ POINT_4_ID(15), POINT_4_Y (16), POINT_4_Z (17); - + private int idx; FIELD(int idx) { this.idx = idx; @@ -172,7 +174,7 @@ /** Trivial constructor. */ public DA66Parser() { - data = new TreeMap<Double, List<XY>>(); + data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP); } @@ -266,8 +268,8 @@ return false; } - Double iy; - Double iz; + double iy; + double iz; try { iy = Double.parseDouble(y) / 1000d; iz = Double.parseDouble(z) / 1000d; @@ -278,7 +280,7 @@ } // We ignore idx, and increment instead. - Integer index; + int index; int lastPointIdx = lastPointIdx(); if (lastPointIdx <= 0) { index = 1;
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java Sun Dec 30 10:56:52 2012 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java Tue Jan 01 13:54:08 2013 +0100 @@ -1,21 +1,23 @@ package de.intevation.flys.importer.parsers; +import de.intevation.artifacts.common.utils.FileTools; + +import de.intevation.flys.importer.XY; + +import de.intevation.flys.utils.EpsilonComparator; + +import java.io.File; +import java.io.IOException; + import java.util.ArrayList; +import java.util.List; import java.util.Map; -import java.util.List; import java.util.TreeMap; import java.util.regex.Pattern; -import java.io.File; -import java.io.IOException; - import org.apache.log4j.Logger; -import de.intevation.flys.importer.XY; - -import de.intevation.artifacts.common.utils.FileTools; - /** * To create cross-sections, generate: Map<double,list<xy>> from files @@ -55,7 +57,7 @@ /** Trivial constructor. */ public W80Parser() { - data = new TreeMap<Double, List<XY>>(); + data = new TreeMap<Double, List<XY>>(EpsilonComparator.CMP); }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/EpsilonComparator.java Sun Dec 30 10:56:52 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package de.intevation.flys.importer.parsers.tim; - -import java.util.Comparator; - -public class EpsilonComparator implements Comparator<Double> -{ - public static final double EPSILON = 1e-4; - - public static final EpsilonComparator CMP = new EpsilonComparator(EPSILON); - - private double epsilon; - - public EpsilonComparator(double epsilon) { - this.epsilon = epsilon; - } - - @Override - public int compare(Double a, Double b) { - double diff = a - b; - if (diff < -epsilon) return -1; - if (diff > epsilon) return +1; - return 0; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/TIMParser.java Sun Dec 30 10:56:52 2012 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/TIMParser.java Tue Jan 01 13:54:08 2013 +0100 @@ -11,6 +11,7 @@ import java.util.Map; import java.util.TreeMap; +import de.intevation.flys.utils.EpsilonComparator; /** Parser for single .tim files. */ // TODO switch to proper logging.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/utils/EpsilonComparator.java Tue Jan 01 13:54:08 2013 +0100 @@ -0,0 +1,25 @@ +package de.intevation.flys.utils; + +import java.util.Comparator; + +public class EpsilonComparator implements Comparator<Double> +{ + public static final double EPSILON = 1e-4; + + public static final EpsilonComparator CMP = new EpsilonComparator(EPSILON); + + private double epsilon; + + public EpsilonComparator(double epsilon) { + this.epsilon = epsilon; + } + + @Override + public int compare(Double a, Double b) { + double diff = a - b; + if (diff < -epsilon) return -1; + if (diff > epsilon) return +1; + return 0; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :