# HG changeset patch # User Felix Wolfsteller # Date 1358939447 -3600 # Node ID c9a27912840d783dd92275bfe34e7b088b3088d2 # Parent f86c8d75fd85c5bdaf959da5cc6e586c7d474ece RangeAccess: Add accidentally omitted implementation of getLocations from FLYSUtils. diff -r f86c8d75fd85 -r c9a27912840d flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/RangeAccess.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/RangeAccess.java Wed Jan 23 10:43:27 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/RangeAccess.java Wed Jan 23 12:10:47 2013 +0100 @@ -2,10 +2,15 @@ import org.apache.log4j.Logger; +import gnu.trove.TDoubleArrayList; + import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.WINFOArtifact; + import de.intevation.flys.utils.FLYSUtils; + /** For the moment, light-weight wrapper around FLYSUtils. */ // TODO employ 'Caching' like other Accesses, remove usage of FLYSUtils. public class RangeAccess @@ -28,6 +33,45 @@ } + /** + * Return sorted array of locations at which stuff was calculated + * (from ld_locations data), null if not parameterized this way. + */ + public double[] getLocations() { + String locationStr = getString("ld_locations"); + + if (locationStr == null || locationStr.length() == 0) { + if (getArtifact() instanceof WINFOArtifact) { + WINFOArtifact winfo = (WINFOArtifact) getArtifact(); + if (winfo.getReferenceStartKm() != null && winfo.getReferenceEndKms() != null) { + return new double[] + { + winfo.getReferenceStartKm().doubleValue(), + winfo.getReferenceEndKms()[0] + }; + } + } + return null; + } + + String[] tmp = locationStr.split(" "); + TDoubleArrayList locations = new TDoubleArrayList(); + + for (String l: tmp) { + try { + locations.add(Double.parseDouble(l)); + } + catch (NumberFormatException nfe) { + logger.debug(nfe.getLocalizedMessage(), nfe); + } + } + + locations.sort(); + + return locations.toNativeArray(); + } + + /** Return ld_from data (in km). */ public double getFrom() { if (from == null) { @@ -83,14 +127,5 @@ public double[] getKmFromTo() { return FLYSUtils.getKmFromTo(this.getArtifact()); } - - - /** - * Return sorted array of locations at which stuff was calculated - * (from ld_locations data), null if not parameterized this way. - */ - public double[] getLocations() { - return FLYSUtils.getLocations(this.getArtifact()); - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :