# HG changeset patch # User Sascha L. Teichmann # Date 1357044848 -3600 # Node ID 94b39073f0f7c415c60e92298564cabbfd9f269f # Parent 0b4e1a4930451e7a02d3cb72497f37c895a1e22d 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. diff -r 0b4e1a493045 -r 94b39073f0f7 flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java --- 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> data = parser.getData(); + List lines = - new ArrayList(); + new ArrayList(data.size()); - for (Map.Entry> entry: parser.getData().entrySet()) { + for (Map.Entry> entry: data.entrySet()) { Double km = entry.getKey(); List points = entry.getValue(); lines.add(new ImportCrossSectionLine(km, points)); diff -r 0b4e1a493045 -r 94b39073f0f7 flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA50Parser.java --- 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> from files @@ -33,7 +35,7 @@ /** Trivial constructor. */ public DA50Parser() { - data = new TreeMap>(); + data = new TreeMap>(EpsilonComparator.CMP); } diff -r 0b4e1a493045 -r 94b39073f0f7 flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java --- 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>(); + data = new TreeMap>(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; diff -r 0b4e1a493045 -r 94b39073f0f7 flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java --- 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> from files @@ -55,7 +57,7 @@ /** Trivial constructor. */ public W80Parser() { - data = new TreeMap>(); + data = new TreeMap>(EpsilonComparator.CMP); } diff -r 0b4e1a493045 -r 94b39073f0f7 flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/EpsilonComparator.java --- 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 -{ - 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 : diff -r 0b4e1a493045 -r 94b39073f0f7 flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/TIMParser.java --- 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. diff -r 0b4e1a493045 -r 94b39073f0f7 flys-backend/src/main/java/de/intevation/flys/utils/EpsilonComparator.java --- /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 +{ + 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 :