diff --git a/classlib/src/main/java/org/threeten/bp/ZoneOffset.java b/classlib/src/main/java/org/threeten/bp/ZoneOffset.java index 4b3112723..a3e2c6b9e 100644 --- a/classlib/src/main/java/org/threeten/bp/ZoneOffset.java +++ b/classlib/src/main/java/org/threeten/bp/ZoneOffset.java @@ -39,8 +39,8 @@ import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectStreamException; import java.io.Serializable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; +import java.util.HashMap; +import java.util.Map; import org.threeten.bp.jdk8.Jdk8Methods; import org.threeten.bp.temporal.ChronoField; @@ -101,9 +101,9 @@ public final class ZoneOffset }; /** Cache of time-zone offset by offset in seconds. */ - private static final ConcurrentMap SECONDS_CACHE = new ConcurrentHashMap(16, 0.75f, 4); + private static final Map SECONDS_CACHE = new HashMap<>(); /** Cache of time-zone offset by ID. */ - private static final ConcurrentMap ID_CACHE = new ConcurrentHashMap(16, 0.75f, 4); + private static final Map ID_CACHE = new HashMap<>(); /** * The number of seconds per hour. diff --git a/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java b/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java index c6a62efab..af6c57573 100644 --- a/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java +++ b/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java @@ -36,15 +36,13 @@ import java.io.DataOutput; import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectStreamException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.ServiceLoader; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import org.threeten.bp.Clock; import org.threeten.bp.DateTimeException; @@ -153,24 +151,11 @@ public abstract class Chronology implements Comparable { /** * Map of available calendars by ID. */ - private static final ConcurrentHashMap CHRONOS_BY_ID = new ConcurrentHashMap(); + private static final Map CHRONOS_BY_ID = new HashMap<>(); /** * Map of available calendars by calendar type. */ - private static final ConcurrentHashMap CHRONOS_BY_TYPE = new ConcurrentHashMap(); - /** - * Access JDK 7 method if on JDK 7. - */ - private static final Method LOCALE_METHOD; - static { - Method method = null; - try { - method = Locale.class.getMethod("getUnicodeLocaleType", String.class); - } catch (Throwable ex) { - // ignore - } - LOCALE_METHOD = method; - } + private static final Map CHRONOS_BY_TYPE = new HashMap<>(); //----------------------------------------------------------------------- /** @@ -240,18 +225,7 @@ public abstract class Chronology implements Comparable { init(); Jdk8Methods.requireNonNull(locale, "locale"); String type = "iso"; - if (LOCALE_METHOD != null) { - // JDK 7: locale.getUnicodeLocaleType("ca"); - try { - type = (String) LOCALE_METHOD.invoke(locale, "ca"); - } catch (IllegalArgumentException ex) { - // ignore - } catch (IllegalAccessException ex) { - // ignore - } catch (InvocationTargetException ex) { - // ignore - } - } else if (locale.equals(JapaneseChronology.LOCALE)) { + if (locale.equals(JapaneseChronology.LOCALE)) { type = "japanese"; } if (type == null || "iso".equals(type) || "iso8601".equals(type)) { diff --git a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java index 6c4ef4e1b..76c0290c7 100644 --- a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java +++ b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java @@ -38,7 +38,6 @@ import java.io.InvalidObjectException; import java.io.ObjectStreamException; import java.io.Serializable; import java.util.Arrays; -import java.util.concurrent.atomic.AtomicReference; import org.threeten.bp.DateTimeException; import org.threeten.bp.LocalDate; @@ -106,7 +105,7 @@ public final class JapaneseEra private static final long serialVersionUID = 1466499369062886794L; // array for the singleton JapaneseEra instances - private static final AtomicReference KNOWN_ERAS; + private static JapaneseEra[] KNOWN_ERAS; static { JapaneseEra[] array = new JapaneseEra[5]; @@ -115,7 +114,7 @@ public final class JapaneseEra array[2] = SHOWA; array[3] = HEISEI; array[4] = REIWA; - KNOWN_ERAS = new AtomicReference(array); + KNOWN_ERAS = array; } /** @@ -177,7 +176,7 @@ public final class JapaneseEra * @throws DateTimeException if an additional era has already been registered */ public static JapaneseEra registerEra(LocalDate since, String name) { - JapaneseEra[] known = KNOWN_ERAS.get(); + JapaneseEra[] known = KNOWN_ERAS; if (known.length > 5) { throw new DateTimeException("Only one additional Japanese era can be added"); } @@ -189,9 +188,7 @@ public final class JapaneseEra JapaneseEra era = new JapaneseEra(ADDITIONAL_VALUE, since, name); JapaneseEra[] newArray = Arrays.copyOf(known, 6); newArray[5] = era; - if (!KNOWN_ERAS.compareAndSet(known, newArray)) { - throw new DateTimeException("Only one additional Japanese era can be added"); - } + KNOWN_ERAS = newArray; return era; } @@ -207,7 +204,7 @@ public final class JapaneseEra * @throws DateTimeException if the value is invalid */ public static JapaneseEra of(int japaneseEra) { - JapaneseEra[] known = KNOWN_ERAS.get(); + JapaneseEra[] known = KNOWN_ERAS; if (japaneseEra < MEIJI.eraValue || japaneseEra > known[known.length - 1].eraValue) { throw new DateTimeException("japaneseEra is invalid"); } @@ -226,7 +223,7 @@ public final class JapaneseEra */ public static JapaneseEra valueOf(String japaneseEra) { Jdk8Methods.requireNonNull(japaneseEra, "japaneseEra"); - JapaneseEra[] known = KNOWN_ERAS.get(); + JapaneseEra[] known = KNOWN_ERAS; for (JapaneseEra era : known) { if (japaneseEra.equals(era.name)) { return era; @@ -247,7 +244,7 @@ public final class JapaneseEra * @return an array of JapaneseEras */ public static JapaneseEra[] values() { - JapaneseEra[] known = KNOWN_ERAS.get(); + JapaneseEra[] known = KNOWN_ERAS; return Arrays.copyOf(known, known.length); } @@ -262,7 +259,7 @@ public final class JapaneseEra if (date.isBefore(MEIJI.since)) { throw new DateTimeException("Date too early: " + date); } - JapaneseEra[] known = KNOWN_ERAS.get(); + JapaneseEra[] known = KNOWN_ERAS; for (int i = known.length - 1; i >= 0; i--) { JapaneseEra era = known[i]; if (date.compareTo(era.since) >= 0) { diff --git a/classlib/src/main/java/org/threeten/bp/format/DateTimeTextProvider.java b/classlib/src/main/java/org/threeten/bp/format/DateTimeTextProvider.java index 3066611e1..fba6b4fbc 100644 --- a/classlib/src/main/java/org/threeten/bp/format/DateTimeTextProvider.java +++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeTextProvider.java @@ -34,7 +34,6 @@ package org.threeten.bp.format; import java.util.Iterator; import java.util.Locale; import java.util.Map.Entry; -import java.util.concurrent.atomic.AtomicReference; import org.threeten.bp.temporal.TemporalField; @@ -51,7 +50,7 @@ import org.threeten.bp.temporal.TemporalField; */ public abstract class DateTimeTextProvider { - private static final AtomicReference MUTABLE_PROVIDER = new AtomicReference(); + private static DateTimeTextProvider MUTABLE_PROVIDER; /** * Gets the provider. @@ -72,9 +71,10 @@ public abstract class DateTimeTextProvider { * @throws IllegalStateException if initialization has already occurred or another provider has been set */ public static void setInitializer(DateTimeTextProvider provider) { - if (!MUTABLE_PROVIDER.compareAndSet(null, provider)) { + if (MUTABLE_PROVIDER != null) { throw new IllegalStateException("Provider was already set, possibly with a default during initialization"); } + MUTABLE_PROVIDER = provider; } //----------------------------------------------------------------------- @@ -120,8 +120,8 @@ public abstract class DateTimeTextProvider { // initialize the provider static DateTimeTextProvider initialize() { // Set the default initializer if none has been provided yet - MUTABLE_PROVIDER.compareAndSet(null, new SimpleDateTimeTextProvider()); - return MUTABLE_PROVIDER.get(); + MUTABLE_PROVIDER = new SimpleDateTimeTextProvider(); + return MUTABLE_PROVIDER; } } diff --git a/classlib/src/main/java/org/threeten/bp/format/DecimalStyle.java b/classlib/src/main/java/org/threeten/bp/format/DecimalStyle.java index 3aec9354c..828a56b7d 100644 --- a/classlib/src/main/java/org/threeten/bp/format/DecimalStyle.java +++ b/classlib/src/main/java/org/threeten/bp/format/DecimalStyle.java @@ -33,11 +33,11 @@ package org.threeten.bp.format; import java.text.DecimalFormatSymbols; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.Locale; +import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import org.threeten.bp.jdk8.Jdk8Methods; @@ -61,7 +61,7 @@ public final class DecimalStyle { /** * The cache of symbols instances. */ - private static final ConcurrentMap CACHE = new ConcurrentHashMap(16, 0.75f, 2); + private static final Map CACHE = new HashMap<>(); /** * The zero digit. diff --git a/classlib/src/main/java/org/threeten/bp/format/SimpleDateTimeFormatStyleProvider.java b/classlib/src/main/java/org/threeten/bp/format/SimpleDateTimeFormatStyleProvider.java index 8d3cc16e2..5d3958343 100644 --- a/classlib/src/main/java/org/threeten/bp/format/SimpleDateTimeFormatStyleProvider.java +++ b/classlib/src/main/java/org/threeten/bp/format/SimpleDateTimeFormatStyleProvider.java @@ -33,9 +33,9 @@ package org.threeten.bp.format; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.HashMap; import java.util.Locale; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; +import java.util.Map; import org.threeten.bp.chrono.Chronology; @@ -51,8 +51,7 @@ final class SimpleDateTimeFormatStyleProvider extends DateTimeFormatStyleProvide // TODO: Better implementation based on CLDR /** Cache of formatters. */ - private static final ConcurrentMap FORMATTER_CACHE = - new ConcurrentHashMap(16, 0.75f, 2); + private static final Map FORMATTER_CACHE = new HashMap<>(); @Override public Locale[] getAvailableLocales() { diff --git a/classlib/src/main/java/org/threeten/bp/format/SimpleDateTimeTextProvider.java b/classlib/src/main/java/org/threeten/bp/format/SimpleDateTimeTextProvider.java index bc2de2621..52d5cf0f8 100644 --- a/classlib/src/main/java/org/threeten/bp/format/SimpleDateTimeTextProvider.java +++ b/classlib/src/main/java/org/threeten/bp/format/SimpleDateTimeTextProvider.java @@ -49,8 +49,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import org.threeten.bp.temporal.IsoFields; import org.threeten.bp.temporal.TemporalField; @@ -75,8 +73,7 @@ final class SimpleDateTimeTextProvider extends DateTimeTextProvider { }; /** Cache. */ - private final ConcurrentMap, Object> cache = - new ConcurrentHashMap, Object>(16, 0.75f, 2); + private final Map, Object> cache = new HashMap<>(); //----------------------------------------------------------------------- @Override diff --git a/classlib/src/main/java/org/threeten/bp/temporal/WeekFields.java b/classlib/src/main/java/org/threeten/bp/temporal/WeekFields.java index 197b6f082..89143112a 100644 --- a/classlib/src/main/java/org/threeten/bp/temporal/WeekFields.java +++ b/classlib/src/main/java/org/threeten/bp/temporal/WeekFields.java @@ -44,6 +44,7 @@ import static org.threeten.bp.temporal.ChronoUnit.YEARS; import java.io.InvalidObjectException; import java.io.Serializable; import java.util.GregorianCalendar; +import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -127,7 +128,7 @@ public final class WeekFields implements Serializable { * The cache of rules by firstDayOfWeek plus minimalDays. * Initialized first to be available for definition of ISO, etc. */ - private static final ConcurrentMap CACHE = new ConcurrentHashMap(4, 0.75f, 2); + private static final Map CACHE = new HashMap<>(); /** * The ISO-8601 definition, where a week starts on Monday and the first week diff --git a/classlib/src/main/java/org/threeten/bp/zone/StandardZoneRules.java b/classlib/src/main/java/org/threeten/bp/zone/StandardZoneRules.java index 9f20424d1..e4c661e3c 100644 --- a/classlib/src/main/java/org/threeten/bp/zone/StandardZoneRules.java +++ b/classlib/src/main/java/org/threeten/bp/zone/StandardZoneRules.java @@ -38,9 +38,9 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; +import java.util.Map; import org.threeten.bp.Duration; import org.threeten.bp.Instant; @@ -98,8 +98,7 @@ final class StandardZoneRules extends ZoneRules implements Serializable { /** * The map of recent transitions. */ - private final ConcurrentMap lastRulesCache = - new ConcurrentHashMap(); + private final Map lastRulesCache = new HashMap<>(); /** * Creates an instance. diff --git a/classlib/src/main/java/org/threeten/bp/zone/ZoneRulesInitializer.java b/classlib/src/main/java/org/threeten/bp/zone/ZoneRulesInitializer.java index 11e34b8fa..bc01aa072 100644 --- a/classlib/src/main/java/org/threeten/bp/zone/ZoneRulesInitializer.java +++ b/classlib/src/main/java/org/threeten/bp/zone/ZoneRulesInitializer.java @@ -33,8 +33,6 @@ package org.threeten.bp.zone; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; /** * Controls how the time-zone rules are initialized. @@ -57,8 +55,8 @@ public abstract class ZoneRulesInitializer { */ public static final ZoneRulesInitializer DO_NOTHING = new DoNothingZoneRulesInitializer(); - private static final AtomicBoolean INITIALIZED = new AtomicBoolean(false); - private static final AtomicReference INITIALIZER = new AtomicReference(); + private static boolean INITIALIZED; + private static ZoneRulesInitializer INITIALIZER; /** * Sets the initializer to use. @@ -70,23 +68,27 @@ public abstract class ZoneRulesInitializer { * @throws IllegalStateException if initialization has already occurred or another initializer has been set */ public static void setInitializer(ZoneRulesInitializer initializer) { - if (INITIALIZED.get()) { + if (INITIALIZED) { throw new IllegalStateException("Already initialized"); } - if (!INITIALIZER.compareAndSet(null, initializer)) { + if (INITIALIZER != null) { throw new IllegalStateException("Initializer was already set, possibly with a default during initialization"); } + INITIALIZER = initializer; } //----------------------------------------------------------------------- // initialize the providers static void initialize() { - if (INITIALIZED.getAndSet(true)) { + if (INITIALIZED) { throw new IllegalStateException("Already initialized"); } + INITIALIZED = true; // Set the default initializer if none has been provided yet. - INITIALIZER.compareAndSet(null, new ServiceLoaderZoneRulesInitializer()); - INITIALIZER.get().initializeProviders(); + if (INITIALIZER == null) { + INITIALIZER = new ServiceLoaderZoneRulesInitializer(); + } + INITIALIZER.initializeProviders(); } /** diff --git a/classlib/src/main/java/org/threeten/bp/zone/ZoneRulesProvider.java b/classlib/src/main/java/org/threeten/bp/zone/ZoneRulesProvider.java index db95108b1..2eb8a7905 100644 --- a/classlib/src/main/java/org/threeten/bp/zone/ZoneRulesProvider.java +++ b/classlib/src/main/java/org/threeten/bp/zone/ZoneRulesProvider.java @@ -31,12 +31,13 @@ */ package org.threeten.bp.zone; +import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.NavigableMap; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.CopyOnWriteArrayList; import org.threeten.bp.DateTimeException; import org.threeten.bp.ZoneId; @@ -73,11 +74,11 @@ public abstract class ZoneRulesProvider { /** * The set of loaded providers. */ - private static final CopyOnWriteArrayList PROVIDERS = new CopyOnWriteArrayList(); + private static final List PROVIDERS = new ArrayList<>(); /** * The lookup from zone region ID to provider. */ - private static final ConcurrentMap ZONES = new ConcurrentHashMap(512, 0.75f, 2); + private static final Map ZONES = new HashMap<>(); static { ZoneRulesInitializer.initialize(); }