1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.libcore.timezone.tzlookup.zonetree; 17 18 import java.time.Instant; 19 import java.util.HashMap; 20 import java.util.Map; 21 22 /** 23 * A record for a country of when zones stopped being (effectively) used. 24 */ 25 public final class CountryZoneUsage { 26 private final String isoCode; 27 private final Map<String, Entry> zoneIdEntryMap = new HashMap<>(); 28 CountryZoneUsage(String isoCode)29 public CountryZoneUsage(String isoCode) { 30 this.isoCode = isoCode; 31 } 32 getIsoCode()33 public String getIsoCode() { 34 return isoCode; 35 } 36 addEntry(String zoneId, Instant notUsedAfterInstant)37 void addEntry(String zoneId, Instant notUsedAfterInstant) { 38 if (zoneIdEntryMap.containsKey(zoneId)) { 39 throw new IllegalArgumentException( 40 "Entry exists for " + zoneId + " for isoCode=" + isoCode); 41 } 42 zoneIdEntryMap.put(zoneId, new Entry(zoneId, notUsedAfterInstant)); 43 } 44 hasEntry(String zoneId)45 public boolean hasEntry(String zoneId) { 46 return zoneIdEntryMap.containsKey(zoneId); 47 } 48 getNotUsedAfterInstant(String zoneId)49 public Instant getNotUsedAfterInstant(String zoneId) { 50 Entry entry = zoneIdEntryMap.get(zoneId); 51 if (entry == null) { 52 throw new IllegalArgumentException( 53 "No entry for " + zoneId+ " for isoCode=" + isoCode); 54 } 55 return entry.notUsedAfter; 56 } 57 58 private static class Entry { 59 final String zoneId; 60 final Instant notUsedAfter; 61 Entry(String zoneId, Instant notUsedAfter)62 Entry(String zoneId, Instant notUsedAfter) { 63 this.zoneId = zoneId; 64 this.notUsedAfter = notUsedAfter; 65 } 66 } 67 } 68