From d74756d198eeb33626746f8683aeffd043f9e710 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Thu, 13 Oct 2022 16:03:14 -0700 Subject: [PATCH] Review Picnic's refaster rule suggestions --- .github/workflows/analysis.yml | 32 +++++------------ .github/workflows/benchmarks.yml | 2 +- .github/workflows/dependency-check.yml | 31 ++++------------ .github/workflows/snyke.yml | 35 ++++++------------- build.gradle | 14 ++++---- .../benmanes/caffeine/cache/Feature.java | 3 +- .../caffeine/cache/LocalAsyncCache.java | 2 +- .../benmanes/caffeine/cache/AsMapTest.java | 8 ++--- .../caffeine/cache/AsyncAsMapTest.java | 20 +++++------ .../caffeine/cache/BoundedLocalCacheTest.java | 13 ++++--- .../benmanes/caffeine/cache/EvictionTest.java | 3 +- .../caffeine/cache/ExpireAfterAccessTest.java | 5 +-- .../caffeine/cache/ExpireAfterWriteTest.java | 8 ++--- .../caffeine/cache/LoadingCacheTest.java | 7 ++-- .../caffeine/cache/LocalCacheSubject.java | 2 +- .../caffeine/cache/ReferenceTest.java | 3 +- .../caffeine/cache/RefreshAfterWriteTest.java | 14 ++++---- .../caffeine/cache/issues/Issue298Test.java | 6 ++-- .../caffeine/cache/issues/Issue30Test.java | 5 +-- .../cache/testing/CacheContextSubject.java | 5 ++- .../cache/testing/CacheGenerator.java | 3 +- .../caffeine/testing/CollectionSubject.java | 5 ++- .../benmanes/caffeine/testing/MapSubject.java | 5 ++- gradle/codeQuality.gradle | 6 ++-- gradle/dependencies.gradle | 5 +-- .../jcache/processor/EntryProcessorEntry.java | 2 +- .../caffeine/jcache/CacheManagerTest.java | 2 +- .../TypesafeConfigurationTest.java | 23 ++++++------ .../copy/JavaSerializationCopierTest.java | 4 +-- .../JCacheExpiryAndMaximumSizeTest.java | 3 +- .../jcache/expiry/JCacheExpiryTest.java | 3 +- .../processor/EntryProcessorEntryTest.java | 4 +-- .../cache/simulator/BasicSettings.java | 3 +- .../countmin64/CountMin64TinyLfu.java | 3 +- .../admission/perfect/PerfectFrequency.java | 3 +- .../table/RandomRemovalFrequencyTable.java | 3 +- .../admission/tinycache/TinyCacheAdapter.java | 3 +- .../simulator/policy/adaptive/ArcPolicy.java | 3 +- .../simulator/policy/adaptive/CarPolicy.java | 3 +- .../simulator/policy/adaptive/CartPolicy.java | 3 +- .../policy/irr/ClockProPlusPolicy.java | 3 +- .../simulator/policy/irr/ClockProPolicy.java | 3 +- .../policy/irr/ClockProSimplePolicy.java | 3 +- .../simulator/policy/irr/DClockPolicy.java | 3 +- .../cache/simulator/policy/irr/FrdPolicy.java | 3 +- .../policy/irr/HillClimberFrdPolicy.java | 3 +- .../policy/irr/IndicatorFrdPolicy.java | 3 +- .../simulator/policy/irr/LirsPolicy.java | 3 +- .../policy/linked/FrequentlyUsedPolicy.java | 3 +- .../policy/linked/MultiQueuePolicy.java | 3 +- .../simulator/policy/linked/S4LruPolicy.java | 3 +- .../policy/linked/SegmentedLruPolicy.java | 3 +- .../policy/opt/ClairvoyantPolicy.java | 3 +- .../policy/product/ExpiringMapPolicy.java | 3 +- .../policy/product/HazelcastPolicy.java | 3 +- .../policy/product/TCachePolicy.java | 3 +- .../policy/sampled/SampledPolicy.java | 3 +- .../policy/sketch/WindowTinyLfuPolicy.java | 3 +- .../HillClimberWindowTinyLfuPolicy.java | 7 ++-- .../policy/sketch/climbing/gradient/Adam.java | 3 +- .../sketch/climbing/gradient/AmsGrad.java | 3 +- .../sketch/climbing/gradient/Nadam.java | 3 +- .../sketch/climbing/gradient/Stochastic.java | 3 +- .../sketch/climbing/hill/SimpleClimber.java | 3 +- .../hill/SimulatedAnnealingClimber.java | 3 +- .../climbing/inference/IndicatorClimber.java | 3 +- .../sketch/climbing/sim/MiniSimClimber.java | 3 +- .../feedback/FeedbackTinyLfuPolicy.java | 3 +- .../feedback/FeedbackWindowTinyLfuPolicy.java | 3 +- .../FullySegmentedWindowTinyLfuPolicy.java | 3 +- .../segment/LruWindowTinyLfuPolicy.java | 3 +- .../segment/RandomWindowTinyLfuPolicy.java | 3 +- .../sketch/segment/S4WindowTinyLfuPolicy.java | 3 +- .../sketch/tinycache/TinyCachePolicy.java | 3 +- .../TinyCacheWithGhostCachePolicy.java | 3 +- .../tinycache/WindowTinyCachePolicy.java | 3 +- .../policy/two_queue/TuQueuePolicy.java | 3 +- .../policy/two_queue/TwoQueuePolicy.java | 3 +- 78 files changed, 157 insertions(+), 268 deletions(-) diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 34293313aa..c0a917b7a5 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ 11, 18 ] + java: [ 11, 19 ] env: JAVA_VERSION: ${{ matrix.java }} steps: @@ -20,27 +20,11 @@ jobs: with: egress-policy: audit - uses: actions/checkout@v3 - - name: Set up JDK ${{ matrix.java }} - uses: Wandalen/wretry.action@v1.0.35 - timeout-minutes: 5 - with: - action: actions/setup-java@v3 - with: | - distribution: temurin - java-version: ${{ matrix.java }} - attempt_limit: 3 - attempt_delay: 2000 - - name: Setup Gradle - uses: Wandalen/wretry.action@v1.0.35 - timeout-minutes: 5 - with: - action: gradle/gradle-build-action@v2 - with: | - cache-read-only: false - generate-job-summary: false - arguments: help --daemon --no-scan - gradle-home-cache-strict-match: true - attempt_limit: 3 - attempt_delay: 2000 - name: Run analyzers - run: ./.github/scripts/analyze.sh + uses: ./.github/actions/run-gradle + with: + early-access: false + java: ${{ matrix.java }} + arguments: > + pmdJavaPoet pmdMain pmdCodeGen pmdJmh -Dpmd + spotbugsJavaPoet spotbugsMain spotbugsCodeGen spotbugsJmh -Dspotbugs diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index cc1b6ffb9e..b2e15d1c30 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -5,7 +5,7 @@ on: [ push, pull_request ] env: GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }} GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - MAX_JVM: 18 + MAX_JVM: 19 EA_JVM: 20 jobs: diff --git a/.github/workflows/dependency-check.yml b/.github/workflows/dependency-check.yml index 85c1cc3fe0..580890762f 100644 --- a/.github/workflows/dependency-check.yml +++ b/.github/workflows/dependency-check.yml @@ -9,7 +9,7 @@ permissions: read-all env: GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }} GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - JAVA_VERSION: 18 + JAVA_VERSION: 19 jobs: dependency-check: @@ -24,31 +24,12 @@ jobs: with: egress-policy: audit - uses: actions/checkout@v3 - - name: Set up JDK ${{ env.JAVA_VERSION }} - uses: Wandalen/wretry.action@v1.0.35 - timeout-minutes: 5 - with: - action: actions/setup-java@v3 - with: | - cache: gradle - distribution: temurin - java-version: ${{ env.JAVA_VERSION }} - attempt_limit: 3 - attempt_delay: 2000 - - name: Setup Gradle - uses: Wandalen/wretry.action@v1.0.35 - timeout-minutes: 5 - with: - action: gradle/gradle-build-action@v2 - with: | - cache-read-only: false - arguments: help --no-scan - generate-job-summary: false - attempt_limit: 3 - attempt_delay: 2000 - name: Run dependency-check - run: ./gradlew dependencyCheckAggregate - continue-on-error: true + uses: ./.github/actions/run-gradle + with: + early-access: false + java: ${{ env.JAVA_VERSION }} + arguments: dependencyCheckAggregate - name: Upload result to GitHub Code Scanning uses: github/codeql-action/upload-sarif@v2 continue-on-error: true diff --git a/.github/workflows/snyke.yml b/.github/workflows/snyke.yml index b3ca993a10..1a7bdfe233 100644 --- a/.github/workflows/snyke.yml +++ b/.github/workflows/snyke.yml @@ -7,7 +7,7 @@ permissions: read-all env: GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }} GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - JAVA_VERSION: 18 + JAVA_VERSION: 19 jobs: snyke: @@ -24,35 +24,22 @@ jobs: with: egress-policy: audit - uses: actions/checkout@v3 - - name: Set up JDK ${{ env.JAVA_VERSION }} - uses: Wandalen/wretry.action@v1.0.35 - timeout-minutes: 5 - with: - action: actions/setup-java@v3 - with: | - distribution: temurin - java-version: ${{ env.JAVA_VERSION }} - attempt_limit: 3 - attempt_delay: 2000 - - name: Setup Gradle - uses: Wandalen/wretry.action@v1.0.35 - timeout-minutes: 5 - with: - action: gradle/gradle-build-action@v2 - with: | - cache-read-only: false - arguments: help --no-scan - generate-job-summary: false - attempt_limit: 3 - attempt_delay: 2000 - name: Run Snyk test + uses: ./.github/actions/run-gradle continue-on-error: true - run: ./gradlew snyk-test -PsnykArgs="--sarif-file-output=snyk.sarif" + with: + early-access: false + java: ${{ env.JAVA_VERSION }} + arguments: snyk-test -PsnykArgs="--sarif-file-output=snyk.sarif" - name: Upload result to GitHub Code Scanning uses: github/codeql-action/upload-sarif@v2 continue-on-error: true with: sarif_file: snyk.sarif - name: Run Snyk monitor + uses: ./.github/actions/run-gradle continue-on-error: true - run: ./gradlew snyk-monitor + with: + early-access: false + java: ${{ env.JAVA_VERSION }} + arguments: snyk-monitor diff --git a/build.gradle b/build.gradle index 71e9f4e3fb..164b01a215 100644 --- a/build.gradle +++ b/build.gradle @@ -18,14 +18,12 @@ buildscript { dependencies { classpath gradlePlugins.values() + classpath platforms.collect { platform(it) } - configurations.each { configuration -> + configurations.all { configuration -> restrictions.each { module, version -> constraints.add(configuration.name, module).version { require version } } - platforms.each { dependency -> - add(configuration.name, platform(dependency)) - } } } } @@ -43,13 +41,10 @@ allprojects { } dependencies { - configurations.each { configuration -> + configurations.all { configuration -> restrictions.each { module, version -> constraints.add(configuration.name, module).version { require version } } - platforms.each { dependency -> - add(configuration.name, platform(dependency)) - } } } } @@ -72,6 +67,9 @@ subprojects { } dependencies { + implementation platforms.collect { platform(it) } + annotationProcessor platforms.collect { platform(it) } + testImplementation libraries.guava testImplementation testLibraries.junit testImplementation testLibraries.truth diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Feature.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Feature.java index 1aa1fa59c8..471a222a32 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Feature.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Feature.java @@ -17,6 +17,7 @@ import static java.util.stream.Collectors.joining; +import java.util.Collections; import java.util.Set; import com.google.common.base.CaseFormat; @@ -100,6 +101,6 @@ public static boolean usesMaximum(Set features) { } public static boolean usesFastPath(Set features) { - return features.stream().noneMatch(fastPathIncompatible::contains) && usesMaximum(features); + return Collections.disjoint(features, fastPathIncompatible) && usesMaximum(features); } } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java index acc1fd7a0c..559dd2b0fa 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java @@ -160,7 +160,7 @@ default CompletableFuture> getAll(Iterable keys, */ static CompletableFuture> composeResult(Map> futures) { if (futures.isEmpty()) { - return CompletableFuture.completedFuture(Collections.emptyMap()); + return CompletableFuture.completedFuture(Map.of()); } @SuppressWarnings("rawtypes") CompletableFuture[] array = futures.values().toArray(new CompletableFuture[0]); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java index a9517b79d2..b73cab68a3 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java @@ -27,9 +27,7 @@ import static com.github.benmanes.caffeine.testing.MapSubject.assertThat; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.collect.ImmutableMap.toImmutableMap; -import static com.google.common.collect.Maps.immutableEntry; import static com.google.common.truth.Truth.assertThat; -import static java.util.Map.entry; import static java.util.function.Function.identity; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; @@ -2567,7 +2565,7 @@ public void entrySet_contains_nullValue(Map map, CacheContext context) @Test(dataProvider = "caches") @CacheSpec(removalListener = { Listener.DISABLED, Listener.REJECTING }) public void entrySet_contains_absent(Map map, CacheContext context) { - var entry = entry(context.absentKey(), context.absentValue()); + var entry = Map.entry(context.absentKey(), context.absentValue()); assertThat(map.entrySet().contains(entry)).isFalse(); } @@ -2576,7 +2574,7 @@ public void entrySet_contains_absent(Map map, CacheContext context) { @CacheSpec(population = Population.FULL, removalListener = { Listener.DISABLED, Listener.REJECTING }) public void entrySet_contains_present(Map map, CacheContext context) { - var entry = entry(context.firstKey(), context.original().get(context.firstKey())); + var entry = Map.entry(context.firstKey(), context.original().get(context.firstKey())); assertThat(map.entrySet().contains(entry)).isTrue(); } @@ -2593,7 +2591,7 @@ public void entrySet_empty(Map map, CacheContext context) { @Test(dataProvider = "caches", expectedExceptions = UnsupportedOperationException.class) public void entrySet_addIsNotSupported(Map map, CacheContext context) { try { - map.entrySet().add(immutableEntry(Int.valueOf(1), Int.valueOf(2))); + map.entrySet().add(Map.entry(Int.valueOf(1), Int.valueOf(2))); } finally { assertThat(map).isExhaustivelyEmpty(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java index 945cec1402..c96c584488 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java @@ -27,11 +27,8 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableMap.toImmutableMap; -import static com.google.common.collect.Maps.immutableEntry; import static com.google.common.truth.Truth.assertThat; -import static java.util.Map.entry; import static java.util.function.Function.identity; -import static java.util.stream.Collectors.toUnmodifiableMap; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -1393,8 +1390,8 @@ public void hashCode_self(AsyncCache cache, CacheContext context) { @CacheSpec(population = Population.EMPTY, removalListener = { Listener.DISABLED, Listener.REJECTING }) public void equalsAndHashCodeFail_empty(AsyncCache cache, CacheContext context) { - var other = Stream.of(1, 2, 3) - .collect(toUnmodifiableMap(Int::valueOf, key -> Int.futureOf(-key))); + var other = Map.of(Int.valueOf(1), Int.futureOf(-1), + Int.valueOf(2), Int.futureOf(-2), Int.valueOf(3), Int.futureOf(-3)); assertThat(cache.asMap().equals(other)).isFalse(); assertThat(other.equals(cache.asMap())).isFalse(); assertThat(cache.asMap().hashCode()).isNotEqualTo(other.hashCode()); @@ -1404,10 +1401,9 @@ public void equalsAndHashCodeFail_empty(AsyncCache cache, CacheContext @Test(dataProvider = "caches") @CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }, removalListener = { Listener.DISABLED, Listener.REJECTING }) - public void equalsAndHashCodeFail_present( - AsyncCache cache, CacheContext context) { - var other = Stream.of(1, 2, 3) - .collect(toUnmodifiableMap(Int::valueOf, key -> Int.futureOf(-key))); + public void equalsAndHashCodeFail_present(AsyncCache cache, CacheContext context) { + var other = Map.of(Int.valueOf(1), Int.futureOf(-1), + Int.valueOf(2), Int.futureOf(-2), Int.valueOf(3), Int.futureOf(-3)); assertThat(cache.asMap().equals(other)).isFalse(); assertThat(other.equals(cache.asMap())).isFalse(); assertThat(cache.asMap().hashCode()).isNotEqualTo(other.hashCode()); @@ -2334,7 +2330,7 @@ public void entrySet_contains_nullValue(AsyncCache cache, CacheContext @Test(dataProvider = "caches") @CacheSpec(removalListener = { Listener.DISABLED, Listener.REJECTING }) public void entrySet_contains_absent(AsyncCache cache, CacheContext context) { - var entry = entry(context.absentKey(), context.absentValue().asFuture()); + var entry = Map.entry(context.absentKey(), context.absentValue().asFuture()); assertThat(cache.asMap().entrySet().contains(entry)).isFalse(); } @@ -2343,7 +2339,7 @@ public void entrySet_contains_absent(AsyncCache cache, CacheContext co @CacheSpec(population = Population.FULL, removalListener = { Listener.DISABLED, Listener.REJECTING }) public void entrySet_contains_present(AsyncCache cache, CacheContext context) { - var entry = entry(context.firstKey(), cache.asMap().get(context.firstKey())); + var entry = Map.entry(context.firstKey(), cache.asMap().get(context.firstKey())); assertThat(cache.asMap().entrySet().contains(entry)).isTrue(); } @@ -2352,7 +2348,7 @@ public void entrySet_contains_present(AsyncCache cache, CacheContext c @Test(dataProvider = "caches", expectedExceptions = UnsupportedOperationException.class) public void entrySet_addIsNotSupported(AsyncCache cache, CacheContext context) { try { - cache.asMap().entrySet().add(immutableEntry(Int.valueOf(1), Int.valueOf(2).asFuture())); + cache.asMap().entrySet().add(Map.entry(Int.valueOf(1), Int.valueOf(2).asFuture())); } finally { assertThat(cache).isEmpty(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java index 3dd1b35d17..e01b2ebe41 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java @@ -42,7 +42,6 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.truth.Truth.assertThat; import static java.lang.Thread.State.BLOCKED; -import static java.util.Map.entry; import static java.util.function.Function.identity; import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.any; @@ -929,7 +928,7 @@ public void evict_resurrect_weight(Cache> cache, CacheContext con ConcurrentTestHarness.execute(() -> { evictor.set(Thread.currentThread()); started.set(true); - cache.policy().eviction().get().setMaximum(0); + cache.policy().eviction().orElseThrow().setMaximum(0); done.set(true); }); @@ -943,7 +942,7 @@ public void evict_resurrect_weight(Cache> cache, CacheContext con assertThat(cache).containsEntry(key, List.of()); assertThat(context).removalNotifications().withCause(REPLACED) - .contains(entry(key, value)).exclusively(); + .contains(Map.entry(key, value)).exclusively(); } @Test(dataProvider = "caches") @@ -994,14 +993,14 @@ public void evict_resurrect_expireAfterAccess(Cache cache, CacheContex ConcurrentTestHarness.execute(() -> { evictor.set(Thread.currentThread()); started.set(true); - cache.policy().expireAfterAccess().get().setExpiresAfter(Duration.ZERO); + cache.policy().expireAfterAccess().orElseThrow().setExpiresAfter(Duration.ZERO); done.set(true); }); await().untilTrue(started); var threadState = EnumSet.of(State.BLOCKED, State.WAITING); await().until(() -> threadState.contains(evictor.get().getState())); - cache.policy().expireAfterAccess().get().setExpiresAfter(Duration.ofHours(1)); + cache.policy().expireAfterAccess().orElseThrow().setExpiresAfter(Duration.ofHours(1)); return v; }); await().untilTrue(done); @@ -1025,14 +1024,14 @@ public void evict_resurrect_expireAfterWrite(Cache cache, CacheContext ConcurrentTestHarness.execute(() -> { evictor.set(Thread.currentThread()); started.set(true); - cache.policy().expireAfterWrite().get().setExpiresAfter(Duration.ZERO); + cache.policy().expireAfterWrite().orElseThrow().setExpiresAfter(Duration.ZERO); done.set(true); }); await().untilTrue(started); var threadState = EnumSet.of(State.BLOCKED, State.WAITING); await().until(() -> threadState.contains(evictor.get().getState())); - cache.policy().expireAfterWrite().get().setExpiresAfter(Duration.ofHours(1)); + cache.policy().expireAfterWrite().orElseThrow().setExpiresAfter(Duration.ofHours(1)); return v; }); await().untilTrue(done); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java index 96ba876500..e4edf91d51 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/EvictionTest.java @@ -30,7 +30,6 @@ import static com.google.common.collect.ImmutableMap.toImmutableMap; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth8.assertThat; -import static java.util.Map.entry; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; @@ -261,7 +260,7 @@ public void evict_zero_async(AsyncCache> cache, CacheContext cont await().untilTrue(done); await().untilAsserted(() -> assertThat(cache).isEmpty()); assertThat(context).notifications().withCause(SIZE) - .contains(entry(context.absentKey(), Int.listOf(1, 2, 3, 4, 5))) + .contains(Map.entry(context.absentKey(), Int.listOf(1, 2, 3, 4, 5))) .exclusively(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterAccessTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterAccessTest.java index 3a64c9ca83..3819877fbe 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterAccessTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterAccessTest.java @@ -262,11 +262,12 @@ public void putIfAbsent(Map map, CacheContext context) { @CacheSpec(population = Population.FULL, expireAfterAccess = Expire.ONE_MINUTE) public void getIfPresentQuietly(Cache cache, CacheContext context, @ExpireAfterAccess FixedExpiration expireAfterAccess) { - var original = expireAfterAccess.ageOf(context.firstKey()).get(); + var original = expireAfterAccess.ageOf(context.firstKey()).orElseThrow(); var advancement = Duration.ofSeconds(30); context.ticker().advance(advancement); cache.policy().getIfPresentQuietly(context.firstKey()); - var current = cache.policy().expireAfterAccess().get().ageOf(context.firstKey()).get(); + var current = cache.policy().expireAfterAccess() + .flatMap(policy -> policy.ageOf(context.firstKey())).orElseThrow(); assertThat(current.minus(advancement)).isEqualTo(original); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterWriteTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterWriteTest.java index 154aa2de20..730018fba9 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterWriteTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterWriteTest.java @@ -226,11 +226,11 @@ public void putIfAbsent(Map map, CacheContext context) { @CacheSpec(population = Population.FULL, expireAfterWrite = Expire.ONE_MINUTE) public void getIfPresentQuietly(Cache cache, CacheContext context, @ExpireAfterWrite FixedExpiration expireAfterWrite) { - var original = expireAfterWrite.ageOf(context.firstKey()).get(); + var original = expireAfterWrite.ageOf(context.firstKey()).orElseThrow(); var advancement = Duration.ofSeconds(30); context.ticker().advance(advancement); cache.policy().getIfPresentQuietly(context.firstKey()); - var current = expireAfterWrite.ageOf(context.firstKey()).get(); + var current = expireAfterWrite.ageOf(context.firstKey()).orElseThrow(); assertThat(current.minus(advancement)).isEqualTo(original); } @@ -305,9 +305,9 @@ public void ageOf(CacheContext context, public void ageOf_duration(CacheContext context, @ExpireAfterWrite FixedExpiration expireAfterWrite) { // Truncated to seconds to ignore the LSB (nanosecond) used for refreshAfterWrite's lock - assertThat(expireAfterWrite.ageOf(context.firstKey()).get().toSeconds()).isEqualTo(0); + assertThat(expireAfterWrite.ageOf(context.firstKey()).orElseThrow().toSeconds()).isEqualTo(0); context.ticker().advance(30, TimeUnit.SECONDS); - assertThat(expireAfterWrite.ageOf(context.firstKey()).get().toSeconds()).isEqualTo(30); + assertThat(expireAfterWrite.ageOf(context.firstKey()).orElseThrow().toSeconds()).isEqualTo(30); context.ticker().advance(45, TimeUnit.SECONDS); assertThat(expireAfterWrite.ageOf(context.firstKey())).isEmpty(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java index ced13e6aa9..7f26e52f23 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java @@ -29,7 +29,6 @@ import static com.github.benmanes.caffeine.testing.MapSubject.assertThat; import static com.google.common.collect.ImmutableMap.toImmutableMap; import static com.google.common.truth.Truth.assertThat; -import static java.util.Map.entry; import static java.util.function.Function.identity; import static uk.org.lidalia.slf4jext.ConventionalLevelHierarchy.INFO_LEVELS; import static uk.org.lidalia.slf4jext.Level.WARN; @@ -684,7 +683,7 @@ public void refresh_conflict(CacheContext context) { assertThat(cache).containsEntry(key, updated); assertThat(context).stats().success(1).failures(0); assertThat(context).removalNotifications().withCause(REPLACED) - .contains(entry(key, original), entry(key, refreshed)) + .contains(Map.entry(key, original), Map.entry(key, refreshed)) .exclusively(); } @@ -725,7 +724,7 @@ public void refresh_put(CacheContext context) { assertThat(context).stats().success(1).failures(0); assertThat(context).removalNotifications().withCause(REPLACED) - .contains(entry(key, original), entry(key, refreshed)) + .contains(Map.entry(key, original), Map.entry(key, refreshed)) .exclusively(); } @@ -766,7 +765,7 @@ public void refresh_invalidate(CacheContext context) { // linearizable await().untilAsserted(() -> assertThat(cache).doesNotContainKey(key)); assertThat(context).removalNotifications().withCause(EXPLICIT) - .contains(entry(key, original), entry(key, refreshed)) + .contains(Map.entry(key, original), Map.entry(key, refreshed)) .exclusively(); } assertThat(context).stats().success(1).failures(0); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LocalCacheSubject.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LocalCacheSubject.java index 7002af7022..e27bbb59d1 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LocalCacheSubject.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LocalCacheSubject.java @@ -125,7 +125,7 @@ private void drain(BoundedLocalCache bounded) { for (;;) { bounded.cleanUp(); - if (bounded.writeBuffer.size() > 0) { + if (!bounded.writeBuffer.isEmpty()) { continue; // additional writes to drain } else if (bounded.evicts() && (bounded.adjustment() != adjustment)) { adjustment = bounded.adjustment(); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ReferenceTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ReferenceTest.java index aca41db5af..3ed9e577fb 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ReferenceTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ReferenceTest.java @@ -28,7 +28,6 @@ import static com.google.common.base.Predicates.not; import static com.google.common.collect.ImmutableMap.toImmutableMap; import static com.google.common.truth.Truth.assertThat; -import static java.util.Map.entry; import static java.util.function.Function.identity; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; @@ -1137,7 +1136,7 @@ public void entrySet_toArray(Map map, CacheContext context) { @CacheSpec(population = Population.FULL, requiresWeakOrSoft = true, removalListener = {Listener.DISABLED, Listener.REJECTING}) public void entrySet_contains(Map map, CacheContext context) { - var entry = entry(new Int(context.firstKey()), + var entry = Map.entry(new Int(context.firstKey()), new Int(context.original().get(context.firstKey()))); assertThat(map.entrySet().contains(entry)).isFalse(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/RefreshAfterWriteTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/RefreshAfterWriteTest.java index 3282922eb7..24a7a138fc 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/RefreshAfterWriteTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/RefreshAfterWriteTest.java @@ -29,7 +29,6 @@ import static com.github.benmanes.caffeine.testing.MapSubject.assertThat; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth8.assertThat; -import static java.util.Map.entry; import static java.util.function.Function.identity; import static org.hamcrest.Matchers.is; import static uk.org.lidalia.slf4jext.ConventionalLevelHierarchy.INFO_LEVELS; @@ -39,6 +38,7 @@ import java.time.temporal.ChronoUnit; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; @@ -228,8 +228,8 @@ public void refreshIfNeeded_discard(LoadingCache cache, CacheContext c assertThat(cache).containsEntry(context.firstKey(), context.absentValue()); assertThat(context).removalNotifications().withCause(REPLACED) - .contains(entry(context.firstKey(), context.original().get(context.firstKey())), - entry(context.firstKey(), context.firstKey())) + .contains(Map.entry(context.firstKey(), context.original().get(context.firstKey())), + Map.entry(context.firstKey(), context.firstKey())) .exclusively(); } @@ -766,7 +766,7 @@ public void put(CacheContext context) { assertThat(cache).containsEntry(key, updated); assertThat(context).stats().success(1).failures(0); assertThat(context).removalNotifications().withCause(REPLACED) - .contains(entry(key, original), entry(key, refreshed)) + .contains(Map.entry(key, original), Map.entry(key, refreshed)) .exclusively(); } @@ -921,11 +921,11 @@ public void ageOf(CacheContext context, FixedRefresh refreshAfterWrite refreshAfterWrite = Expire.ONE_MINUTE) public void ageOf_duration(CacheContext context, FixedRefresh refreshAfterWrite) { // Truncated to seconds to ignore the LSB (nanosecond) used for refreshAfterWrite's lock - assertThat(refreshAfterWrite.ageOf(context.firstKey()).get().toSeconds()).isEqualTo(0); + assertThat(refreshAfterWrite.ageOf(context.firstKey()).orElseThrow().toSeconds()).isEqualTo(0); context.ticker().advance(30, TimeUnit.SECONDS); - assertThat(refreshAfterWrite.ageOf(context.firstKey()).get().toSeconds()).isEqualTo(30); + assertThat(refreshAfterWrite.ageOf(context.firstKey()).orElseThrow().toSeconds()).isEqualTo(30); context.ticker().advance(45, TimeUnit.SECONDS); - assertThat(refreshAfterWrite.ageOf(context.firstKey()).get().toSeconds()).isEqualTo(75); + assertThat(refreshAfterWrite.ageOf(context.firstKey()).orElseThrow().toSeconds()).isEqualTo(75); } @Test(dataProvider = "caches") diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java index dc5c73a1ee..bcb9149051 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java @@ -77,7 +77,7 @@ public void before() { key = "key"; cache = makeAsyncCache(); - policy = cache.synchronous().policy().expireVariably().get(); + policy = cache.synchronous().policy().expireVariably().orElseThrow(); } @AfterMethod @@ -103,7 +103,7 @@ public void readDuringCreate() { // Ran expireAfterCreate (expire: infinite -> create) doCreate.set(true); - await().until(() -> policy.getExpiresAfter(key).get().toNanos() <= EXPIRE_NS); + await().until(() -> policy.getExpiresAfter(key).orElseThrow().toNanos() <= EXPIRE_NS); await().untilTrue(startedRead); // Ran reader (expire: create -> ?) @@ -112,7 +112,7 @@ public void readDuringCreate() { reader.join(); // Ensure expire is [expireAfterCreate], not [infinite] - assertThat(policy.getExpiresAfter(key).get().toNanos()).isAtMost(EXPIRE_NS); + assertThat(policy.getExpiresAfter(key).orElseThrow().toNanos()).isAtMost(EXPIRE_NS); } private AsyncLoadingCache makeAsyncCache() { diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue30Test.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue30Test.java index db3a5c1afc..2e0b3f0fcd 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue30Test.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue30Test.java @@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertWithMessage; import static java.time.ZoneOffset.UTC; +import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -55,7 +56,6 @@ */ @Test(groups = "isolated") @Listeners(CacheValidationListener.class) -@SuppressWarnings({"PreferJavaTimeOverload", "TimeZoneUsage"}) public final class Issue30Test { private static final boolean DEBUG = false; @@ -85,7 +85,7 @@ public Object[][] providesCache() { var source = new ConcurrentHashMap(); var lastLoad = new ConcurrentHashMap(); AsyncLoadingCache cache = Caffeine.newBuilder() - .expireAfterWrite(TTL, TimeUnit.MILLISECONDS) + .expireAfterWrite(Duration.ofMillis(TTL)) .executor(executor) .buildAsync(new Loader(source, lastLoad)); return new Object[][] {{ cache, source, lastLoad }}; @@ -163,6 +163,7 @@ public CompletableFuture asyncLoad(String key, Executor executor) { return CompletableFuture.completedFuture(source.get(key)); } + @SuppressWarnings("TimeZoneUsage") private void reportCacheMiss(String key) { Instant now = Instant.now(); Instant last = lastLoad.get(key); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContextSubject.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContextSubject.java index 5cc7e98f4c..f1709c6b1d 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContextSubject.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheContextSubject.java @@ -50,7 +50,6 @@ import com.github.benmanes.caffeine.testing.Int; import com.google.common.base.CaseFormat; import com.google.common.collect.ImmutableMultiset; -import com.google.common.primitives.Ints; import com.google.common.truth.FailureMetadata; import com.google.common.truth.StandardSubjectBuilder; import com.google.common.truth.Subject; @@ -316,7 +315,7 @@ public void isEmpty() { /** Fails if the number of notifications does not have the given size. */ public void hasSize(long expectedSize) { awaitUntil((type, listener) -> { - check(type).that(listener.removed()).hasSize(Ints.checkedCast(expectedSize)); + check(type).that(listener.removed()).hasSize(Math.toIntExact(expectedSize)); }); } @@ -398,7 +397,7 @@ public void exclusively() { .map(RemovalNotification::getCause) .collect(toImmutableMultiset()); check(type).that(causes).isEqualTo(ImmutableMultiset.builder() - .addCopies(cause, Ints.checkedCast(expectedSize)).build()); + .addCopies(cause, Math.toIntExact(expectedSize)).build()); }); } } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheGenerator.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheGenerator.java index 17f857d980..574dde1737 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheGenerator.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheGenerator.java @@ -42,7 +42,6 @@ import com.github.benmanes.caffeine.testing.Int; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; /** @@ -257,7 +256,7 @@ private static ImmutableList> makeInts() { var builder = new ImmutableList.Builder>(); for (int i = 0; i < size; i++) { Int value = Int.valueOf(BASE + i); - builder.add(Maps.immutableEntry(value, value.negate())); + builder.add(Map.entry(value, value.negate())); } return builder.build(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/testing/CollectionSubject.java b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/CollectionSubject.java index 5b58462d1f..712c6da99c 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/testing/CollectionSubject.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/CollectionSubject.java @@ -25,7 +25,6 @@ import java.util.Queue; import java.util.Set; -import com.google.common.primitives.Ints; import com.google.common.truth.FailureMetadata; /** @@ -51,13 +50,13 @@ public static CollectionSubject assertThat(Collection actual) { /** Fails if the collection does not have the given size. */ public final void hasSize(long expectedSize) { - hasSize(Ints.checkedCast(expectedSize)); + hasSize(Math.toIntExact(expectedSize)); } /** Fails if the collection does not have less than the given size. */ public void hasSizeLessThan(long other) { checkArgument(other >= 0, "expectedSize (%s) must be >= 0", other); - check("size()").that(actual.size()).isLessThan(Ints.checkedCast(other)); + check("size()").that(actual.size()).isLessThan(Math.toIntExact(other)); } /** diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/testing/MapSubject.java b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/MapSubject.java index ffdc988508..43ca915915 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/testing/MapSubject.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/MapSubject.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Range; -import com.google.common.primitives.Ints; import com.google.common.truth.FailureMetadata; import com.google.common.truth.Ordered; @@ -50,13 +49,13 @@ public static MapSubject assertThat(Map actual) { /** Fails if the map does not have the given size. */ public final void hasSize(long expectedSize) { - super.hasSize(Ints.checkedCast(expectedSize)); + super.hasSize(Math.toIntExact(expectedSize)); } /** Fails if the map does not have less than the given size. */ public void hasSizeLessThan(long other) { checkArgument(other >= 0, "expectedSize (%s) must be >= 0", other); - check("size()").that(actual.size()).isLessThan(Ints.checkedCast(other)); + check("size()").that(actual.size()).isLessThan(Math.toIntExact(other)); } /** Fails if the map's size is not in {@code range}. */ diff --git a/gradle/codeQuality.gradle b/gradle/codeQuality.gradle index 16274e6e15..1389fa6827 100644 --- a/gradle/codeQuality.gradle +++ b/gradle/codeQuality.gradle @@ -180,11 +180,9 @@ tasks.withType(Test).configureEach { showExceptions = true showStackTraces = true } - if (System.env.JDK_EA) { - extensions.configure(JacocoTaskExtension) { - it.enabled = (System.env.JDK_EA != 'true') - } + if (System.env.JDK_EA == 'true') { systemProperty 'net.bytebuddy.experimental', true + extensions.configure(JacocoTaskExtension) { it.enabled = true } } } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 86badae380..9386b24819 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -36,7 +36,7 @@ ext { config: '1.4.2', ehcache3: '3.10.2', errorprone: '2.16', - errorproneSupport: '0.3.0', + errorproneSupport: '0.4.0', expiringMap: '0.5.10', fastfilter: '1.0.2', fastutil: '8.5.9', @@ -261,10 +261,11 @@ ext { "org.ow2.asm:asm-bom:${platformVerrsions.asm}", ] restrictions = [ - 'com.fasterxml.jackson:jackson-bom': '2.13.4.20221012', 'com.beust:jcommander': '1.82', + 'com.fasterxml.jackson:jackson-bom': '2.13.4.20221012', 'com.google.protobuf:protobuf-java': '3.21.7', 'com.thoughtworks.xstream:xstream': '1.4.19', + 'org.apache.commons:commons-text': '1.10.0', 'org.apache.httpcomponents:httpclient': '4.5.13', 'org.bouncycastle:bcprov-jdk15on': '1.70', 'org.jsoup:jsoup': '1.15.3', diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntry.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntry.java index 8431a3a2f7..f7b75ca630 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntry.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntry.java @@ -64,7 +64,7 @@ public K getKey() { } else if (value != null) { action = Action.READ; } else if (cacheLoader.isPresent()) { - value = cacheLoader.get().load(key); + value = cacheLoader.orElseThrow().load(key); cacheLoader = Optional.empty(); if (value != null) { action = Action.LOADED; diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/CacheManagerTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/CacheManagerTest.java index a7cef9b2bf..5cca8eb2fd 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/CacheManagerTest.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/CacheManagerTest.java @@ -54,7 +54,7 @@ public void beforeClass() { @Test public void jmxBeanIsRegistered_createCache() throws OperationsException { checkConfigurationJmx(() -> cacheManager.createCache("cache-not-in-config-file", - TypesafeConfigurator.from(ConfigFactory.load(), "test-cache").get())); + TypesafeConfigurator.from(ConfigFactory.load(), "test-cache").orElseThrow())); } @Test diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration/TypesafeConfigurationTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration/TypesafeConfigurationTest.java index 8bed916590..718d10268b 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration/TypesafeConfigurationTest.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/configuration/TypesafeConfigurationTest.java @@ -81,9 +81,9 @@ public void invalidCache() { public void testCache() { Optional> config = TypesafeConfigurator.from(ConfigFactory.load(), "test-cache"); - assertThat(config.get()).isEqualTo(TypesafeConfigurator.from( - ConfigFactory.load(), "test-cache").get()); - checkTestCache(config.get()); + assertThat(config).isEqualTo( + TypesafeConfigurator.from(ConfigFactory.load(), "test-cache")); + checkTestCache(config.orElseThrow()); } @Test @@ -94,13 +94,14 @@ public void testCache2() { TypesafeConfigurator.from(ConfigFactory.load(), "test-cache-2"); assertThat(config1).isNotEqualTo(config2); - assertThat(config2.get().getKeyType()).isAssignableTo(String.class); - assertThat(config2.get().getValueType()).isAssignableTo(Integer.class); - assertThat(config2.get().isNativeStatisticsEnabled()).isFalse(); - assertThat(config2.get().getExpiryPolicyFactory().create().getExpiryForAccess()).isNull(); - assertThat(config2.get().getExpiryFactory().get().create()).isInstanceOf(TestExpiry.class); - assertThat(config2.get().getExecutorFactory().create()).isEqualTo(ForkJoinPool.commonPool()); - assertThat(config2.get().getCacheWriter()).isNull(); + var config = config2.orElseThrow(); + assertThat(config.getKeyType()).isAssignableTo(String.class); + assertThat(config.getValueType()).isAssignableTo(Integer.class); + assertThat(config.isNativeStatisticsEnabled()).isFalse(); + assertThat(config.getExpiryPolicyFactory().create().getExpiryForAccess()).isNull(); + assertThat(config.getExpiryFactory().orElseThrow().create()).isInstanceOf(TestExpiry.class); + assertThat(config.getExecutorFactory().create()).isEqualTo(ForkJoinPool.commonPool()); + assertThat(config.getCacheWriter()).isNull(); } @Test @@ -169,6 +170,6 @@ static void checkRefresh(CaffeineConfiguration config) { static void checkSize(CaffeineConfiguration config) { assertThat(config.getMaximumSize()).isEmpty(); assertThat(config.getMaximumWeight()).hasValue(1_000L); - assertThat(config.getWeigherFactory().get().create()).isInstanceOf(TestWeigher.class); + assertThat(config.getWeigherFactory().orElseThrow().create()).isInstanceOf(TestWeigher.class); } } diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/copy/JavaSerializationCopierTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/copy/JavaSerializationCopierTest.java index 0463b1ab68..99258c4902 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/copy/JavaSerializationCopierTest.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/copy/JavaSerializationCopierTest.java @@ -22,7 +22,6 @@ import java.io.ObjectInputStream; import java.io.ObjectStreamClass; import java.io.UncheckedIOException; -import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -76,7 +75,6 @@ public void deserializable_badData(JavaSerializationCopier copier) { copier.deserialize(new byte[0], Thread.currentThread().getContextClassLoader()); } - @SuppressWarnings("TimeZoneUsage") @Test(expectedExceptions = CacheException.class) public void deserializable_classNotFound() { var copier = new JavaSerializationCopier() { @@ -90,7 +88,7 @@ public void deserializable_classNotFound() { }; } }; - copier.roundtrip(Instant.now(), Thread.currentThread().getContextClassLoader()); + copier.roundtrip(100, Thread.currentThread().getContextClassLoader()); } @Test(dataProvider = "copier") diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryAndMaximumSizeTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryAndMaximumSizeTest.java index cfd90d08fb..d70683d172 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryAndMaximumSizeTest.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryAndMaximumSizeTest.java @@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -83,7 +82,7 @@ protected CaffeineConfiguration getConfiguration() { @Test public void expiry() { jcache.put(KEY_1, VALUE_1); - verify(expiry, times(1)).expireAfterCreate(anyInt(), anyInt(), anyLong()); + verify(expiry).expireAfterCreate(anyInt(), anyInt(), anyLong()); jcache.put(KEY_1, VALUE_2); verify(expiry).expireAfterUpdate(anyInt(), anyInt(), anyLong(), anyLong()); diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryTest.java index 8a9b7a2f55..3d4f236c31 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryTest.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryTest.java @@ -17,7 +17,6 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -63,7 +62,7 @@ protected CaffeineConfiguration getConfiguration() { @Test public void configured() { jcache.put(KEY_1, VALUE_1); - verify(expiry, times(1)).expireAfterCreate(anyInt(), anyInt(), anyLong()); + verify(expiry).expireAfterCreate(anyInt(), anyInt(), anyLong()); jcache.put(KEY_1, VALUE_2); verify(expiry).expireAfterUpdate(anyInt(), anyInt(), anyLong(), anyLong()); diff --git a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntryTest.java b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntryTest.java index 39a65fc2aa..ec5fe4b1dd 100644 --- a/jcache/src/test/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntryTest.java +++ b/jcache/src/test/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntryTest.java @@ -24,8 +24,6 @@ import org.testng.annotations.Test; -import com.google.common.collect.Maps; - /** * @author ben.manes@gmail.com (Ben Manes) */ @@ -54,6 +52,6 @@ public void hash() { @Test public void string() { - assertThat(entry.toString()).isEqualTo(Maps.immutableEntry(1, 2).toString()); + assertThat(entry.toString()).isEqualTo(Map.entry(1, 2).toString()); } } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/BasicSettings.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/BasicSettings.java index c71203ffe6..68685bcf82 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/BasicSettings.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/BasicSettings.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.common.collect.Sets.toImmutableEnumSet; import static java.util.Locale.US; import static java.util.Objects.requireNonNull; @@ -65,7 +66,7 @@ public Set admission() { return config().getStringList("admission").stream() .map(String::toUpperCase) .map(Admission::valueOf) - .collect(toImmutableSet()); + .collect(toImmutableEnumSet()); } public MembershipSettings membership() { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin64/CountMin64TinyLfu.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin64/CountMin64TinyLfu.java index 8f67db4c8d..455725fffd 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin64/CountMin64TinyLfu.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin64/CountMin64TinyLfu.java @@ -17,7 +17,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.admission.Frequency; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -46,7 +45,7 @@ public CountMin64TinyLfu(Config config) { BasicSettings settings = new BasicSettings(config); sketch = new CountMin64(settings.tinyLfu().countMin64().eps(), settings.tinyLfu().countMin64().confidence(), settings.randomSeed()); - sampleSize = Ints.checkedCast(10 * settings.maximumSize()); + sampleSize = Math.toIntExact(10 * settings.maximumSize()); conservative = settings.tinyLfu().conservative(); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/perfect/PerfectFrequency.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/perfect/PerfectFrequency.java index 341cf22770..58dd6d5461 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/perfect/PerfectFrequency.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/perfect/PerfectFrequency.java @@ -17,7 +17,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.admission.Frequency; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2IntMap; @@ -36,7 +35,7 @@ public final class PerfectFrequency implements Frequency { public PerfectFrequency(Config config) { BasicSettings settings = new BasicSettings(config); - sampleSize = Ints.checkedCast(10 * settings.maximumSize()); + sampleSize = Math.toIntExact(10 * settings.maximumSize()); counts = new Long2IntOpenHashMap(); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/table/RandomRemovalFrequencyTable.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/table/RandomRemovalFrequencyTable.java index ccd9a49262..5b003c2a2f 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/table/RandomRemovalFrequencyTable.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/table/RandomRemovalFrequencyTable.java @@ -23,7 +23,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.admission.Frequency; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -52,7 +51,7 @@ public final class RandomRemovalFrequencyTable implements Frequency { public RandomRemovalFrequencyTable(Config config) { BasicSettings settings = new BasicSettings(config); - maxSum = Ints.checkedCast(sampleFactor * settings.maximumSize()); + maxSum = Math.toIntExact(sampleFactor * settings.maximumSize()); random = new Random(settings.randomSeed()); table = new HashMap<>(maxSum); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheAdapter.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheAdapter.java index 5cc61f6205..7b6985aa71 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheAdapter.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheAdapter.java @@ -17,7 +17,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.admission.Frequency; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -40,7 +39,7 @@ public final class TinyCacheAdapter implements Frequency { public TinyCacheAdapter(Config config) { BasicSettings settings = new BasicSettings(config); // number of (independent sets) - int nrSets = Ints.checkedCast(sampleFactor * settings.maximumSize() / 64); + int nrSets = Math.toIntExact(sampleFactor * settings.maximumSize() / 64); tcs = new TinyCacheSketch(nrSets, 64,settings.randomSeed()); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/ArcPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/ArcPolicy.java index 57c82bb117..16b001880f 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/ArcPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/ArcPolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -74,7 +73,7 @@ public final class ArcPolicy implements KeyOnlyPolicy { public ArcPolicy(Config config) { BasicSettings settings = new BasicSettings(config); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.policyStats = new PolicyStats(name()); this.data = new Long2ObjectOpenHashMap<>(); this.headT1 = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CarPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CarPolicy.java index 7b8f399964..6eaea1f387 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CarPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CarPolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -61,7 +60,7 @@ public final class CarPolicy implements KeyOnlyPolicy { public CarPolicy(Config config) { BasicSettings settings = new BasicSettings(config); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.policyStats = new PolicyStats(name()); this.data = new Long2ObjectOpenHashMap<>(); this.headT1 = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CartPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CartPolicy.java index 0e039d3d0f..46efa870e8 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CartPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CartPolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -64,7 +63,7 @@ public final class CartPolicy implements KeyOnlyPolicy { public CartPolicy(Config config) { BasicSettings settings = new BasicSettings(config); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.policyStats = new PolicyStats(name()); this.data = new Long2ObjectOpenHashMap<>(); this.headT1 = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPlusPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPlusPolicy.java index 8b0d6f2af8..c23a67574f 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPlusPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPlusPolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -115,7 +114,7 @@ public final class ClockProPlusPolicy implements KeyOnlyPolicy { public ClockProPlusPolicy(Config config) { ClockProPlusSettings settings = new ClockProPlusSettings(config); - this.maxSize = Ints.checkedCast(settings.maximumSize()); + this.maxSize = Math.toIntExact(settings.maximumSize()); this.maxNonResSize = (int) (maxSize * settings.nonResidentMultiplier()); this.minResColdSize = (int) (maxSize * settings.percentMinCold()); if (minResColdSize < settings.lowerBoundCold()) { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPolicy.java index 866781a3d4..cdff66f54d 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -95,7 +94,7 @@ public final class ClockProPolicy implements KeyOnlyPolicy { public ClockProPolicy(Config config) { ClockProSettings settings = new ClockProSettings(config); - this.maxSize = Ints.checkedCast(settings.maximumSize()); + this.maxSize = Math.toIntExact(settings.maximumSize()); this.maxNonResSize = (int) (maxSize * settings.nonResidentMultiplier()); this.minResColdSize = (int) (maxSize * settings.percentMinCold()); if (minResColdSize < settings.lowerBoundCold()) { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProSimplePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProSimplePolicy.java index 8ad3ff0238..986f3de6a4 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProSimplePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProSimplePolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -99,7 +98,7 @@ public final class ClockProSimplePolicy implements KeyOnlyPolicy { public ClockProSimplePolicy(Config config) { BasicSettings settings = new BasicSettings(config); - this.maxSize = Ints.checkedCast(settings.maximumSize()); + this.maxSize = Math.toIntExact(settings.maximumSize()); this.minColdSize = this.maxSize / 100; this.maxColdSize = this.maxSize - (this.maxSize / 100); this.policyStats = new PolicyStats(name()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java index 8d30d29e51..e281be1688 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java @@ -28,7 +28,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -69,7 +68,7 @@ public final class DClockPolicy implements KeyOnlyPolicy { public DClockPolicy(DClockSettings settings, double percentActive) { this.policyStats = new PolicyStats(name() + " (active: %d%%)", (int) (100 * percentActive)); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maxActive = (int) (percentActive * maximumSize); this.data = new Long2ObjectOpenHashMap<>(); this.headNonResident = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/FrdPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/FrdPolicy.java index f989467456..196daa0c75 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/FrdPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/FrdPolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -61,7 +60,7 @@ public final class FrdPolicy implements KeyOnlyPolicy { public FrdPolicy(Config config) { FrdSettings settings = new FrdSettings(config); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maximumMainResidentSize = (int) (maximumSize * settings.percentMain()); this.maximumFilterSize = maximumSize - maximumMainResidentSize; this.policyStats = new PolicyStats(name()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/HillClimberFrdPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/HillClimberFrdPolicy.java index 7e36d8637c..64e58e31a3 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/HillClimberFrdPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/HillClimberFrdPolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -58,7 +57,7 @@ public final class HillClimberFrdPolicy implements KeyOnlyPolicy { public HillClimberFrdPolicy(Config config) { FrdSettings settings = new FrdSettings(config); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maximumMainResidentSize = (int) (maximumSize * settings.percentMain()); this.maximumFilterSize = maximumSize - maximumMainResidentSize; this.policyStats = new PolicyStats(name()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/IndicatorFrdPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/IndicatorFrdPolicy.java index 7297d9021d..dc4e529d22 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/IndicatorFrdPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/IndicatorFrdPolicy.java @@ -23,7 +23,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.Indicator; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -53,7 +52,7 @@ public final class IndicatorFrdPolicy implements KeyOnlyPolicy { public IndicatorFrdPolicy(Config config) { FrdSettings settings = new FrdSettings(config); this.period = settings.period(); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maximumMainResidentSize = (int) (maximumSize * settings.percentMain()); this.maximumFilterSize = maximumSize - maximumMainResidentSize; this.policyStats = new PolicyStats(name()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/LirsPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/LirsPolicy.java index cab7a283a3..614c14639d 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/LirsPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/LirsPolicy.java @@ -25,7 +25,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -77,7 +76,7 @@ public final class LirsPolicy implements KeyOnlyPolicy { public LirsPolicy(Config config) { LirsSettings settings = new LirsSettings(config); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maximumNonResidentSize = (int) (maximumSize * settings.nonResidentMultiplier()); this.maximumHotSize = (int) (maximumSize * settings.percentHot()); this.policyStats = new PolicyStats(name()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/FrequentlyUsedPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/FrequentlyUsedPolicy.java index 024e23550b..e802e0966f 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/FrequentlyUsedPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/FrequentlyUsedPolicy.java @@ -30,7 +30,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -53,7 +52,7 @@ public final class FrequentlyUsedPolicy implements KeyOnlyPolicy { public FrequentlyUsedPolicy(Admission admission, EvictionPolicy policy, Config config) { BasicSettings settings = new BasicSettings(config); this.policyStats = new PolicyStats(admission.format(policy.label())); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.admittor = admission.from(config, policyStats); this.data = new Long2ObjectOpenHashMap<>(); this.policy = requireNonNull(policy); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/MultiQueuePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/MultiQueuePolicy.java index d212094cd2..2c43ce80ad 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/MultiQueuePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/MultiQueuePolicy.java @@ -24,7 +24,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap; @@ -64,7 +63,7 @@ public final class MultiQueuePolicy implements KeyOnlyPolicy { public MultiQueuePolicy(Config config) { MultiQueueSettings settings = new MultiQueueSettings(config); - maximumSize = Ints.checkedCast(settings.maximumSize()); + maximumSize = Math.toIntExact(settings.maximumSize()); threshold = new long[settings.numberOfQueues()]; headQ = new Node[settings.numberOfQueues()]; out = new Long2ObjectLinkedOpenHashMap<>(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/S4LruPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/S4LruPolicy.java index c4280bd5d8..0df3b8856f 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/S4LruPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/S4LruPolicy.java @@ -29,7 +29,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -60,7 +59,7 @@ public final class S4LruPolicy implements KeyOnlyPolicy { public S4LruPolicy(Admission admission, Config config) { S4LruSettings settings = new S4LruSettings(config); this.policyStats = new PolicyStats(admission.format(name())); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.admittor = admission.from(config, policyStats); this.data = new Long2ObjectOpenHashMap<>(); this.levels = settings.levels(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/SegmentedLruPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/SegmentedLruPolicy.java index 7cc6406060..99c6fe4b87 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/SegmentedLruPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/SegmentedLruPolicy.java @@ -27,7 +27,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -73,7 +72,7 @@ public SegmentedLruPolicy(Admission admission, Config config) { this.headProtected = new Node(); this.headProbation = new Node(); this.data = new Long2ObjectOpenHashMap<>(); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maxProtected = (int) (maximumSize * settings.percentProtected()); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/opt/ClairvoyantPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/opt/ClairvoyantPolicy.java index 73200ee03b..1dff1d5e26 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/opt/ClairvoyantPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/opt/ClairvoyantPolicy.java @@ -23,7 +23,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy; import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue; @@ -54,7 +53,7 @@ public final class ClairvoyantPolicy implements Policy { public ClairvoyantPolicy(Config config) { BasicSettings settings = new BasicSettings(config); - maximumSize = Ints.checkedCast(settings.maximumSize()); + maximumSize = Math.toIntExact(settings.maximumSize()); accessTimes = new Long2ObjectOpenHashMap<>(); policyStats = new PolicyStats(name()); infiniteTimestamp = Integer.MAX_VALUE; diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/ExpiringMapPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/ExpiringMapPolicy.java index d2692deec4..c0832a5a29 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/ExpiringMapPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/ExpiringMapPolicy.java @@ -26,7 +26,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.CaseFormat; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import net.jodah.expiringmap.ExpirationPolicy; @@ -45,7 +44,7 @@ public final class ExpiringMapPolicy implements KeyOnlyPolicy { public ExpiringMapPolicy(ExpiringMapSettings settings, Eviction policy) { policyStats = new PolicyStats(name() + " (%s)", policy); cache = ExpiringMap.builder() - .maxSize(Ints.checkedCast(settings.maximumSize())) + .maxSize(Math.toIntExact(settings.maximumSize())) .expirationPolicy(policy.type) .build(); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/HazelcastPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/HazelcastPolicy.java index b8ff79fd60..a9166f473d 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/HazelcastPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/HazelcastPolicy.java @@ -30,7 +30,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.CaseFormat; import com.google.common.base.Enums; -import com.google.common.primitives.Ints; import com.hazelcast.config.EvictionConfig; import com.hazelcast.config.EvictionPolicy; import com.hazelcast.config.InMemoryFormat; @@ -57,7 +56,7 @@ public final class HazelcastPolicy implements KeyOnlyPolicy { public HazelcastPolicy(HazelcastSettings settings, EvictionPolicy policy) { policyStats = new PolicyStats(name() + " (%s)", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, policy.name())); - maximumSize = Ints.checkedCast(settings.maximumSize()); + maximumSize = Math.toIntExact(settings.maximumSize()); var config = new NearCacheConfig() .setSerializeKeys(false) .setInMemoryFormat(InMemoryFormat.OBJECT) diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/TCachePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/TCachePolicy.java index a987141524..7e8970484f 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/TCachePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/TCachePolicy.java @@ -26,7 +26,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.CaseFormat; -import com.google.common.primitives.Ints; import com.trivago.triava.tcache.Cache; import com.trivago.triava.tcache.EvictionPolicy; import com.trivago.triava.tcache.TCacheFactory; @@ -45,7 +44,7 @@ public final class TCachePolicy implements KeyOnlyPolicy { public TCachePolicy(TCacheSettings settings, Eviction policy) { policyStats = new PolicyStats(name() + " (%s)", policy); cache = TCacheFactory.standardFactory().builder() - .setMaxElements(Ints.checkedCast(settings.maximumSize())) + .setMaxElements(Math.toIntExact(settings.maximumSize())) .setEvictionPolicy(policy.type) .setStatistics(true) .build(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java index 68b7a234c3..2ea542c4e8 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java @@ -35,7 +35,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -71,7 +70,7 @@ public SampledPolicy(Admission admission, EvictionPolicy policy, Config config) this.admittor = admission.from(config, policyStats); SampledSettings settings = new SampledSettings(config); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.sampleStrategy = settings.sampleStrategy(); this.random = new Random(settings.randomSeed()); this.data = new Long2ObjectOpenHashMap<>(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/WindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/WindowTinyLfuPolicy.java index 8e7324a7a4..f1b4aff641 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/WindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/WindowTinyLfuPolicy.java @@ -29,7 +29,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -72,7 +71,7 @@ public final class WindowTinyLfuPolicy implements KeyOnlyPolicy { public WindowTinyLfuPolicy(double percentMain, WindowTinyLfuSettings settings) { this.policyStats = new PolicyStats(name() + " (%.0f%%)", 100 * (1.0d - percentMain)); this.admittor = new TinyLfu(settings.config(), policyStats); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); int maxMain = (int) (maximumSize * percentMain); this.maxProtected = (int) (maxMain * settings.percentMainProtected()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberWindowTinyLfuPolicy.java index b9294ca600..42de0252f4 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberWindowTinyLfuPolicy.java @@ -21,7 +21,7 @@ import static com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber.QueueType.PROTECTED; import static com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber.QueueType.WINDOW; import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.common.collect.Sets.toImmutableEnumSet; import static java.util.Locale.US; import java.util.HashSet; @@ -41,7 +41,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber.QueueType; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -77,7 +76,7 @@ public final class HillClimberWindowTinyLfuPolicy implements KeyOnlyPolicy { public HillClimberWindowTinyLfuPolicy(HillClimberType strategy, double percentMain, HillClimberWindowTinyLfuSettings settings) { - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); int maxMain = (int) (maximumSize * percentMain); this.maxProtected = (int) (maxMain * settings.percentMainProtected()); this.maxWindow = maximumSize - maxMain; @@ -382,7 +381,7 @@ public ImmutableSet strategy() { return config().getStringList("hill-climber-window-tiny-lfu.strategy").stream() .map(strategy -> strategy.replace('-', '_').toUpperCase(US)) .map(HillClimberType::valueOf) - .collect(toImmutableSet()); + .collect(toImmutableEnumSet()); } } } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Adam.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Adam.java index c56ebde708..ea082c0811 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Adam.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Adam.java @@ -19,7 +19,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -41,7 +40,7 @@ public final class Adam extends AbstractClimber { public Adam(Config config) { AdamSettings settings = new AdamSettings(config); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); sampleSize = (int) (settings.percentSample() * maximumSize); stepSize = (int) (settings.percentPivot() * maximumSize); epsilon = settings.epsilon(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/AmsGrad.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/AmsGrad.java index 7f7419b9a7..82189b1fed 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/AmsGrad.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/AmsGrad.java @@ -19,7 +19,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -42,7 +41,7 @@ public final class AmsGrad extends AbstractClimber { public AmsGrad(Config config) { AmsGradSettings settings = new AmsGradSettings(config); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); sampleSize = (int) (settings.percentSample() * maximumSize); stepSize = (int) (settings.percentPivot() * maximumSize); epsilon = settings.epsilon(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Nadam.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Nadam.java index 96159c8d02..1ae7ffc594 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Nadam.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Nadam.java @@ -19,7 +19,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -42,7 +41,7 @@ public final class Nadam extends AbstractClimber { public Nadam(Config config) { NadamSettings settings = new NadamSettings(config); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); sampleSize = (int) (settings.percentSample() * maximumSize); stepSize = (int) (settings.percentPivot() * maximumSize); epsilon = settings.epsilon(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Stochastic.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Stochastic.java index 12d90fe9bc..ea716eaec5 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Stochastic.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Stochastic.java @@ -21,7 +21,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -53,7 +52,7 @@ public final class Stochastic extends AbstractClimber { public Stochastic(Config config) { StochasticSettings settings = new StochasticSettings(config); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); sampleSize = (int) (settings.percentSample() * maximumSize); stepSize = (int) (settings.percentPivot() * maximumSize); acceleration = settings.acceleration(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimpleClimber.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimpleClimber.java index 5bbda302b3..2b29a4fa06 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimpleClimber.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimpleClimber.java @@ -17,7 +17,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -38,7 +37,7 @@ public final class SimpleClimber extends AbstractClimber { public SimpleClimber(Config config) { SimpleClimberSettings settings = new SimpleClimberSettings(config); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); this.initialSampleSize = (int) (settings.percentSample() * maximumSize); this.initialStepSize = settings.percentPivot() * maximumSize; this.restartThreshold = settings.restartThreshold(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimulatedAnnealingClimber.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimulatedAnnealingClimber.java index 4c7f6f9091..a56efde28e 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimulatedAnnealingClimber.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimulatedAnnealingClimber.java @@ -19,7 +19,6 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -41,7 +40,7 @@ public final class SimulatedAnnealingClimber extends AbstractClimber { public SimulatedAnnealingClimber(Config config) { SimulatedAnnealingSettings settings = new SimulatedAnnealingSettings(config); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); this.initialStepSize = (int) (settings.percentPivot() * maximumSize); this.sampleSize = (int) (settings.percentSample() * maximumSize); this.coolDownTolerance = 100 * settings.coolDownTolerance(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference/IndicatorClimber.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference/IndicatorClimber.java index 389526ce90..f2dcf0003a 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference/IndicatorClimber.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference/IndicatorClimber.java @@ -18,7 +18,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.sketch.Indicator; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimberWindowTinyLfuPolicy.HillClimberWindowTinyLfuSettings; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -34,7 +33,7 @@ public final class IndicatorClimber implements HillClimber { public IndicatorClimber(Config config) { HillClimberWindowTinyLfuSettings settings = new HillClimberWindowTinyLfuSettings(config); - this.cacheSize = Ints.checkedCast(settings.maximumSize()); + this.cacheSize = Math.toIntExact(settings.maximumSize()); this.prevPercent = 1 - settings.percentMain().get(0); this.indicator = new Indicator(config); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim/MiniSimClimber.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim/MiniSimClimber.java index b3ed8ab228..b57ab07d4f 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim/MiniSimClimber.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim/MiniSimClimber.java @@ -23,7 +23,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; @@ -51,7 +50,7 @@ public final class MiniSimClimber implements HillClimber { public MiniSimClimber(Config config) { MiniSimSettings settings = new MiniSimSettings(config); - this.cacheSize = Ints.checkedCast(settings.maximumSize()); + this.cacheSize = Math.toIntExact(settings.maximumSize()); R = (cacheSize / 1000) > 100 ? 1000 : (cacheSize / 100); WindowTinyLfuSettings simulationSettings = new WindowTinyLfuSettings(ConfigFactory .parseString("maximum-size = " + cacheSize / R) diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackTinyLfuPolicy.java index be2f982d4c..a81b748212 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackTinyLfuPolicy.java @@ -26,7 +26,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; @@ -65,7 +64,7 @@ public final class FeedbackTinyLfuPolicy implements KeyOnlyPolicy { public FeedbackTinyLfuPolicy(Config config) { this.policyStats = new PolicyStats(name()); FeedbackTinyLfuSettings settings = new FeedbackTinyLfuSettings(config); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.admittor = new TinyLfu(settings.config(), policyStats); this.data = new Long2ObjectOpenHashMap<>(); this.head = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackWindowTinyLfuPolicy.java index bbcd5612ec..7f4216fcec 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackWindowTinyLfuPolicy.java @@ -30,7 +30,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; @@ -82,7 +81,7 @@ public final class FeedbackWindowTinyLfuPolicy implements KeyOnlyPolicy { public FeedbackWindowTinyLfuPolicy(double percentMain, FeedbackWindowTinyLfuSettings settings) { this.policyStats = new PolicyStats(name() + " (%.0f%%)", 100 * (1.0d - percentMain)); this.admittor = new TinyLfu(settings.config(), policyStats); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); int maxMain = (int) (maximumSize * percentMain); this.maxProtected = (int) (maxMain * settings.percentMainProtected()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/FullySegmentedWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/FullySegmentedWindowTinyLfuPolicy.java index f18752b2c7..a9f8dc7dd8 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/FullySegmentedWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/FullySegmentedWindowTinyLfuPolicy.java @@ -30,7 +30,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.github.benmanes.caffeine.cache.simulator.policy.linked.SegmentedLruPolicy; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -65,7 +64,7 @@ public final class FullySegmentedWindowTinyLfuPolicy implements KeyOnlyPolicy { public FullySegmentedWindowTinyLfuPolicy( double percentMain, FullySegmentedWindowTinyLfuSettings settings) { this.policyStats = new PolicyStats(name() + " (%.0f%%)", 100 * (1.0d - percentMain)); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); int maxMain = (int) (maximumSize * percentMain); this.maxWindow = maximumSize - maxMain; this.maxMainProtected = (int) (maxMain * settings.percentMainProtected()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/LruWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/LruWindowTinyLfuPolicy.java index d962197829..f383cae109 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/LruWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/LruWindowTinyLfuPolicy.java @@ -29,7 +29,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -56,7 +55,7 @@ public final class LruWindowTinyLfuPolicy implements KeyOnlyPolicy { public LruWindowTinyLfuPolicy(double percentMain, LruWindowTinyLfuSettings settings) { this.policyStats = new PolicyStats(name() + " (%.0f%%)", 100 * (1.0d - percentMain)); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); this.admittor = new TinyLfu(settings.config(), policyStats); this.maxMain = (int) (maximumSize * percentMain); this.data = new Long2ObjectOpenHashMap<>(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/RandomWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/RandomWindowTinyLfuPolicy.java index 74bcc03104..6e5b63c7f9 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/RandomWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/RandomWindowTinyLfuPolicy.java @@ -29,7 +29,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -55,7 +54,7 @@ public final class RandomWindowTinyLfuPolicy implements KeyOnlyPolicy { public RandomWindowTinyLfuPolicy(double percentMain, RandomWindowTinyLfuSettings settings) { policyStats = new PolicyStats(name() + " (%.0f%%)", 100 * (1.0d - percentMain)); - maximumSize = Ints.checkedCast(settings.maximumSize()); + maximumSize = Math.toIntExact(settings.maximumSize()); admittor = new TinyLfu(settings.config(), policyStats); random = new Random(settings.randomSeed()); data = new Long2ObjectOpenHashMap<>(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/S4WindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/S4WindowTinyLfuPolicy.java index d0317b288b..2ea8adbaa7 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/S4WindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/S4WindowTinyLfuPolicy.java @@ -30,7 +30,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -60,7 +59,7 @@ public final class S4WindowTinyLfuPolicy implements KeyOnlyPolicy { public S4WindowTinyLfuPolicy(double percentMain, S4WindowTinyLfuSettings settings) { this.policyStats = new PolicyStats(name() + " (%.0f%%)", 100 * (1.0d - percentMain)); this.admittor = new TinyLfu(settings.config(), policyStats); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maxMain = (int) (maximumSize * percentMain); this.maxWindow = maximumSize - maxMain; this.data = new Long2ObjectOpenHashMap<>(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCachePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCachePolicy.java index b9eaad4c52..b5c94c7b7b 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCachePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCachePolicy.java @@ -20,7 +20,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy; import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -34,7 +33,7 @@ public final class TinyCachePolicy implements KeyOnlyPolicy { public TinyCachePolicy(Config config) { this.policyStats = new PolicyStats(name()); BasicSettings settings = new BasicSettings(config); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); tinyCache = new TinyCache((int) Math.ceil(maximumSize / 64.0), 64, settings.randomSeed()); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCacheWithGhostCachePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCacheWithGhostCachePolicy.java index 4b04ec4670..099a43b363 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCacheWithGhostCachePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCacheWithGhostCachePolicy.java @@ -20,7 +20,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy; import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -34,7 +33,7 @@ public final class TinyCacheWithGhostCachePolicy implements KeyOnlyPolicy { public TinyCacheWithGhostCachePolicy(Config config) { this.policyStats = new PolicyStats(name()); BasicSettings settings = new BasicSettings(config); - int maximumSize = Ints.checkedCast(settings.maximumSize()); + int maximumSize = Math.toIntExact(settings.maximumSize()); tinyCache = new TinyCacheWithGhostCache((int) Math.ceil(maximumSize / 64.0), 64, settings.randomSeed()); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/WindowTinyCachePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/WindowTinyCachePolicy.java index a46283511f..e2496966d8 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/WindowTinyCachePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/WindowTinyCachePolicy.java @@ -21,7 +21,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy; import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -36,7 +35,7 @@ public final class WindowTinyCachePolicy implements KeyOnlyPolicy { public WindowTinyCachePolicy(Config config) { policyStats = new PolicyStats(name()); BasicSettings settings = new BasicSettings(config); - int maxSize = Ints.checkedCast(settings.maximumSize()); + int maxSize = Math.toIntExact(settings.maximumSize()); if (maxSize <= 64) { window = null; } else { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TuQueuePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TuQueuePolicy.java index 561859b797..591beb1641 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TuQueuePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TuQueuePolicy.java @@ -22,7 +22,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -76,7 +75,7 @@ public TuQueuePolicy(Config config) { this.headCold = new Node(); this.data = new Long2ObjectOpenHashMap<>(); this.policyStats = new PolicyStats(name()); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maxHot = (int) (maximumSize * settings.percentHot()); this.maxWarm = (int) (maximumSize * settings.percentWarm()); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TwoQueuePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TwoQueuePolicy.java index 04e62e4cf2..88f9ccf2ee 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TwoQueuePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TwoQueuePolicy.java @@ -20,7 +20,6 @@ import com.github.benmanes.caffeine.cache.simulator.policy.Policy.PolicySpec; import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; -import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -66,7 +65,7 @@ public TwoQueuePolicy(Config config) { this.headMain = new Node(); this.data = new Long2ObjectOpenHashMap<>(); this.policyStats = new PolicyStats(name()); - this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maximumSize = Math.toIntExact(settings.maximumSize()); this.maxIn = (int) (maximumSize * settings.percentIn()); this.maxOut = (int) (maximumSize * settings.percentOut()); }