From 410173fcc019bf387859c799bb73bedf54ffe718 Mon Sep 17 00:00:00 2001 From: bclayton-usgs <bclayton@usgs.gov> Date: Tue, 17 Mar 2020 08:06:55 -0600 Subject: [PATCH] switch to EnumMap --- .../nshmp/netcdf/reader/StaticHazard.java | 15 +++++++++------ .../nshmp/netcdf/reader/StaticHazards.java | 16 +++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/StaticHazard.java b/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/StaticHazard.java index 28dc0f0..fa202d9 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/StaticHazard.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/StaticHazard.java @@ -2,18 +2,21 @@ package gov.usgs.earthquake.nshmp.netcdf.reader; import static com.google.common.base.Preconditions.checkState; -import java.util.HashMap; +import java.util.EnumMap; import java.util.Map; import gov.usgs.earthquake.nshmp.data.XySequence; import gov.usgs.earthquake.nshmp.gmm.Imt; @SuppressWarnings("serial") -public class StaticHazard extends HashMap<Imt, XySequence> { +public class StaticHazard extends EnumMap<Imt, XySequence> { - public StaticHazard() {} + public StaticHazard() { + super(Imt.class); + } - private StaticHazard(Map<Imt, XySequence> staticHazard) { + private StaticHazard(EnumMap<Imt, XySequence> staticHazard) { + super(Imt.class); putAll(staticHazard); } @@ -26,10 +29,10 @@ public class StaticHazard extends HashMap<Imt, XySequence> { } public static class Builder { - Map<Imt, XySequence> staticHazard; + EnumMap<Imt, XySequence> staticHazard; private Builder() { - staticHazard = new HashMap<>(); + staticHazard = new EnumMap<>(Imt.class); } public Builder put(Imt imt, XySequence xySequence) { diff --git a/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/StaticHazards.java b/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/StaticHazards.java index 0bba7f0..a634c22 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/StaticHazards.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/netcdf/reader/StaticHazards.java @@ -2,17 +2,19 @@ package gov.usgs.earthquake.nshmp.netcdf.reader; import static com.google.common.base.Preconditions.checkState; -import java.util.HashMap; -import java.util.Map; +import java.util.EnumMap; import gov.usgs.earthquake.nshmp.netcdf.SiteClass; @SuppressWarnings("serial") -public class StaticHazards extends HashMap<SiteClass, StaticHazard> { +public class StaticHazards extends EnumMap<SiteClass, StaticHazard> { - public StaticHazards() {} + public StaticHazards() { + super(SiteClass.class); + } - private StaticHazards(Map<SiteClass, StaticHazard> staticHazards) { + private StaticHazards(EnumMap<SiteClass, StaticHazard> staticHazards) { + super(SiteClass.class); this.putAll(staticHazards); } @@ -21,10 +23,10 @@ public class StaticHazards extends HashMap<SiteClass, StaticHazard> { } public static class Builder { - Map<SiteClass, StaticHazard> staticHazards; + EnumMap<SiteClass, StaticHazard> staticHazards; private Builder() { - staticHazards = new HashMap<>(); + staticHazards = new EnumMap<>(SiteClass.class); } public Builder put(SiteClass siteClass, StaticHazard staticHazard) { -- GitLab