From 7882ac1b4460fd6b89edfb07b535049ea67c4491 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Thu, 31 Oct 2024 13:30:02 -0600
Subject: [PATCH 1/4] remove method

---
 .../gov/usgs/earthquake/nshmp/www/ServletUtil.java | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/ServletUtil.java b/src/main/java/gov/usgs/earthquake/nshmp/www/ServletUtil.java
index 23f3917b..18bd5407 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/www/ServletUtil.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/www/ServletUtil.java
@@ -28,10 +28,8 @@ import com.google.gson.JsonSerializer;
 
 import gov.usgs.earthquake.nshmp.calc.Site;
 import gov.usgs.earthquake.nshmp.calc.ValueFormat;
-import gov.usgs.earthquake.nshmp.geo.Location;
 import gov.usgs.earthquake.nshmp.gmm.Imt;
 import gov.usgs.earthquake.nshmp.model.HazardModel;
-import gov.usgs.earthquake.nshmp.model.SiteData;
 import gov.usgs.earthquake.nshmp.www.meta.MetaUtil;
 
 import io.micronaut.context.annotation.Value;
@@ -189,18 +187,6 @@ public class ServletUtil {
     return new Server(threads, timer);
   }
 
-  public static Site createSite(Location location, double vs30, SiteData siteData) {
-    Site.Builder builder = Site.builder()
-        .location(location)
-        .vs30(vs30);
-    SiteData.Values sdValues = siteData.get(location);
-    sdValues.z1p0.ifPresent(builder::z1p0);
-    sdValues.z2p5.ifPresent(builder::z2p5);
-    sdValues.zSed.ifPresent(builder::zSed);
-    builder.gmmTrees(sdValues.gmmTrees);
-    return builder.build();
-  }
-
   public static class Server {
 
     final int threads;
-- 
GitLab


From e08a523b73764203bcc1ecbdda5c19aa34314ce3 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Thu, 31 Oct 2024 13:30:19 -0600
Subject: [PATCH 2/4] use new method

---
 .../gov/usgs/earthquake/nshmp/www/hazard/DisaggService.java | 6 ++++--
 .../gov/usgs/earthquake/nshmp/www/hazard/HazardService.java | 4 +++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/hazard/DisaggService.java b/src/main/java/gov/usgs/earthquake/nshmp/www/hazard/DisaggService.java
index 5f1d223f..a0bdb002 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/www/hazard/DisaggService.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/www/hazard/DisaggService.java
@@ -8,6 +8,7 @@ import static java.util.stream.Collectors.toList;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.OptionalDouble;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.concurrent.CompletableFuture;
@@ -27,6 +28,7 @@ import gov.usgs.earthquake.nshmp.calc.Disaggregation;
 import gov.usgs.earthquake.nshmp.calc.Hazard;
 import gov.usgs.earthquake.nshmp.calc.HazardCalcs;
 import gov.usgs.earthquake.nshmp.calc.Site;
+import gov.usgs.earthquake.nshmp.calc.Sites;
 import gov.usgs.earthquake.nshmp.geo.Location;
 import gov.usgs.earthquake.nshmp.gmm.Gmm;
 import gov.usgs.earthquake.nshmp.gmm.Imt;
@@ -147,7 +149,7 @@ public final class DisaggService {
         .build();
 
     Location loc = Location.create(request.longitude, request.latitude);
-    Site site = ServletUtil.createSite(loc, request.vs30, model.siteData());
+    Site site = Sites.locationToSite(loc, model.siteData(), OptionalDouble.of(request.vs30));
 
     // use HazardService.calcHazard() instead?
     CompletableFuture<Hazard> hazFuture = CompletableFuture.supplyAsync(
@@ -180,7 +182,7 @@ public final class DisaggService {
         .build();
 
     Location loc = Location.create(request.longitude, request.latitude);
-    Site site = ServletUtil.createSite(loc, request.vs30, model.siteData());
+    Site site = Sites.locationToSite(loc, model.siteData(), OptionalDouble.of(request.vs30));
 
     // could just get from HazardService
     CompletableFuture<Hazard> hazFuture = CompletableFuture.supplyAsync(
diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/hazard/HazardService.java b/src/main/java/gov/usgs/earthquake/nshmp/www/hazard/HazardService.java
index c6ba8adf..42830d66 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/www/hazard/HazardService.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/www/hazard/HazardService.java
@@ -12,6 +12,7 @@ import java.util.EnumMap;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
+import java.util.OptionalDouble;
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
@@ -26,6 +27,7 @@ import gov.usgs.earthquake.nshmp.calc.DataType;
 import gov.usgs.earthquake.nshmp.calc.Hazard;
 import gov.usgs.earthquake.nshmp.calc.HazardCalcs;
 import gov.usgs.earthquake.nshmp.calc.Site;
+import gov.usgs.earthquake.nshmp.calc.Sites;
 import gov.usgs.earthquake.nshmp.data.MutableXySequence;
 import gov.usgs.earthquake.nshmp.data.XySequence;
 import gov.usgs.earthquake.nshmp.geo.Location;
@@ -114,7 +116,7 @@ public final class HazardService {
         .build();
 
     Location loc = Location.create(request.longitude, request.latitude);
-    Site site = ServletUtil.createSite(loc, request.vs30, model.siteData());
+    Site site = Sites.locationToSite(loc, model.siteData(), OptionalDouble.of(request.vs30));
 
     CompletableFuture<Hazard> future = CompletableFuture.supplyAsync(
         () -> HazardCalcs.hazard(
-- 
GitLab


From 58e11b2200b2670fa173e1de5943649317f3d71d Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Thu, 31 Oct 2024 13:30:26 -0600
Subject: [PATCH 3/4] use new method

---
 .../earthquake/nshmp/model/NshmTestUtils.java   | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java b/src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
index 89852afa..cd30056e 100644
--- a/src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
+++ b/src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
@@ -15,6 +15,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
+import java.util.OptionalDouble;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -35,6 +36,7 @@ import gov.usgs.earthquake.nshmp.calc.CalcConfig;
 import gov.usgs.earthquake.nshmp.calc.Hazard;
 import gov.usgs.earthquake.nshmp.calc.HazardCalcs;
 import gov.usgs.earthquake.nshmp.calc.Site;
+import gov.usgs.earthquake.nshmp.calc.Sites;
 import gov.usgs.earthquake.nshmp.data.XySequence;
 import gov.usgs.earthquake.nshmp.geo.Location;
 import gov.usgs.earthquake.nshmp.gmm.Imt;
@@ -220,9 +222,10 @@ class NshmTestUtils {
       NshmModel nshmModel,
       NamedLocation location) {
 
-    Site site = createSite(
+    Site site = Sites.locationToSite(
         location.location(),
-        nshmModel.model.siteData());
+        nshmModel.model.siteData(),
+        OptionalDouble.empty());
 
     CalcConfig config = CalcConfig.copyOf(nshmModel.model.config())
         .imts(nshmModel.nshm.imts())
@@ -279,16 +282,6 @@ class NshmTestUtils {
     Files.write(resultPath, json.getBytes());
   }
 
-  private static Site createSite(Location loc, SiteData siteData) {
-    Site.Builder builder = Site.builder().location(loc);
-    SiteData.Values values = siteData.get(loc);
-    values.z1p0.ifPresent(builder::z1p0);
-    values.z2p5.ifPresent(builder::z2p5);
-    values.zSed.ifPresent(builder::zSed);
-    builder.gmmTrees(values.gmmTrees);
-    return builder.build();
-  }
-
   private static class Curve {
     double[] xs;
     double[] ys;
-- 
GitLab


From 640aa8990ffc5109d13e1891cd42793dba236d7d Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Thu, 31 Oct 2024 13:30:49 -0600
Subject: [PATCH 4/4] spotless apply

---
 src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java b/src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
index cd30056e..656649be 100644
--- a/src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
+++ b/src/test/java/gov/usgs/earthquake/nshmp/model/NshmTestUtils.java
@@ -38,7 +38,6 @@ import gov.usgs.earthquake.nshmp.calc.HazardCalcs;
 import gov.usgs.earthquake.nshmp.calc.Site;
 import gov.usgs.earthquake.nshmp.calc.Sites;
 import gov.usgs.earthquake.nshmp.data.XySequence;
-import gov.usgs.earthquake.nshmp.geo.Location;
 import gov.usgs.earthquake.nshmp.gmm.Imt;
 import gov.usgs.earthquake.nshmp.www.Application;
 import gov.usgs.earthquake.nshmp.www.hazard.HazardServiceUtils;
-- 
GitLab