Skip to content

Commit 15fae0c

Browse files
authored
Merge pull request #157 from cquiroz/demo
Remove the use of ConcurrentHashMap
2 parents 3cd53fa + 931ae87 commit 15fae0c

File tree

8 files changed

+54
-53
lines changed

8 files changed

+54
-53
lines changed

core/shared/src/main/scala/org/threeten/bp/ZoneOffset.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import java.io.IOException
3939
import java.io.InvalidObjectException
4040
import java.io.ObjectStreamException
4141
import java.io.Serializable
42-
import java.util.concurrent.ConcurrentHashMap
43-
import java.util.concurrent.ConcurrentMap
42+
import java.util.HashMap
43+
import java.util.Map
4444
import org.threeten.bp.temporal.ChronoField
4545
import org.threeten.bp.temporal.Temporal
4646
import org.threeten.bp.temporal.TemporalAccessor
@@ -56,12 +56,12 @@ import org.threeten.bp.zone.ZoneRules
5656
object ZoneOffset {
5757

5858
/** Cache of time-zone offset by offset in seconds. */
59-
private val SECONDS_CACHE: ConcurrentMap[Integer, ZoneOffset] =
60-
new ConcurrentHashMap[Integer, ZoneOffset](16, 0.75f, 4)
59+
private val SECONDS_CACHE: Map[Integer, ZoneOffset] =
60+
new HashMap[Integer, ZoneOffset]()
6161

6262
/** Cache of time-zone offset by ID. */
63-
private val ID_CACHE: ConcurrentMap[String, ZoneOffset] =
64-
new ConcurrentHashMap[String, ZoneOffset](16, 0.75f, 4)
63+
private val ID_CACHE: Map[String, ZoneOffset] =
64+
new HashMap[String, ZoneOffset]()
6565

6666
/** The number of seconds per hour. */
6767
private val SECONDS_PER_HOUR: Int = 60 * 60
@@ -310,9 +310,9 @@ object ZoneOffset {
310310
var result: ZoneOffset = SECONDS_CACHE.get(totalSecs)
311311
if (result == null) {
312312
result = new ZoneOffset(totalSeconds)
313-
SECONDS_CACHE.putIfAbsent(totalSecs, result)
313+
SECONDS_CACHE.put(totalSecs, result)
314314
result = SECONDS_CACHE.get(totalSecs)
315-
ID_CACHE.putIfAbsent(result.getId, result)
315+
ID_CACHE.put(result.getId, result)
316316
}
317317
result
318318
} else

core/shared/src/main/scala/org/threeten/bp/chrono/Chronology.scala

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import java.io.IOException
3737
import java.io.InvalidObjectException
3838
import java.io.ObjectStreamException
3939
import java.util.{ Locale, Objects }
40-
import java.util.concurrent.ConcurrentHashMap
40+
import java.util.HashMap
41+
import java.util.Map
4142

4243
import org.threeten.bp.Clock
4344
import org.threeten.bp.DateTimeException
@@ -60,12 +61,12 @@ import org.threeten.bp.temporal.ValueRange
6061
object Chronology {
6162

6263
/** Map of available calendars by ID. */
63-
private val CHRONOS_BY_ID: ConcurrentHashMap[String, Chronology] =
64-
new ConcurrentHashMap[String, Chronology]
64+
private val CHRONOS_BY_ID: Map[String, Chronology] =
65+
new HashMap[String, Chronology]()
6566

6667
/** Map of available calendars by calendar type. */
67-
private val CHRONOS_BY_TYPE: ConcurrentHashMap[String, Chronology] =
68-
new ConcurrentHashMap[String, Chronology]
68+
private val CHRONOS_BY_TYPE: Map[String, Chronology] =
69+
new HashMap[String, Chronology]()
6970

7071
/** Obtains an instance of {@code Chronology} from a temporal object.
7172
*
@@ -189,24 +190,24 @@ object Chronology {
189190
register(MinguoChronology.INSTANCE)
190191
register(JapaneseChronology.INSTANCE)
191192
register(HijrahChronology.INSTANCE)
192-
CHRONOS_BY_ID.putIfAbsent("Hijrah", HijrahChronology.INSTANCE)
193-
CHRONOS_BY_TYPE.putIfAbsent("islamic", HijrahChronology.INSTANCE)
193+
CHRONOS_BY_ID.put("Hijrah", HijrahChronology.INSTANCE)
194+
CHRONOS_BY_TYPE.put("islamic", HijrahChronology.INSTANCE)
194195
val chronologies: java.util.Iterator[Chronology] =
195196
ChronologyPlatformHelper.loadAdditionalChronologies
196197
while (chronologies.hasNext) {
197198
val chrono = chronologies.next()
198-
CHRONOS_BY_ID.putIfAbsent(chrono.getId, chrono)
199+
CHRONOS_BY_ID.put(chrono.getId, chrono)
199200
val `type`: String = chrono.getCalendarType
200201
if (`type` != null)
201-
CHRONOS_BY_TYPE.putIfAbsent(`type`, chrono)
202+
CHRONOS_BY_TYPE.put(`type`, chrono)
202203
}
203204
}
204205

205206
private def register(chrono: Chronology): Unit = {
206-
CHRONOS_BY_ID.putIfAbsent(chrono.getId, chrono)
207+
CHRONOS_BY_ID.put(chrono.getId, chrono)
207208
val `type`: String = chrono.getCalendarType
208209
if (`type` != null)
209-
CHRONOS_BY_TYPE.putIfAbsent(`type`, chrono)
210+
CHRONOS_BY_TYPE.put(`type`, chrono)
210211
()
211212
}
212213

core/shared/src/main/scala/org/threeten/bp/format/DecimalStyle.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ package org.threeten.bp.format
3333

3434
import java.text.DecimalFormatSymbols
3535
import java.util.{ Locale, Objects }
36-
import java.util.concurrent.ConcurrentHashMap
37-
import java.util.concurrent.ConcurrentMap
36+
import java.util.HashMap
37+
import java.util.Map
3838
import scala.collection.JavaConverters._
3939

4040
/** Localized symbols used in date and time formatting.
@@ -54,8 +54,8 @@ object DecimalStyle {
5454
val STANDARD: DecimalStyle = new DecimalStyle('0', '+', '-', '.')
5555

5656
/** The cache of symbols instances. */
57-
private val CACHE: ConcurrentMap[Locale, DecimalStyle] =
58-
new ConcurrentHashMap[Locale, DecimalStyle](16, 0.75f, 2)
57+
private val CACHE: Map[Locale, DecimalStyle] =
58+
new HashMap[Locale, DecimalStyle]()
5959

6060
/** Lists all the locales that are supported.
6161
*
@@ -85,7 +85,7 @@ object DecimalStyle {
8585
Objects.requireNonNull(locale, "locale")
8686
// Size reduced
8787
if (CACHE.get(locale) == null) {
88-
CACHE.putIfAbsent(locale, create(locale))
88+
CACHE.put(locale, create(locale))
8989
}
9090
CACHE.get(locale)
9191
}

core/shared/src/main/scala/org/threeten/bp/format/SimpleDateTimeFormatStyleProvider.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ package org.threeten.bp.format
3434
import java.text.DateFormat
3535
import java.text.SimpleDateFormat
3636
import java.util.Locale
37-
import java.util.concurrent.ConcurrentHashMap
38-
import java.util.concurrent.ConcurrentMap
37+
import java.util.HashMap
38+
import java.util.Map
3939
import org.threeten.bp.chrono.Chronology
4040

4141
private object SimpleDateTimeFormatStyleProvider {
4242

4343
/** Cache of formatters. */
44-
private val FORMATTER_CACHE: ConcurrentMap[String, AnyRef] =
45-
new ConcurrentHashMap[String, AnyRef](16, 0.75f, 2)
44+
private val FORMATTER_CACHE: Map[String, AnyRef] =
45+
new HashMap[String, AnyRef]()
4646
}
4747

4848
/** The Service Provider Implementation to obtain date-time formatters for a style.
@@ -83,10 +83,10 @@ final class SimpleDateTimeFormatStyleProvider extends DateTimeFormatStyleProvide
8383
val pattern: String = format.toPattern
8484
val formatter: DateTimeFormatter =
8585
new DateTimeFormatterBuilder().appendPattern(pattern).toFormatter(locale)
86-
SimpleDateTimeFormatStyleProvider.FORMATTER_CACHE.putIfAbsent(key, formatter)
86+
SimpleDateTimeFormatStyleProvider.FORMATTER_CACHE.put(key, formatter)
8787
formatter
8888
case _ =>
89-
SimpleDateTimeFormatStyleProvider.FORMATTER_CACHE.putIfAbsent(key, "")
89+
SimpleDateTimeFormatStyleProvider.FORMATTER_CACHE.put(key, "")
9090
throw new IllegalArgumentException("Unable to convert DateFormat to DateTimeFormatter")
9191
}
9292
}

core/shared/src/main/scala/org/threeten/bp/format/internal/TTBPSimpleDateTimeTextProvider.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import java.text.DateFormatSymbols
3939
import java.util.Calendar
4040
import java.util.GregorianCalendar
4141
import java.util.Locale
42-
import java.util.concurrent.ConcurrentHashMap
43-
import java.util.concurrent.ConcurrentMap
42+
import java.util.HashMap
43+
import java.util.{ Map => JMap }
4444

4545
import org.threeten.bp.temporal.IsoFields
4646
import org.threeten.bp.temporal.TemporalField
@@ -133,8 +133,8 @@ object TTBPSimpleDateTimeTextProvider {
133133
final class TTBPSimpleDateTimeTextProvider extends TTBPDateTimeTextProvider {
134134

135135
/** Cache. */
136-
private val cache: ConcurrentMap[(TemporalField, Locale), AnyRef] =
137-
new ConcurrentHashMap[(TemporalField, Locale), AnyRef](16, 0.75f, 2)
136+
private val cache: JMap[(TemporalField, Locale), AnyRef] =
137+
new HashMap[(TemporalField, Locale), AnyRef]()
138138

139139
override def getText(
140140
field: TemporalField,
@@ -162,7 +162,7 @@ final class TTBPSimpleDateTimeTextProvider extends TTBPDateTimeTextProvider {
162162
var store: AnyRef = cache.get(key)
163163
if (store == null) {
164164
store = createStore(field, locale)
165-
cache.putIfAbsent(key, store)
165+
cache.put(key, store)
166166
store = cache.get(key)
167167
}
168168
store

core/shared/src/main/scala/org/threeten/bp/temporal/WeekFields.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ import org.threeten.bp.temporal.ChronoUnit.YEARS
4343
import java.io.InvalidObjectException
4444
import java.io.Serializable
4545
import java.util.{ GregorianCalendar, Locale, Objects }
46-
import java.util.concurrent.ConcurrentHashMap
47-
import java.util.concurrent.ConcurrentMap
46+
import java.util.HashMap
47+
import java.util.Map
4848
import org.threeten.bp.DateTimeException
4949
import org.threeten.bp.DayOfWeek
5050
import org.threeten.bp.Year
@@ -58,8 +58,8 @@ object WeekFields {
5858
/** The cache of rules by firstDayOfWeek plus minimalDays.
5959
* Initialized first to be available for definition of ISO, etc.
6060
*/
61-
private val CACHE: ConcurrentMap[String, WeekFields] =
62-
new ConcurrentHashMap[String, WeekFields](4, 0.75f, 2)
61+
private val CACHE: Map[String, WeekFields] =
62+
new HashMap[String, WeekFields]()
6363

6464
/** The ISO-8601 definition, where a week starts on Monday and the first week
6565
* has a minimum of 4 days.
@@ -123,7 +123,7 @@ object WeekFields {
123123
var rules: WeekFields = CACHE.get(key)
124124
if (rules == null) {
125125
rules = new WeekFields(firstDayOfWeek, minimalDaysInFirstWeek)
126-
CACHE.putIfAbsent(key, rules)
126+
CACHE.put(key, rules)
127127
rules = CACHE.get(key)
128128
}
129129
rules

core/shared/src/main/scala/org/threeten/bp/zone/StandardZoneRules.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import java.io.IOException
3737
import java.io.Serializable
3838
import java.util.Arrays
3939
import java.util.Collections
40-
import java.util.concurrent.ConcurrentHashMap
41-
import java.util.concurrent.ConcurrentMap
40+
import java.util.HashMap
41+
import java.util.Map
4242
import org.threeten.bp.Duration
4343
import org.threeten.bp.Instant
4444
import org.threeten.bp.LocalDate
@@ -211,8 +211,8 @@ final class StandardZoneRules private (
211211
with Serializable {
212212

213213
/** The map of recent transitions. */
214-
private val lastRulesCache: ConcurrentMap[Integer, Array[ZoneOffsetTransition]] =
215-
new ConcurrentHashMap[Integer, Array[ZoneOffsetTransition]]
214+
private val lastRulesCache: Map[Integer, Array[ZoneOffsetTransition]] =
215+
new HashMap[Integer, Array[ZoneOffsetTransition]]()
216216

217217
/** Creates an instance. */
218218
/* // Can't be implemented with Scala's constructor rules. Replaced with apply factory method.
@@ -422,7 +422,7 @@ final class StandardZoneRules private (
422422
}
423423

424424
if (year < StandardZoneRules.LAST_CACHED_YEAR)
425-
lastRulesCache.putIfAbsent(yearObj, transArray)
425+
lastRulesCache.put(yearObj, transArray)
426426
transArray
427427
}
428428

core/shared/src/main/scala/org/threeten/bp/zone/ZoneRulesProvider.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
package org.threeten.bp.zone
3333

3434
import java.util.{ Collections, Objects }
35-
import java.util.concurrent.ConcurrentHashMap
36-
import java.util.concurrent.ConcurrentMap
37-
import java.util.concurrent.CopyOnWriteArrayList
35+
import java.util.HashMap
36+
import java.util.Map
37+
import java.util.ArrayList
3838

3939
object ZoneRulesProvider {
4040

4141
/** The set of loaded providers. */
42-
private val PROVIDERS: CopyOnWriteArrayList[ZoneRulesProvider] =
43-
new CopyOnWriteArrayList[ZoneRulesProvider]
42+
private val PROVIDERS: ArrayList[ZoneRulesProvider] =
43+
new ArrayList[ZoneRulesProvider]
4444

4545
/** The lookup from zone region ID to provider. */
46-
private val ZONES: ConcurrentMap[String, ZoneRulesProvider] =
47-
new ConcurrentHashMap[String, ZoneRulesProvider](512, 0.75f, 2)
46+
private val ZONES: Map[String, ZoneRulesProvider] =
47+
new HashMap[String, ZoneRulesProvider]()
4848

4949
/** Gets the set of available zone IDs.
5050
*
@@ -157,7 +157,7 @@ object ZoneRulesProvider {
157157
while (zoneIds.hasNext) {
158158
val zoneId = zoneIds.next()
159159
Objects.requireNonNull(zoneId, "zoneId")
160-
val old: ZoneRulesProvider = ZONES.putIfAbsent(zoneId, provider)
160+
val old: ZoneRulesProvider = ZONES.put(zoneId, provider)
161161
if (old != null)
162162
throw new ZoneRulesException(
163163
s"Unable to register zone as one already registered with that ID: $zoneId, currently loading from provider: $provider"

0 commit comments

Comments
 (0)