Tidy up libcore.timezone APIs

Tidy up the libcore.timezone APIs to make them as close as possible to
android.timezone. In future, these classes should be repackages to be
the actual android.timezone classes, so the APIs need to be in sync.

Bug: 148086409
Test: treehugger
Change-Id: Ia8e903655a843baeb539febfd201132be94cf7b1
diff --git a/luni/src/main/java/libcore/timezone/CountryTimeZones.java b/luni/src/main/java/libcore/timezone/CountryTimeZones.java
index d0fa081..2e15d31 100644
--- a/luni/src/main/java/libcore/timezone/CountryTimeZones.java
+++ b/luni/src/main/java/libcore/timezone/CountryTimeZones.java
@@ -40,25 +40,33 @@
     @libcore.api.CorePlatformApi
     public static final class OffsetResult {
 
-        /** A zone that matches the supplied criteria. See also {@link #mOneMatch}. */
-        @libcore.api.CorePlatformApi
-        public final TimeZone mTimeZone;
+        /** A zone that matches the supplied criteria. See also {@link #isOnlyMatch}. */
+        private final TimeZone timeZone;
 
         /** True if there is one match for the supplied criteria */
-        @libcore.api.CorePlatformApi
-        public final boolean mOneMatch;
+        private final boolean isOnlyMatch;
 
-        public OffsetResult(TimeZone timeZone, boolean oneMatch) {
-            mTimeZone = java.util.Objects.requireNonNull(timeZone);
-            mOneMatch = oneMatch;
+        public OffsetResult(TimeZone timeZone, boolean isOnlyMatch) {
+            this.timeZone = java.util.Objects.requireNonNull(timeZone);
+            this.isOnlyMatch = isOnlyMatch;
+        }
+
+        @libcore.api.CorePlatformApi
+        public TimeZone getTimeZone() {
+            return timeZone;
+        }
+
+        @libcore.api.CorePlatformApi
+        public boolean isOnlyMatch() {
+            return isOnlyMatch;
         }
 
         @Override
         public String toString() {
-            return "Result{" +
-                    "mTimeZone='" + mTimeZone + '\'' +
-                    ", mOneMatch=" + mOneMatch +
-                    '}';
+            return "Result{"
+                    + "timeZone='" + timeZone + '\''
+                    + ", isOnlyMatch=" + isOnlyMatch
+                    + '}';
         }
     }
 
@@ -69,22 +77,34 @@
      */
     @libcore.api.CorePlatformApi
     public static final class TimeZoneMapping {
-        @libcore.api.CorePlatformApi
-        public final String timeZoneId;
-        @libcore.api.CorePlatformApi
-        public final boolean showInPicker;
-        @libcore.api.CorePlatformApi
-        public final Long notUsedAfter;
+        private final String timeZoneId;
+        private final boolean shownInPicker;
+        private final Long notUsedAfter;
 
         /** Memoized TimeZone object for {@link #timeZoneId}. */
         private TimeZone timeZone;
 
-        TimeZoneMapping(String timeZoneId, boolean showInPicker, Long notUsedAfter) {
+        TimeZoneMapping(String timeZoneId, boolean shownInPicker, Long notUsedAfter) {
             this.timeZoneId = Objects.requireNonNull(timeZoneId);
-            this.showInPicker = showInPicker;
+            this.shownInPicker = shownInPicker;
             this.notUsedAfter = notUsedAfter;
         }
 
+        @libcore.api.CorePlatformApi
+        public String getTimeZoneId() {
+            return timeZoneId;
+        }
+
+        @libcore.api.CorePlatformApi
+        public boolean isShownInPicker() {
+            return shownInPicker;
+        }
+
+        @libcore.api.CorePlatformApi
+        public Long getNotUsedAfter() {
+            return notUsedAfter;
+        }
+
         /**
          * Returns a {@link TimeZone} object for this mapping, or {@code null} if the ID is unknown.
          */
@@ -132,21 +152,21 @@
                 return false;
             }
             TimeZoneMapping that = (TimeZoneMapping) o;
-            return showInPicker == that.showInPicker &&
+            return shownInPicker == that.shownInPicker &&
                     Objects.equals(timeZoneId, that.timeZoneId) &&
                     Objects.equals(notUsedAfter, that.notUsedAfter);
         }
 
         @Override
         public int hashCode() {
-            return Objects.hash(timeZoneId, showInPicker, notUsedAfter);
+            return Objects.hash(timeZoneId, shownInPicker, notUsedAfter);
         }
 
         @Override
         public String toString() {
             return "TimeZoneMapping{"
                     + "timeZoneId='" + timeZoneId + '\''
-                    + ", showInPicker=" + showInPicker
+                    + ", shownInPicker=" + shownInPicker
                     + ", notUsedAfter=" + notUsedAfter
                     + '}';
         }
@@ -172,7 +192,7 @@
      * {@code true} indicates the default time zone for a country is a good choice if a time zone
      * cannot be determined by other means.
      */
-    private final boolean defaultTimeZoneBoost;
+    private final boolean defaultTimeZoneBoosted;
     private final List<TimeZoneMapping> timeZoneMappings;
     private final boolean everUsesUtc;
 
@@ -183,11 +203,11 @@
     private TimeZone defaultTimeZone;
 
     private CountryTimeZones(String countryIso, String defaultTimeZoneId,
-            boolean defaultTimeZoneBoost, boolean everUsesUtc,
+            boolean defaultTimeZoneBoosted, boolean everUsesUtc,
             List<TimeZoneMapping> timeZoneMappings) {
         this.countryIso = java.util.Objects.requireNonNull(countryIso);
         this.defaultTimeZoneId = defaultTimeZoneId;
-        this.defaultTimeZoneBoost = defaultTimeZoneBoost;
+        this.defaultTimeZoneBoosted = defaultTimeZoneBoosted;
         this.everUsesUtc = everUsesUtc;
         // Create a defensive copy of the mapping list.
         this.timeZoneMappings = Collections.unmodifiableList(new ArrayList<>(timeZoneMappings));
@@ -197,7 +217,7 @@
      * Creates a {@link CountryTimeZones} object containing only known time zone IDs.
      */
     public static CountryTimeZones createValidated(String countryIso, String defaultTimeZoneId,
-            boolean defaultTimeZoneBoost, boolean everUsesUtc,
+            boolean defaultTimeZoneBoosted, boolean everUsesUtc,
             List<TimeZoneMapping> timeZoneMappings, String debugInfo) {
 
         // We rely on ZoneInfoDB to tell us what the known valid time zone IDs are. ICU may
@@ -227,7 +247,7 @@
 
         String normalizedCountryIso = normalizeCountryIso(countryIso);
         return new CountryTimeZones(
-                normalizedCountryIso, defaultTimeZoneId, defaultTimeZoneBoost, everUsesUtc,
+                normalizedCountryIso, defaultTimeZoneId, defaultTimeZoneBoosted, everUsesUtc,
                 validCountryTimeZoneMappings);
     }
 
@@ -281,8 +301,8 @@
      * would be a good choice <em>generally</em> when there's no other information available.
      */
     @libcore.api.CorePlatformApi
-    public boolean getDefaultTimeZoneBoost() {
-        return defaultTimeZoneBoost;
+    public boolean isDefaultTimeZoneBoosted() {
+        return defaultTimeZoneBoosted;
     }
 
     /**
@@ -322,7 +342,7 @@
             return false;
         }
         CountryTimeZones that = (CountryTimeZones) o;
-        return defaultTimeZoneBoost == that.defaultTimeZoneBoost
+        return defaultTimeZoneBoosted == that.defaultTimeZoneBoosted
                 && everUsesUtc == that.everUsesUtc
                 && countryIso.equals(that.countryIso)
                 && Objects.equals(defaultTimeZoneId, that.defaultTimeZoneId)
@@ -332,10 +352,21 @@
     @Override
     public int hashCode() {
         return Objects.hash(
-                countryIso, defaultTimeZoneId, defaultTimeZoneBoost, timeZoneMappings,
+                countryIso, defaultTimeZoneId, defaultTimeZoneBoosted, timeZoneMappings,
                 everUsesUtc);
     }
 
+    @Override
+    public String toString() {
+        return "CountryTimeZones{"
+                + "countryIso='" + countryIso + '\''
+                + ", defaultTimeZoneId='" + defaultTimeZoneId + '\''
+                + ", defaultTimeZoneBoosted=" + defaultTimeZoneBoosted
+                + ", timeZoneMappings=" + timeZoneMappings
+                + ", everUsesUtc=" + everUsesUtc
+                + '}';
+    }
+
     /**
      * Returns true if the country has at least one zone that is the same as UTC at the given time.
      */
diff --git a/luni/src/main/java/libcore/timezone/TelephonyNetwork.java b/luni/src/main/java/libcore/timezone/TelephonyNetwork.java
index e5e5efb..e0f26ad 100644
--- a/luni/src/main/java/libcore/timezone/TelephonyNetwork.java
+++ b/luni/src/main/java/libcore/timezone/TelephonyNetwork.java
@@ -26,7 +26,7 @@
  * @hide
  */
 @libcore.api.CorePlatformApi
-public class TelephonyNetwork {
+public final class TelephonyNetwork {
 
     /**
      * A numeric network identifier consisting of the Mobile Country Code (MCC) and the Mobile
diff --git a/luni/src/main/java/libcore/timezone/TelephonyNetworkFinder.java b/luni/src/main/java/libcore/timezone/TelephonyNetworkFinder.java
index 3d09f7a..f244159 100644
--- a/luni/src/main/java/libcore/timezone/TelephonyNetworkFinder.java
+++ b/luni/src/main/java/libcore/timezone/TelephonyNetworkFinder.java
@@ -34,7 +34,7 @@
  * @hide
  */
 @libcore.api.CorePlatformApi
-public class TelephonyNetworkFinder {
+public final class TelephonyNetworkFinder {
 
     private final Map<MccMnc, TelephonyNetwork> networksMap;
     private final List<TelephonyNetwork> networksList;
diff --git a/luni/src/main/java/libcore/timezone/TzDataSetVersion.java b/luni/src/main/java/libcore/timezone/TzDataSetVersion.java
index a404551..8b97069b 100644
--- a/luni/src/main/java/libcore/timezone/TzDataSetVersion.java
+++ b/luni/src/main/java/libcore/timezone/TzDataSetVersion.java
@@ -29,7 +29,7 @@
  * @hide
  */
 @libcore.api.CorePlatformApi
-public class TzDataSetVersion {
+public final class TzDataSetVersion {
 
     // Remove from CorePlatformApi when all users in platform code are removed. http://b/123398797
     /**
@@ -102,18 +102,10 @@
                     + REVISION_PATTERN.pattern()
                     + ".*" /* ignore trailing */);
 
-    @libcore.api.CorePlatformApi
-    public final int formatMajorVersion;
-
-    @libcore.api.CorePlatformApi
-    public final int formatMinorVersion;
-
-    // Remove from CorePlatformApi when all users in platform code are removed. http://b/123398797
-    @libcore.api.CorePlatformApi
-    public final String rulesVersion;
-
-    @libcore.api.CorePlatformApi
-    public final int revision;
+    private final int formatMajorVersion;
+    private final int formatMinorVersion;
+    private final String rulesVersion;
+    private final int revision;
 
     @libcore.api.CorePlatformApi
     public TzDataSetVersion(int formatMajorVersion, int formatMinorVersion, String rulesVersion,
@@ -170,6 +162,27 @@
         return readFromFile(new File(tzVersionFileName));
     }
 
+    @libcore.api.CorePlatformApi
+    public int getFormatMajorVersion() {
+        return formatMajorVersion;
+    }
+
+    @libcore.api.CorePlatformApi
+    public int getFormatMinorVersion() {
+        return formatMinorVersion;
+    }
+
+    @libcore.api.CorePlatformApi
+    public String getRulesVersion() {
+        return rulesVersion;
+    }
+
+    // Remove from CorePlatformApi when all users in platform code are removed. http://b/123398797
+    @libcore.api.CorePlatformApi
+    public int getRevision() {
+        return revision;
+    }
+
     // Remove from CorePlatformApi when all users in platform code are removed. http://b/123398797
     @libcore.api.CorePlatformApi
     public byte[] toBytes() {
diff --git a/luni/src/main/java/libcore/util/CoreLibraryDebug.java b/luni/src/main/java/libcore/util/CoreLibraryDebug.java
index dc1012f..a488b70 100644
--- a/luni/src/main/java/libcore/util/CoreLibraryDebug.java
+++ b/luni/src/main/java/libcore/util/CoreLibraryDebug.java
@@ -83,14 +83,14 @@
             try {
                 TzDataSetVersion tzDataSetVersion =
                         TzDataSetVersion.readFromFile(file);
-                String formatVersionString = tzDataSetVersion.formatMajorVersion + "."
-                        + tzDataSetVersion.formatMinorVersion;
+                String formatVersionString = tzDataSetVersion.getFormatMajorVersion() + "."
+                        + tzDataSetVersion.getFormatMinorVersion();
                 debugInfo.addStringEntry(statusKey, "OK")
                         .addStringEntry(debugKeyPrefix + "formatVersion", formatVersionString)
                         .addStringEntry(debugKeyPrefix + "rulesVersion",
-                                tzDataSetVersion.rulesVersion)
+                                tzDataSetVersion.getRulesVersion())
                         .addStringEntry(debugKeyPrefix + "revision",
-                                tzDataSetVersion.revision);
+                                tzDataSetVersion.getRevision());
             } catch (IOException | TzDataSetException e) {
                 debugInfo.addStringEntry(statusKey, "ERROR");
                 debugInfo.addStringEntry(debugKeyPrefix + "exception_class", e.getClass().getName());
diff --git a/luni/src/test/java/libcore/libcore/icu/TimeZoneIntegrationTest.java b/luni/src/test/java/libcore/libcore/icu/TimeZoneIntegrationTest.java
index 9593caa..043cce7 100644
--- a/luni/src/test/java/libcore/libcore/icu/TimeZoneIntegrationTest.java
+++ b/luni/src/test/java/libcore/libcore/icu/TimeZoneIntegrationTest.java
@@ -247,9 +247,9 @@
         TzDataSetVersion actualVersion = TzDataSetVersion.readFromFile(new File(versionFile));
         assertEquals(
                 TzDataSetVersion.currentFormatMajorVersion(),
-                actualVersion.formatMajorVersion);
+                actualVersion.getFormatMajorVersion());
         int minDeviceMinorVersion = TzDataSetVersion.currentFormatMinorVersion();
-        assertTrue(actualVersion.formatMinorVersion >= minDeviceMinorVersion);
+        assertTrue(actualVersion.getFormatMinorVersion() >= minDeviceMinorVersion);
     }
 
     /**
diff --git a/luni/src/test/java/libcore/libcore/timezone/CountryTimeZonesTest.java b/luni/src/test/java/libcore/libcore/timezone/CountryTimeZonesTest.java
index 1b9aad0..1948b7dd 100644
--- a/luni/src/test/java/libcore/libcore/timezone/CountryTimeZonesTest.java
+++ b/luni/src/test/java/libcore/libcore/timezone/CountryTimeZonesTest.java
@@ -376,7 +376,7 @@
                         x -> x == null ? "null" : x.getID();
                 Function<OffsetResult, String> offsetResultFormatter =
                         x -> x == null ? "null"
-                                : "{" + x.mTimeZone.getID() + ", " + x.mOneMatch + "}";
+                                : "{" + x.getTimeZone().getID() + ", " + x.isOnlyMatch() + "}";
                 failures.add("Fail: case=" + i
                         + ", totalOffsetMillis=" + totalOffsetMillis
                         + ", isDst=" + isDst
@@ -540,8 +540,8 @@
     private static boolean offsetResultEquals(OffsetResult expected, OffsetResult actual) {
         return expected == actual
                 || (expected != null && actual != null
-                && Objects.equals(expected.mTimeZone.getID(), actual.mTimeZone.getID())
-                && expected.mOneMatch == actual.mOneMatch);
+                && Objects.equals(expected.getTimeZone().getID(), actual.getTimeZone().getID())
+                && expected.isOnlyMatch() == actual.isOnlyMatch());
     }
 
     /**
diff --git a/luni/src/test/java/libcore/libcore/timezone/TimeZoneFinderTest.java b/luni/src/test/java/libcore/libcore/timezone/TimeZoneFinderTest.java
index 805b2ca..ef07371 100644
--- a/luni/src/test/java/libcore/libcore/timezone/TimeZoneFinderTest.java
+++ b/luni/src/test/java/libcore/libcore/timezone/TimeZoneFinderTest.java
@@ -432,7 +432,7 @@
                 + "  </countryzones>\n"
                 + "</timezones>\n");
         CountryTimeZones countryTimeZones = finder.lookupCountryTimeZones("gb");
-        assertTrue(countryTimeZones.getDefaultTimeZoneBoost());
+        assertTrue(countryTimeZones.isDefaultTimeZoneBoosted());
     }
 
     @Test
diff --git a/luni/src/test/java/libcore/libcore/timezone/TzDataSetVersionTest.java b/luni/src/test/java/libcore/libcore/timezone/TzDataSetVersionTest.java
index 75e079b..a653301 100644
--- a/luni/src/test/java/libcore/libcore/timezone/TzDataSetVersionTest.java
+++ b/luni/src/test/java/libcore/libcore/timezone/TzDataSetVersionTest.java
@@ -55,10 +55,10 @@
 
     public void testConstructor() throws Exception {
         TzDataSetVersion distroVersion = new TzDataSetVersion(1, 2, VALID_RULES_VERSION, 3);
-        assertEquals(1, distroVersion.formatMajorVersion);
-        assertEquals(2, distroVersion.formatMinorVersion);
-        assertEquals(VALID_RULES_VERSION, distroVersion.rulesVersion);
-        assertEquals(3, distroVersion.revision);
+        assertEquals(1, distroVersion.getFormatMajorVersion());
+        assertEquals(2, distroVersion.getFormatMinorVersion());
+        assertEquals(VALID_RULES_VERSION, distroVersion.getRulesVersion());
+        assertEquals(3, distroVersion.getRevision());
     }
 
     public void testToFromBytesRoundTrip() throws Exception {
diff --git a/mmodules/core_platform_api/api/platform/current-api.txt b/mmodules/core_platform_api/api/platform/current-api.txt
index 0560a6e..04c4d90 100644
--- a/mmodules/core_platform_api/api/platform/current-api.txt
+++ b/mmodules/core_platform_api/api/platform/current-api.txt
@@ -1098,26 +1098,26 @@
   public final class CountryTimeZones {
     method public String getCountryIso();
     method public android.icu.util.TimeZone getDefaultTimeZone();
-    method public boolean getDefaultTimeZoneBoost();
     method public String getDefaultTimeZoneId();
     method public java.util.List<libcore.timezone.CountryTimeZones.TimeZoneMapping> getEffectiveTimeZoneMappingsAt(long);
     method public java.util.List<libcore.timezone.CountryTimeZones.TimeZoneMapping> getTimeZoneMappings();
     method public boolean hasUtcZone(long);
+    method public boolean isDefaultTimeZoneBoosted();
     method public boolean isForCountryCode(String);
     method public libcore.timezone.CountryTimeZones.OffsetResult lookupByOffsetWithBias(int, Boolean, Integer, long, android.icu.util.TimeZone);
   }
 
   public static final class CountryTimeZones.OffsetResult {
-    field public final boolean mOneMatch;
-    field public final android.icu.util.TimeZone mTimeZone;
+    method public android.icu.util.TimeZone getTimeZone();
+    method public boolean isOnlyMatch();
   }
 
   public static final class CountryTimeZones.TimeZoneMapping {
     method public static libcore.timezone.CountryTimeZones.TimeZoneMapping createForTests(String, boolean, Long);
+    method public Long getNotUsedAfter();
     method public android.icu.util.TimeZone getTimeZone();
-    field public final Long notUsedAfter;
-    field public final boolean showInPicker;
-    field public final String timeZoneId;
+    method public String getTimeZoneId();
+    method public boolean isShownInPicker();
   }
 
   public final class CountryZonesFinder {
@@ -1133,13 +1133,13 @@
     method public void validate() throws java.io.IOException;
   }
 
-  public class TelephonyNetwork {
+  public final class TelephonyNetwork {
     method public String getCountryIsoCode();
     method public String getMcc();
     method public String getMnc();
   }
 
-  public class TelephonyNetworkFinder {
+  public final class TelephonyNetworkFinder {
     method public libcore.timezone.TelephonyNetwork findNetworkByMccMnc(String, String);
   }
 
@@ -1158,19 +1158,19 @@
     method public void validate() throws java.io.IOException;
   }
 
-  public class TzDataSetVersion {
+  public final class TzDataSetVersion {
     ctor public TzDataSetVersion(int, int, String, int) throws libcore.timezone.TzDataSetVersion.TzDataSetException;
     method public static int currentFormatMajorVersion();
     method public static int currentFormatMinorVersion();
+    method public int getFormatMajorVersion();
+    method public int getFormatMinorVersion();
+    method public int getRevision();
+    method public String getRulesVersion();
     method public static boolean isCompatibleWithThisDevice(libcore.timezone.TzDataSetVersion);
     method public static libcore.timezone.TzDataSetVersion readFromFile(java.io.File) throws java.io.IOException, libcore.timezone.TzDataSetVersion.TzDataSetException;
     method public static libcore.timezone.TzDataSetVersion readTimeZoneModuleVersion() throws java.io.IOException, libcore.timezone.TzDataSetVersion.TzDataSetException;
     method public byte[] toBytes();
     field public static final String DEFAULT_FILE_NAME = "tz_version";
-    field public final int formatMajorVersion;
-    field public final int formatMinorVersion;
-    field public final int revision;
-    field public final String rulesVersion;
   }
 
   public static class TzDataSetVersion.TzDataSetException extends java.lang.Exception {