diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/EqRateExport.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/EqRateExport.java index 4ee830ad09f7ed50866afceea181c7f4753f7fc3..8b6ab14c2d40a4a920b0ef50e3f0ccc157729f06 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/EqRateExport.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/EqRateExport.java @@ -6,15 +6,13 @@ import static java.nio.file.StandardOpenOption.APPEND; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.DoubleStream; -import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.primitives.Doubles; import gov.usgs.earthquake.nshmp.Text; import gov.usgs.earthquake.nshmp.data.XySequence; @@ -87,7 +85,7 @@ public final class EqRateExport { */ public void write(EqRate rate) throws IOException { - Iterable<Double> emptyValues = Doubles.asList(new double[rate.totalMfd.size()]); + double[] emptyValues = new double[rate.totalMfd.size()]; Function<Double, String> formatter = Text.formatDoubleFunction(valueFormat); /* Can't init output until we have a demo rate record for mfd x-values */ @@ -97,16 +95,15 @@ public final class EqRateExport { } String name = namedSites ? rate.site.name() : null; - Location location = rate.site.location(); + Location loc = rate.site.location(); - List<String> locData = Lists.newArrayList( - name, - String.format("%.5f", location.longitude), - String.format("%.5f", location.latitude)); + String locStr = name + "," + + String.format("%.5f", loc.longitude) + "," + + String.format("%.5f", loc.latitude); - String totalLine = toLine(locData, rate.totalMfd.yValues(), formatter); - - String emptyLine = toLine(locData, emptyValues, formatter); + double[] values = rate.totalMfd.yValues().toArray(); + String totalLine = toLine(locStr, values, formatter); + String emptyLine = toLine(locStr, emptyValues, formatter); /* write/append */ Path totalFile = out.resolve(file); @@ -118,7 +115,7 @@ public final class EqRateExport { String typeLine = emptyLine; if (rate.typeMfds.containsKey(type)) { XySequence typeRate = rate.typeMfds.get(type); - typeLine = toLine(locData, typeRate.yValues(), formatter); + typeLine = toLine(locStr, typeRate.yValues().toArray(), formatter); } HazardExport.writeLine(typeFile, typeLine, APPEND); } @@ -146,23 +143,12 @@ public final class EqRateExport { } private static String toLine( - Iterable<String> location, - Iterable<Double> values, + String locStr, + double[] values, Function<Double, String> formatter) { - return COMMA.joiner().join( - FluentIterable.from(location) - .append(Iterables.transform( - values, - formatter::apply))); - } - - private static String toLine( - Iterable<String> location, - DoubleStream stream, - Function<Double, String> formatter) { - List<Double> values = stream.boxed().collect(Collectors.toList()); - return toLine(location, values, formatter); + StringBuilder sb = new StringBuilder(locStr); + Arrays.stream(values).forEach(v -> sb.append("," + v)); + return sb.toString(); } - } diff --git a/src/main/java/gov/usgs/earthquake/nshmp/gmm/GroundMotionTables.java b/src/main/java/gov/usgs/earthquake/nshmp/gmm/GroundMotionTables.java index cbbacd803afca8a09229f89fea8a7f7f7ca51471..ac7eadd0529ced96e6e7b69bb3755139e7547c9e 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/gmm/GroundMotionTables.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/gmm/GroundMotionTables.java @@ -13,6 +13,7 @@ import static gov.usgs.earthquake.nshmp.gmm.Imt.SA0P3; import static gov.usgs.earthquake.nshmp.gmm.Imt.SA3P0; import static java.lang.Math.log10; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.stream.Collectors.toList; import java.io.IOException; import java.net.URL; @@ -24,18 +25,14 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.function.Function; import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.DoubleStream; -import com.google.common.base.Enums; -import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.io.LineProcessor; -import com.google.common.primitives.Doubles; import gov.usgs.earthquake.nshmp.Text; import gov.usgs.earthquake.nshmp.data.DoubleData; @@ -293,11 +290,10 @@ final class GroundMotionTables { URL url = getResource(TABLE_DIR + filename); try { List<String> lines = readLines(url, UTF_8); - List<Imt> imts = FluentIterable - .from(COMMA.splitter().splitToList(lines.get(0))) + List<Imt> imts = COMMA.splitter().splitToStream(lines.get(0)) .skip(1) - .transform(Enums.stringConverter(Imt.class)) - .toList(); + .map(Imt::valueOf) + .collect(toList()); for (Imt imt : imts) { map.put(imt, new double[NGA_EAST_MODEL_COUNT]); } @@ -768,12 +764,11 @@ final class GroundMotionTables { } if (lineIndex == 2) { - List<Imt> imtList = FluentIterable - .from(SPACE.splitter().split(line)) - .transform(Doubles.stringConverter()) - .transform(new FrequencyToIMT()::apply) - .toList(); - // remove dupes -- (e.g., 2s PGA columns in P11) + List<Imt> imtList = SPACE.splitter().splitToStream(line) + .map(Double::valueOf) + .map(GroundMotionTables::frequencyToImt) + .collect(toList()); + // remove dupes -- (e.g. PGA columns in P11) imts = Lists.newArrayList(new LinkedHashSet<Imt>(imtList)); for (Imt imt : imts) { List<List<Double>> outerList = new ArrayList<List<Double>>(); // r @@ -815,26 +810,23 @@ final class GroundMotionTables { * and handled independently. AB06 uses 0.32, 3.2, and 32 which do not * strictly correspond to 3s, 0.3s, and 0.03s, but we use them anyway. */ - static class FrequencyToIMT implements Function<Double, Imt> { - @Override - public Imt apply(Double f) { - if (FREQ3_LO.contains(f)) { - return SA3P0; - } - if (FREQ3_MID.contains(f)) { - return SA0P3; - } - if (FREQ3_HI.contains(f)) { - return SA0P03; - } - if (f == 99.0) { - return PGA; - } - if (f == 89.0) { - return PGV; - } - return Imt.fromPeriod(1.0 / f); + static Imt frequencyToImt(Double f) { + if (FREQ3_LO.contains(f)) { + return SA3P0; + } + if (FREQ3_MID.contains(f)) { + return SA0P3; + } + if (FREQ3_HI.contains(f)) { + return SA0P03; + } + if (f == 99.0) { + return PGA; + } + if (f == 89.0) { + return PGV; } + return Imt.fromPeriod(1.0 / f); } private static double[][] toArray(List<List<Double>> data) {