From 00ff445bf710c83df7f14b748d0043dfd2e9ae68 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Thu, 11 May 2017 02:02:04 -0700 Subject: [PATCH] IntelliJ static analysis cleanup IntelliJ seems to have some import quirks which this reduces. It seems to still get confused, after a few edits forget about sibling modules, and complains about imports to those classes. Eclipse is a lot smarter. Resolved IntelliJ compilation issues by degrading to raw types, even though javac is happy. Ran their static analyzer and fixed all issues that could be somewhat justified. Most were dead code removals. Hopefully this makes the project a little friendlier for those who want to hack with that IDE. --- build.gradle | 13 ++++-- caffeine/build.gradle | 4 ++ .../benmanes/caffeine/cache/Feature.java | 9 +---- .../caffeine/cache/NodeFactoryGenerator.java | 2 +- .../caffeine/cache/Specifications.java | 6 --- .../caffeine/cache/local/AddConstructor.java | 6 ++- .../cache/local/AddExpirationTicker.java | 7 +--- .../caffeine/cache/local/AddMaximum.java | 7 +--- .../caffeine/cache/local/AddWriteBuffer.java | 7 +--- .../benmanes/caffeine/cache/node/AddKey.java | 5 +-- .../caffeine/cache/node/NodeRule.java | 5 ++- .../caffeine/SingleConsumerQueue.java | 6 +-- .../caffeine/cache/BoundedBuffer.java | 7 ++-- .../caffeine/cache/BoundedLocalCache.java | 38 +++++++++--------- .../benmanes/caffeine/cache/Caffeine.java | 40 +++++++------------ .../cache/LocalAsyncLoadingCache.java | 2 +- .../caffeine/cache/UnboundedLocalCache.java | 2 +- .../caffeine/cache/BoundedLocalCacheTest.java | 5 +-- config/findbugs/exclude.xml | 6 ++- gradle/jmh.gradle | 2 - .../caffeine/jcache/CacheFactory.java | 3 +- .../integration/DisabledCacheWriter.java | 4 +- .../caffeine/jcache/processor/Action.java | 2 +- .../cache/simulator/BasicSettings.java | 10 +---- .../caffeine/cache/simulator/Simulator.java | 2 +- .../cache/simulator/admission/Admission.java | 3 +- .../admission/countmin4/CountMin4.java | 2 +- .../tinycache/HashFunctionParser.java | 6 +-- .../admission/tinycache/TinyCache.java | 8 ---- .../admission/tinycache/TinyCacheAdapter.java | 2 +- .../admission/tinycache/TinyCacheSketch.java | 5 --- .../tinycache/TinyCacheWithGhostCache.java | 5 --- .../cache/simulator/parser/TraceFormat.java | 2 +- .../wikipedia/WikipediaTraceReader.java | 3 +- .../simulator/policy/adaptive/ArcPolicy.java | 2 +- .../simulator/policy/adaptive/CarPolicy.java | 2 +- .../simulator/policy/adaptive/CartPolicy.java | 4 +- .../simulator/policy/irr/ClockProPolicy.java | 2 +- .../simulator/policy/irr/LirsPolicy.java | 4 +- .../policy/linked/FrequentlyUsedPolicy.java | 6 +-- .../simulator/policy/linked/LinkedPolicy.java | 16 -------- .../policy/linked/MultiQueuePolicy.java | 13 ------ .../simulator/policy/linked/S4LruPolicy.java | 13 ------ .../policy/linked/SegmentedLruPolicy.java | 2 +- .../policy/opt/ClairvoyantPolicy.java | 2 +- .../policy/sampled/SampledPolicy.java | 2 +- .../sketch/climbing/HillClimberType.java | 2 +- .../HillClimberWindowTinyLfuPolicy.java | 2 +- .../feedback/FeedbackTinyLfuPolicy.java | 9 ----- .../segment/LruWindowTinyLfuPolicy.java | 4 -- .../sketch/segment/S4WindowTinyLfuPolicy.java | 6 +-- .../sketch/tinycache/TinyCachePolicy.java | 2 - .../policy/two_queue/TuQueuePolicy.java | 2 +- .../policy/two_queue/TwoQueuePolicy.java | 2 +- .../cache/simulator/report/ReportFormat.java | 2 +- 55 files changed, 110 insertions(+), 225 deletions(-) diff --git a/build.gradle b/build.gradle index b83a265a7f..570c406704 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,9 @@ allprojects { subprojects { apply plugin: 'com.github.ethankhall.semantic-versioning' apply plugin: 'nebula.provided-base' + apply plugin: 'eclipse' apply plugin: 'java' + apply plugin: 'idea' apply plugin: 'osgi' apply from: "${rootDir}/gradle/publish.gradle" @@ -73,6 +75,10 @@ subprojects { } archivesBaseName = path[1..-1].replaceAll(':', '-').toLowerCase() + idea.module { + scopes.PROVIDED.plus += [ configurations.provided ] + } + dependencies { provided libraries.jsr305 provided libraries.error_prone_annotations @@ -128,6 +134,9 @@ task jacocoMerge(type: JacocoMerge) { publishedProjects.each { subproject -> executionData subproject.tasks.withType(Test) } + doFirst { + executionData = files(executionData.findAll { it.exists() }) + } } task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') { @@ -143,10 +152,6 @@ task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') { html.enabled = true // human readable xml.enabled = true // required by coveralls } - - doFirst { - executionData = files(executionData.findAll { it.exists() }) - } } coveralls { diff --git a/caffeine/build.gradle b/caffeine/build.gradle index ea148331ae..1da6e6df75 100644 --- a/caffeine/build.gradle +++ b/caffeine/build.gradle @@ -14,6 +14,10 @@ configurations { javaAgent } +idea.module { + scopes.PROVIDED.plus += [ configurations.javaPoetCompile ] +} + plugins.withType(EclipsePlugin) { project.eclipse.classpath.plusConfigurations += [ configurations.javaPoetCompile ] } 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 e46a6f475b..4342af7ab5 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 @@ -99,10 +99,6 @@ public static boolean usesExpirationTicker(Set features) { || features.contains(Feature.REFRESH_WRITE); } - public static boolean usesStatsTicker(Set features) { - return features.contains(Feature.STATS); - } - public static boolean usesMaximum(Set features) { return features.contains(Feature.MAXIMUM_SIZE) || features.contains(Feature.MAXIMUM_WEIGHT); @@ -111,9 +107,6 @@ public static boolean usesMaximum(Set features) { public static boolean usesFastPath(Set features) { Set incompatible = Sets.immutableEnumSet(Feature.EXPIRE_ACCESS, Feature.WEAK_KEYS, Feature.INFIRM_VALUES, Feature.WEAK_VALUES, Feature.SOFT_VALUES); - if (features.stream().anyMatch(incompatible::contains)) { - return false; - } - return usesMaximum(features); + return !features.stream().anyMatch(incompatible::contains) && usesMaximum(features); } } diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java index 595d0a3a14..0d8d2f8c67 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java @@ -219,7 +219,7 @@ private void addGetFactoryMethods() { .build()); } - private void generatedNodes() throws IOException { + private void generatedNodes() { fillClassNameToFeatures(); classNameToFeatures.forEach((className, features) -> { String higherKey = classNameToFeatures.higherKey(className); diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Specifications.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Specifications.java index f0cecee521..ef658dd354 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Specifications.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Specifications.java @@ -63,7 +63,6 @@ public final class Specifications { public static final ParameterSpec valueRefQueueSpec = ParameterSpec.builder(vRefQueueType, "valueReferenceQueue").build(); - public static final ParameterSpec weightSpec = ParameterSpec.builder(int.class, "weight").build(); public static final TypeName NODE = ParameterizedTypeName.get(nodeType, kTypeVar, vTypeVar); public static final TypeName UNSAFE_ACCESS = ClassName.get("com.github.benmanes.caffeine.base", "UnsafeAccess"); @@ -86,11 +85,6 @@ public final class Specifications { public static final TypeName TICKER = ClassName.get(PACKAGE_NAME, "Ticker"); - public static final TypeName WEIGHER = ParameterizedTypeName.get( - ClassName.get(PACKAGE_NAME, "Weigher"), - TypeVariableName.get("? super K"), - TypeVariableName.get("? super V")); - public static final TypeName ACCESS_ORDER_DEQUE = ParameterizedTypeName.get( ClassName.get(PACKAGE_NAME, "AccessOrderDeque"), NODE); diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddConstructor.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddConstructor.java index 6074565921..a0871f4320 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddConstructor.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddConstructor.java @@ -15,6 +15,7 @@ */ package com.github.benmanes.caffeine.cache.local; +import static com.github.benmanes.caffeine.cache.Specifications.BOUNDED_LOCAL_CACHE; import static com.github.benmanes.caffeine.cache.Specifications.BUILDER_PARAM; import static com.github.benmanes.caffeine.cache.Specifications.CACHE_LOADER_PARAM; @@ -32,10 +33,13 @@ protected boolean applies() { @Override protected void execute() { + String cacheLoader = context.superClass.equals(BOUNDED_LOCAL_CACHE) + ? "(CacheLoader) cacheLoader" + : "cacheLoader"; context.constructor .addParameter(BUILDER_PARAM) .addParameter(CACHE_LOADER_PARAM) .addParameter(boolean.class, "async") - .addStatement("super(builder, (CacheLoader) cacheLoader, async)"); + .addStatement("super(builder, $L, async)", cacheLoader); } } diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddExpirationTicker.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddExpirationTicker.java index a03cbfe334..06468a9ff7 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddExpirationTicker.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddExpirationTicker.java @@ -28,11 +28,8 @@ public final class AddExpirationTicker extends LocalCacheRule { @Override protected boolean applies() { - if (Feature.usesExpirationTicker(context.parentFeatures) - || !Feature.usesExpirationTicker(context.generateFeatures)) { - return false; - } - return true; + return !(Feature.usesExpirationTicker(context.parentFeatures) + || !Feature.usesExpirationTicker(context.generateFeatures)); } @Override diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddMaximum.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddMaximum.java index 136a7bf660..b8823caf76 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddMaximum.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddMaximum.java @@ -33,11 +33,8 @@ public final class AddMaximum extends LocalCacheRule { @Override protected boolean applies() { - if (Feature.usesMaximum(context.parentFeatures) - || !Feature.usesMaximum(context.generateFeatures)) { - return false; - } - return true; + return !(Feature.usesMaximum(context.parentFeatures) + || !Feature.usesMaximum(context.generateFeatures)); } @Override diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddWriteBuffer.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddWriteBuffer.java index dd9f02fd72..3a767b7be8 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddWriteBuffer.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddWriteBuffer.java @@ -29,11 +29,8 @@ public final class AddWriteBuffer extends LocalCacheRule { @Override protected boolean applies() { - if (Feature.usesWriteQueue(context.parentFeatures) - || !Feature.usesWriteQueue(context.generateFeatures)) { - return false; - } - return true; + return !(Feature.usesWriteQueue(context.parentFeatures) + || !Feature.usesWriteQueue(context.generateFeatures)); } @Override diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node/AddKey.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node/AddKey.java index d4169eee06..b41ebae1ce 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node/AddKey.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node/AddKey.java @@ -75,11 +75,8 @@ private TypeName keyReferenceType() { /** Adds a constructor assignment. */ private void addKeyConstructorAssignment(MethodSpec.Builder constructor, boolean isReference) { if (isReference || isStrongKeys()) { - String refAssignment = isStrongKeys() - ? "(K) keyReference" - : "(WeakKeyReference) keyReference"; constructor.addStatement("$T.UNSAFE.putObject(this, $N, $N)", - UNSAFE_ACCESS, offsetName("key"), isReference ? refAssignment : "key"); + UNSAFE_ACCESS, offsetName("key"), isReference ? "keyReference" : "key"); } else { constructor.addStatement("$T.UNSAFE.putObject(this, $N, new $T($N, $N))", UNSAFE_ACCESS, offsetName("key"), keyReferenceType(), "key", "keyReferenceQueue"); diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node/NodeRule.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node/NodeRule.java index 64602b528f..e128794dcd 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node/NodeRule.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/node/NodeRule.java @@ -140,14 +140,15 @@ private Strength strengthOf(Feature feature) { } protected enum Strength { - STRONG, WEAK, SOFT; + STRONG, WEAK, SOFT, } protected enum Visibility { IMMEDIATE(false), LAZY(true); final boolean isRelaxed; - private Visibility(boolean mode) { + + Visibility(boolean mode) { this.isRelaxed = mode; } } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/SingleConsumerQueue.java b/caffeine/src/main/java/com/github/benmanes/caffeine/SingleConsumerQueue.java index 492683e4d8..4322322072 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/SingleConsumerQueue.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/SingleConsumerQueue.java @@ -146,7 +146,7 @@ private SingleConsumerQueue(Function> factory) { for (int i = 0; i < ARENA_LENGTH; i++) { arena[i] = new AtomicReference<>(); } - Node node = new Node(null); + Node node = new Node<>(null); this.factory = factory; lazySetTail(node); head = node; @@ -275,7 +275,7 @@ public boolean addAll(Collection c) { first = factory.apply(e); last = first; } else { - Node newLast = new Node(e); + Node newLast = new Node<>(e); last.lazySetNext(newLast); last = newLast; } @@ -438,7 +438,7 @@ Node awaitNext() { static final long serialVersionUID = 1; Object writeReplace() { - return new SerializationProxy(this); + return new SerializationProxy<>(this); } private void readObject(ObjectInputStream stream) throws InvalidObjectException { diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedBuffer.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedBuffer.java index 2500af480d..c3eb71e9dc 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedBuffer.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedBuffer.java @@ -15,6 +15,8 @@ */ package com.github.benmanes.caffeine.cache; +import static com.github.benmanes.caffeine.cache.BoundedBuffer.OFFSET; + import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.function.Consumer; @@ -64,7 +66,6 @@ static final class RingBuffer extends BBHeader.ReadAndWriteCounterRef impleme @SuppressWarnings({"unchecked", "cast", "rawtypes"}) public RingBuffer(E e) { - super(OFFSET); buffer = new AtomicReferenceArray<>(SPACED_SIZE); buffer.lazySet(0, e); } @@ -152,8 +153,8 @@ static abstract class ReadAndWriteCounterRef extends PadWriteCounter { volatile long writeCounter; - ReadAndWriteCounterRef(int writes) { - UnsafeAccess.UNSAFE.putOrderedLong(this, WRITE_OFFSET, writes); + ReadAndWriteCounterRef() { + UnsafeAccess.UNSAFE.putOrderedLong(this, WRITE_OFFSET, OFFSET); } long relaxedWriteCounter() { diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java index cd893bd3c6..84ed3afd8c 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java @@ -931,7 +931,6 @@ void refreshIfNeeded(Node node, long now) { * * @param key the key of the entry that was created * @param value the value of the entry that was created - * @param node the entry in the page replacement policy * @param now the current time, in nanoseconds * @return the expiration time */ @@ -1000,11 +999,10 @@ void setAccessTime(Node node, long now) { /** * Performs the post-processing work required after a write. * - * @param node the node that was written to * @param task the pending operation to be applied * @param now the current time, in nanoseconds */ - void afterWrite(@Nullable Node node, Runnable task, long now) { + void afterWrite(Runnable task, long now) { if (buffersWrites()) { for (int i = 0; i < WRITE_BUFFER_RETRIES; i++) { if (writeBuffer().offer(task)) { @@ -1092,7 +1090,7 @@ public void cleanUp() { /** * Performs the maintenance work, blocking until the lock is acquired. Any exception thrown, such - * as by {@link CacheWriter#delete()}, is propagated to the caller. + * as by {@link CacheWriter#delete}, is propagated to the caller. * * @param task an additional pending task to run, or {@code null} if not present */ @@ -1654,13 +1652,13 @@ V put(K key, V value, boolean notifyWriter, boolean onlyIfAbsent) { return computed; }); if (prior == node) { - afterWrite(node, new AddTask(node, newWeight), now); + afterWrite(new AddTask(node, newWeight), now); return null; } } else { prior = data.putIfAbsent(node.getKeyReference(), node); if (prior == null) { - afterWrite(node, new AddTask(node, newWeight), now); + afterWrite(new AddTask(node, newWeight), now); return null; } } @@ -1711,7 +1709,7 @@ V put(K key, V value, boolean notifyWriter, boolean onlyIfAbsent) { if (expired) { notifyRemoval(key, oldValue, RemovalCause.EXPIRED); } else if (oldValue == null) { - notifyRemoval(key, oldValue, RemovalCause.COLLECTED); + notifyRemoval(key, /* oldValue */ null, RemovalCause.COLLECTED); } else if (mayUpdate && (value != oldValue)) { notifyRemoval(key, oldValue, RemovalCause.REPLACED); } @@ -1719,9 +1717,9 @@ V put(K key, V value, boolean notifyWriter, boolean onlyIfAbsent) { int weightedDifference = mayUpdate ? (newWeight - oldWeight) : 0; if ((oldValue == null) || (weightedDifference != 0) || expired) { - afterWrite(prior, new UpdateTask(prior, weightedDifference), now); + afterWrite(new UpdateTask(prior, weightedDifference), now); } else if (!onlyIfAbsent && expiresAfterWrite() && withinTolerance) { - afterWrite(prior, new UpdateTask(prior, weightedDifference), now); + afterWrite(new UpdateTask(prior, weightedDifference), now); } else { if (mayUpdate) { setWriteTime(prior, now); @@ -1775,7 +1773,7 @@ V removeNoWriter(Object key) { K castKey = (K) key; notifyRemoval(castKey, oldValue, cause); } - afterWrite(node, new RemovalTask(node), 0L); + afterWrite(new RemovalTask(node), 0L); return (cause == RemovalCause.EXPLICIT) ? oldValue : null; } @@ -1813,7 +1811,7 @@ V removeWithWriter(Object key) { }); if (cause[0] != null) { - afterWrite(node[0], new RemovalTask(node[0]), now); + afterWrite(new RemovalTask(node[0]), now); if (hasRemovalListener()) { notifyRemoval(castKey, oldValue[0], cause[0]); } @@ -1864,7 +1862,7 @@ public boolean remove(Object key, Object value) { } else if (hasRemovalListener()) { notifyRemoval(oldKey[0], oldValue[0], cause[0]); } - afterWrite(removed[0], new RemovalTask(removed[0]), now); + afterWrite(new RemovalTask(removed[0]), now); return (cause[0] == RemovalCause.EXPLICIT); } @@ -1910,7 +1908,7 @@ public V replace(K key, V value) { int weightedDifference = (weight - oldWeight[0]); if (expiresAfterWrite() || (weightedDifference != 0)) { - afterWrite(node, new UpdateTask(node, weightedDifference), now); + afterWrite(new UpdateTask(node, weightedDifference), now); } else { afterRead(node, now, /* recordHit */ false); } @@ -1966,7 +1964,7 @@ public boolean replace(K key, V oldValue, V newValue) { int weightedDifference = (weight - oldWeight[0]); if (expiresAfterWrite() || (weightedDifference != 0)) { - afterWrite(node, new UpdateTask(node, weightedDifference), now); + afterWrite(new UpdateTask(node, weightedDifference), now); } else { afterRead(node, now, /* recordHit */ false); } @@ -2084,7 +2082,7 @@ V doComputeIfAbsent(K key, Object keyRef, if (node == null) { if (removed[0] != null) { - afterWrite(null, new RemovalTask(removed[0]), now); + afterWrite(new RemovalTask(removed[0]), now); } return null; } @@ -2104,10 +2102,10 @@ V doComputeIfAbsent(K key, Object keyRef, return oldValue[0]; } if ((oldValue[0] == null) && (cause[0] == null)) { - afterWrite(node, new AddTask(node, weight[1]), now); + afterWrite(new AddTask(node, weight[1]), now); } else { int weightedDifference = (weight[1] - weight[0]); - afterWrite(node, new UpdateTask(node, weightedDifference), now); + afterWrite(new UpdateTask(node, weightedDifference), now); } return newValue[0]; @@ -2265,15 +2263,15 @@ V remap(K key, Object keyRef, BiFunction rema } if (removed[0] != null) { - afterWrite(removed[0], new RemovalTask(removed[0]), now); + afterWrite(new RemovalTask(removed[0]), now); } else if (node == null) { // absent and not computable } else if ((oldValue[0] == null) && (cause[0] == null)) { - afterWrite(node, new AddTask(node, weight[1]), now); + afterWrite(new AddTask(node, weight[1]), now); } else { int weightedDifference = weight[1] - weight[0]; if (expiresAfterWrite() || (weightedDifference != 0)) { - afterWrite(node, new UpdateTask(node, weightedDifference), now); + afterWrite(new UpdateTask(node, weightedDifference), now); } else { if (cause[0] == null) { if (!isComputingAsync(node)) { diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java index 7fb7a4d07d..1f7330e91d 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java @@ -128,7 +128,7 @@ public final class Caffeine { static final Logger logger = Logger.getLogger(Caffeine.class.getName()); static final Supplier ENABLED_STATS_COUNTER_SUPPLIER = ConcurrentStatsCounter::new; - enum Strength { STRONG, WEAK, SOFT } + enum Strength { WEAK, SOFT } static final int UNSET_INT = -1; static final int DEFAULT_INITIAL_CAPACITY = 0; @@ -194,7 +194,7 @@ static void requireState(boolean expression, String template, Object... args) { */ @Nonnull public static Caffeine newBuilder() { - return new Caffeine(); + return new Caffeine<>(); } /** @@ -398,12 +398,12 @@ long getMaximum() { return isWeighted() ? maximumWeight : maximumSize; } - @Nonnull @SuppressWarnings("unchecked") + @Nonnull @SuppressWarnings({"unchecked", "rawtypes"}) Weigher getWeigher(boolean isAsync) { Weigher delegate = isWeighted() && (weigher != Weigher.singletonWeigher()) ? Weigher.boundedWeigher((Weigher) weigher) : Weigher.singletonWeigher(); - return isAsync ? (Weigher) new AsyncWeigher<>(delegate) : delegate; + return isAsync ? (Weigher) new AsyncWeigher(delegate) : delegate; } /** @@ -435,10 +435,6 @@ boolean isStrongKeys() { return (keyStrength == null); } - boolean isWeakKeys() { - return (keyStrength == Strength.WEAK); - } - /** * Specifies that each value (not key) stored in the cache should be wrapped in a * {@link WeakReference} (by default, strong references are used). @@ -473,10 +469,6 @@ boolean isWeakValues() { return (valueStrength == Strength.WEAK); } - boolean isSoftValues() { - return (valueStrength == Strength.SOFT); - } - /** * Specifies that each value (not key) stored in the cache should be wrapped in a * {@link SoftReference} (by default, strong references are used). Softly-referenced objects will @@ -722,16 +714,12 @@ public Caffeine removalListener( return self; } + @SuppressWarnings({"unchecked", "rawtypes"}) RemovalListener getRemovalListener(boolean async) { - @SuppressWarnings("unchecked") RemovalListener castedListener = (RemovalListener) removalListener; - if (async && (castedListener != null)) { - @SuppressWarnings("unchecked") - RemovalListener asyncListener = (RemovalListener) - new AsyncRemovalListener(castedListener, getExecutor()); - return asyncListener; - } - return castedListener; + return async && (castedListener != null) + ? new AsyncRemovalListener(castedListener, getExecutor()) + : castedListener; } /** @@ -856,8 +844,8 @@ public Cache build() { @SuppressWarnings("unchecked") Caffeine self = (Caffeine) this; return isBounded() || refreshes() - ? new BoundedLocalCache.BoundedLocalManualCache(self) - : new UnboundedLocalCache.UnboundedLocalManualCache(self); + ? new BoundedLocalCache.BoundedLocalManualCache<>(self) + : new UnboundedLocalCache.UnboundedLocalManualCache<>(self); } /** @@ -883,8 +871,8 @@ public LoadingCache build( @SuppressWarnings("unchecked") Caffeine self = (Caffeine) this; return isBounded() || refreshes() - ? new BoundedLocalCache.BoundedLocalLoadingCache(self, loader) - : new UnboundedLocalCache.UnboundedLocalLoadingCache(self, loader); + ? new BoundedLocalCache.BoundedLocalLoadingCache<>(self, loader) + : new UnboundedLocalCache.UnboundedLocalLoadingCache<>(self, loader); } /** @@ -938,8 +926,8 @@ public AsyncLoadingCache buildAsync( @SuppressWarnings("unchecked") Caffeine self = (Caffeine) this; return isBounded() || refreshes() - ? new BoundedLocalCache.BoundedLocalAsyncLoadingCache(self, loader) - : new UnboundedLocalCache.UnboundedLocalAsyncLoadingCache(self, loader); + ? new BoundedLocalCache.BoundedLocalAsyncLoadingCache<>(self, loader) + : new UnboundedLocalCache.UnboundedLocalAsyncLoadingCache<>(self, loader); } void requireNonLoadingCache() { diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncLoadingCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncLoadingCache.java index 8c5c8ae387..e8d57947bb 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncLoadingCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncLoadingCache.java @@ -106,7 +106,7 @@ public CompletableFuture getIfPresent(@Nonnull Object key) { public CompletableFuture get(@Nonnull K key, @Nonnull Function mappingFunction) { requireNonNull(mappingFunction); - return get(key, (k1, executor) -> CompletableFuture.supplyAsync( + return get(key, (k1, executor) -> CompletableFuture.supplyAsync( () -> mappingFunction.apply(key), executor)); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java index 39ce2ba928..b08975518b 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java @@ -576,7 +576,7 @@ public boolean remove(Object obj) { @Override public Iterator iterator() { - return new KeyIterator(cache); + return new KeyIterator<>(cache); } @Override 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 be5d3647d4..f65bdb000e 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 @@ -432,10 +432,9 @@ public void exceedsMaximumBufferSize_onRead(Cache cache, Cache population = Population.EMPTY, maximumSize = Maximum.FULL) public void exceedsMaximumBufferSize_onWrite(Cache cache, CacheContext context) { BoundedLocalCache localCache = asBoundedLocalCache(cache); - Node dummy = localCache.nodeFactory.newNode(null, null, null, 1, 0); boolean[] ran = new boolean[1]; - localCache.afterWrite(dummy, () -> ran[0] = true, 0); + localCache.afterWrite(() -> ran[0] = true, 0); assertThat(ran[0], is(true)); assertThat(localCache.writeBuffer().size(), is(0)); @@ -481,7 +480,7 @@ public void afterWrite_drainFullWriteBuffer(Cache cache, Cache int[] triggered = { 0 }; Runnable triggerTask = () -> triggered[0] = 1 + expectedCount[0]; - localCache.afterWrite(null, triggerTask, 0L); + localCache.afterWrite(triggerTask, 0L); assertThat(processed[0], is(expectedCount[0])); assertThat(triggered[0], is(expectedCount[0] + 1)); diff --git a/config/findbugs/exclude.xml b/config/findbugs/exclude.xml index 0b423e84f2..1b4cf14d51 100644 --- a/config/findbugs/exclude.xml +++ b/config/findbugs/exclude.xml @@ -1,4 +1,8 @@ - + + diff --git a/gradle/jmh.gradle b/gradle/jmh.gradle index c711eb244f..a22dd23f0a 100644 --- a/gradle/jmh.gradle +++ b/gradle/jmh.gradle @@ -4,8 +4,6 @@ apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'me.champeau.gradle.jmh' apply plugin: 'io.morethan.jmhreport' -apply plugin: 'eclipse' -apply plugin: 'idea' idea.module { scopes.PROVIDED.plus += [ configurations.jmh ] diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheFactory.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheFactory.java index 1f332ffe58..481e9d537d 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheFactory.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheFactory.java @@ -216,11 +216,10 @@ private boolean configureExpireVariably() { return config.getExpireAfterWrite().isPresent(); } - private boolean configureRefreshAfterWrite() { + private void configureRefreshAfterWrite() { if (config.getRefreshAfterWrite().isPresent()) { caffeine.refreshAfterWrite(config.getRefreshAfterWrite().getAsLong(), TimeUnit.NANOSECONDS); } - return config.getRefreshAfterWrite().isPresent(); } /** Configures the removal listener. */ diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/integration/DisabledCacheWriter.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/integration/DisabledCacheWriter.java index 9b590c9b5d..db53b04b7b 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/integration/DisabledCacheWriter.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/integration/DisabledCacheWriter.java @@ -41,10 +41,10 @@ public static CacheWriter get() { } @Override - public void write(Entry entry) {} + public void write(Entry entry) {} @Override - public void writeAll(Collection> entries) {} + public void writeAll(Collection> entries) {} @Override public void delete(Object key) {} diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/Action.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/Action.java index 2d47dc6622..b7cdd6aa9e 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/Action.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/Action.java @@ -37,5 +37,5 @@ public enum Action { LOADED, /** The entry existed and was deleted. */ - DELETED; + DELETED, } 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 f6015bf46b..4466312b94 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 @@ -150,7 +150,7 @@ public int interval() { } public final class PeriodicSettings { public DoorkeeperSettings doorkeeper() { - return new DoorkeeperSettings("tiny-lfu.count-min-4.periodic"); + return new DoorkeeperSettings(); } } } @@ -161,16 +161,10 @@ public double eps() { public double confidence() { return config().getDouble("tiny-lfu.count-min-64.confidence"); } - public int sampleSize() { - return config().getInt("tiny-lfu.count-min-64.sample_size"); - } } public final class DoorkeeperSettings { - private final String basePath; + private static final String basePath = "tiny-lfu.count-min-4.periodic"; - DoorkeeperSettings(String basePath) { - this.basePath = basePath; - } public boolean enabled() { return config().getBoolean(basePath + ".doorkeeper.enabled"); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/Simulator.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/Simulator.java index 1539cf3a1b..5d2292e8e5 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/Simulator.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/Simulator.java @@ -99,7 +99,7 @@ public Receive createReceive() { } /** Broadcast the trace events to all of the policy actors. */ - private void broadcast() throws IOException { + private void broadcast() { try (LongStream events = eventStream()) { LongArrayList batch = new LongArrayList(batchSize); for (PrimitiveIterator.OfLong i = events.iterator(); i.hasNext();) { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/Admission.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/Admission.java index b274ffbb43..10540d3f64 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/Admission.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/Admission.java @@ -34,8 +34,7 @@ public enum Admission { private final BiFunction factory; private final Function formatter; - private Admission(BiFunction factory, - Function formatter) { + Admission(BiFunction factory, Function formatter) { this.formatter = formatter; this.factory = factory; } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin4/CountMin4.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin4/CountMin4.java index e55ee417da..ea589e9c69 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin4/CountMin4.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin4/CountMin4.java @@ -35,9 +35,9 @@ public abstract class CountMin4 implements Frequency { 0xc3a5c85c97cb3127L, 0xb492b66fbe98f273L, 0x9ae16a3b2f90404fL, 0xcbf29ce484222325L}; static final long RESET_MASK = 0x7777777777777777L; + protected final boolean conservative; protected final int randomSeed; - protected boolean conservative; protected int tableMask; protected long[] table; protected int step = 1; diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/HashFunctionParser.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/HashFunctionParser.java index 918e88d337..2eea49380b 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/HashFunctionParser.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/HashFunctionParser.java @@ -27,7 +27,7 @@ public final class HashFunctionParser { private static final byte fpMask = (byte) 255; // (all bits in byte are 1, (logical value of -1)); private static final long chainMask = 63L; // (6 first bit are set to 1). private final int nrSets; - public HashedItem fpaux; // used just to avoid allocating new memory as a return value. + public final HashedItem fpaux; // used just to avoid allocating new memory as a return value. private final static long Seed64 = 0xe17a1465; private final static long m = 0xc6a4a7935bd1e995L; private final static int r = 47; @@ -37,10 +37,6 @@ public HashFunctionParser(int nrsets) { fpaux = new HashedItem(fpMask, fpMask, fpMask, 0L); } - public HashedItem createHash(Object item) { - return createHash(item.hashCode()); - } - public HashedItem createHash(long item) { long h = (Seed64) ^ (m); item *= m; diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCache.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCache.java index 20b1ddbc99..755926508e 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCache.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCache.java @@ -70,11 +70,6 @@ public boolean contains(long item) { /** * Implementing add and remove together in one function, means that less items are shifted. * (reduction of 3 times from trivial implementation). - * - * @param fpaux - * @param victim - * @param bucketStart - * @return */ private int replace(HashedItem fpaux, byte victim, int bucketStart, int removedOffset) { byte chainId = fpaux.chainId; @@ -88,8 +83,6 @@ private int replace(HashedItem fpaux, byte victim, int bucketStart, int removedO return removedOffset; } - public void recordItem(long item) {} - public boolean addItem(long item) { hashFunc.createHash(item); int bucketStart = this.itemsPerSet * hashFunc.fpaux.set; @@ -111,7 +104,6 @@ private boolean selectVictim(int bucketStart) { if (TinySetIndexing.chainExist(chainIndex[hashFunc.fpaux.set], victimChain)) { replace(hashFunc.fpaux, (byte) victimChain, bucketStart, victimOffset); return true; - } else { throw new RuntimeException("Failed to replace"); } 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 d55ae61637..aa675dc17e 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 @@ -26,7 +26,7 @@ */ public final class TinyCacheAdapter implements Frequency { // the actual data structure. - TinyCacheSketch tcs; + final TinyCacheSketch tcs; // size between cache and sample. static final int sampleFactor = 10; // max frequency estimation of an item. diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheSketch.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheSketch.java index 3e672c69c1..51abda3228 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheSketch.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheSketch.java @@ -72,11 +72,6 @@ public int countItem(long item) { /** * Implementing add and remove together in one function, means that less items are shifted. * (reduction of 3 times from trivial implementation). - * - * @param fpaux - * @param victim - * @param bucketStart - * @return */ private int replace(HashedItem fpaux, byte victim, int bucketStart, int removedOffset) { byte chainId = fpaux.chainId; diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheWithGhostCache.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheWithGhostCache.java index 497b91b8f1..78969e4431 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheWithGhostCache.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheWithGhostCache.java @@ -74,11 +74,6 @@ public boolean contains(long item) { /** * Implementing add and remove together in one function, means that less items are shifted. * (reduction of 3 times from trivial implementation). - * - * @param fpaux - * @param victim - * @param bucketStart - * @return */ private int replace(HashedItem fpaux, byte victim, int bucketStart, int removedOffset) { byte chainId = fpaux.chainId; diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java index 511b8f5ee3..071e60c40e 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java @@ -47,7 +47,7 @@ public enum TraceFormat { private final Function, TraceReader> factory; - private TraceFormat(Function, TraceReader> factory) { + TraceFormat(Function, TraceReader> factory) { this.factory = factory; } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/wikipedia/WikipediaTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/wikipedia/WikipediaTraceReader.java index 90dbce3b4f..0478cda0d0 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/wikipedia/WikipediaTraceReader.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/wikipedia/WikipediaTraceReader.java @@ -102,10 +102,9 @@ private String getPath(String url) { if (index == -1) { return url; } - String path = url.substring(index + 1); // Replace the html entities that we want to search for inside paths - String cleansed = path; + String cleansed = url.substring(index + 1); for (int i = 0; i < SEARCH_LIST.length; i++) { cleansed = StringUtils.replace(cleansed, SEARCH_LIST[i], REPLACEMENT_LIST[i]); } 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 8df5a76c0a..1e126ebb95 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 @@ -235,7 +235,7 @@ public void finished() { private enum QueueType { T1, B1, - T2, B2; + T2, B2, } static final class 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 3ef5d11faf..086ea36b43 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 @@ -253,7 +253,7 @@ public void finished() { private enum QueueType { T1, B1, - T2, B2; + T2, B2, } static final class 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 0f7950940f..dce49575a3 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 @@ -318,12 +318,12 @@ public void finished() { private enum QueueType { T1, B1, - T2, B2; + T2, B2, } private enum FilterType { ShortTerm, - LongTerm; + LongTerm, } static final class Node { 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 6e298abea7..ff19eadec8 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 @@ -307,7 +307,7 @@ public void finished() { } enum Status { - HOT, COLD, TEST; + HOT, COLD, TEST, } private static final class Node { 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 403a8bfadf..863450dcb6 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 @@ -342,7 +342,7 @@ private void printLirs() { enum Status { LIR, HIR_RESIDENT, - HIR_NON_RESIDENT; + HIR_NON_RESIDENT, } // S holds three types of blocks, LIR blocks, resident HIR blocks, non-resident HIR blocks @@ -357,7 +357,7 @@ enum StackType { // stack, Q, with its size of Lhirs. Q, // Adaption to facilitate the search of the non-resident HIR blocks - NR; + NR, } // Each entry in the stack records the LIR/HIR status of a block and its residence status, 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 bcd8444124..0604a463f4 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 @@ -54,7 +54,7 @@ public FrequentlyUsedPolicy(Admission admission, EvictionPolicy policy, Config c this.data = new Long2ObjectOpenHashMap<>(); this.maximumSize = settings.maximumSize(); this.policy = requireNonNull(policy); - this.freq0 = new FrequencyNode(0); + this.freq0 = new FrequencyNode(); } /** Returns all variations of this policy based on the configuration parameters. */ @@ -170,11 +170,11 @@ static final class FrequencyNode { FrequencyNode prev; FrequencyNode next; - public FrequencyNode(int count) { + public FrequencyNode() { nextNode = new Node(this); - this.count = count; this.prev = this; this.next = this; + this.count = 0; } public FrequencyNode(int count, FrequencyNode prev) { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/LinkedPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/LinkedPolicy.java index 6e5283a955..f5f9bdc7b6 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/LinkedPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/LinkedPolicy.java @@ -15,7 +15,6 @@ */ package com.github.benmanes.caffeine.cache.simulator.policy.linked; -import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toSet; @@ -223,21 +222,6 @@ public void remove() { key = Long.MIN_VALUE; } - /** Moves the node to the head. */ - public void moveToHead() { - checkState(key != Long.MIN_VALUE); - - // unlink - prev.next = next; - next.prev = prev; - - // link - next = sentinel.next; - prev = sentinel; - sentinel.next = this; - next.prev = this; - } - /** Moves the node to the tail. */ public void moveToTail() { requireNonNull(key); 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 86ca2995a1..9a3b4617b7 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 @@ -186,19 +186,6 @@ public void appendToTail(Node head) { prev = tail; } - /** Moves the node to the tail. */ - public void moveToTail(Node head) { - // unlink - prev.next = next; - next.prev = prev; - - // link - next = head; - prev = head.prev; - head.prev = this; - prev.next = this; - } - /** Removes the node from the list. */ public void remove() { checkState(key != Long.MIN_VALUE); 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 1424842992..3dded29e9e 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 @@ -190,19 +190,6 @@ public void appendToTail(Node head) { prev = tail; } - /** Moves the node to the tail. */ - public void moveToTail(Node head) { - // unlink - prev.next = next; - next.prev = prev; - - // link - next = head; - prev = head.prev; - head.prev = this; - prev.next = this; - } - /** Removes the node from the list. */ public void remove() { checkState(key != Long.MIN_VALUE); 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 e5d566a6e6..09f5bb1631 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 @@ -150,7 +150,7 @@ public PolicyStats stats() { enum QueueType { PROTECTED, - PROBATION; + PROBATION, } static final class Node { 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 7ae73d7b86..7aa7f2fdc4 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 @@ -113,7 +113,7 @@ private void process(long key) { /** Removes the entry whose next access is farthest away into the future. */ private void evict() { - data.rem(data.lastInt()); + data.remove(data.lastInt()); policyStats.recordEviction(); } } 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 58407eca9d..8e058d7031 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 @@ -134,7 +134,7 @@ public enum Sample { GUESS { @Override public List sample(E[] elements, E candidate, int sampleSize, Random random, PolicyStats policyStats) { - List sample = new ArrayList(sampleSize); + List sample = new ArrayList<>(sampleSize); policyStats.addOperations(sampleSize); for (int i = 0; i < sampleSize; i++) { int index = random.nextInt(elements.length); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberType.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberType.java index 9e298c9fc6..e529373eba 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberType.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberType.java @@ -33,7 +33,7 @@ enum HillClimberType { private final Function factory; - private HillClimberType(Function factory) { + HillClimberType(Function factory) { this.factory = requireNonNull(factory); } 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 63e482e60b..2004aeae3a 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 @@ -360,7 +360,7 @@ public double percentMainProtected() { public Set strategy() { return config().getStringList("hill-climber-window-tiny-lfu.strategy").stream() .map(strategy -> strategy.replace('-', '_').toUpperCase()) - .map(strategy -> HillClimberType.valueOf(strategy)) + .map(HillClimberType::valueOf) .collect(toSet()); } } 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 c2e9ec9ca0..c923426f6c 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 @@ -203,15 +203,6 @@ public void moveToTail(Node head) { appendToTail(head); } - /** Appends the node to the tail of the list. */ - public void appendToHead(Node head) { - Node first = head.next; - head.next = this; - first.prev = this; - prev = head; - next = first; - } - /** Appends the node to the tail of the list. */ public void appendToTail(Node head) { Node tail = head.prev; 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 7889748797..32482388a0 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 @@ -157,10 +157,6 @@ public Node(long key, Status status) { this.key = key; } - public boolean isInQueue() { - return next != null; - } - public void moveToTail(Node head) { remove(); appendToTail(head); 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 23785d9f7f..4ee29e51ef 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 @@ -45,13 +45,13 @@ public final class S4WindowTinyLfuPolicy implements Policy { private final Admittor admittor; private final Node[] headMainQ; private final int maximumSize; + private final int[] sizeMainQ; private final Node headEden; private final int maxMain; private final int maxEden; private final int levels; private int sizeEden; - private int[] sizeMainQ; public S4WindowTinyLfuPolicy(double percentMain, S4WindowTinyLfuSettings settings) { String name = String.format("sketch.S4WindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); @@ -212,10 +212,6 @@ static Node sentinel(int level) { return node; } - public boolean isInQueue() { - return next != null; - } - public void moveToTail(Node head) { remove(); appendToTail(head); 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 86a5a3a40e..41d9b69e79 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 @@ -46,11 +46,9 @@ public static Set policies(Config config) { @Override public void record(long key) { if (tinyCache.contains(key)) { - tinyCache.recordItem(key); policyStats.recordHit(); } else { boolean evicted = tinyCache.addItem(key); - tinyCache.recordItem(key); policyStats.recordMiss(); if (evicted) { policyStats.recordEviction(); 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 bdc5240ac0..d203da7bca 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 @@ -171,7 +171,7 @@ public void finished() { enum QueueType { HOT, WARM, - COLD; + COLD, } static final class Node { 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 a6d3b92a19..88d338d955 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 @@ -186,7 +186,7 @@ public PolicyStats stats() { enum QueueType { MAIN, IN, - OUT; + OUT, } static final class Node { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/report/ReportFormat.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/report/ReportFormat.java index 7201d236ca..576c23289c 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/report/ReportFormat.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/report/ReportFormat.java @@ -33,7 +33,7 @@ public enum ReportFormat { private final Function factory; - private ReportFormat(Function factory) { + ReportFormat(Function factory) { this.factory = requireNonNull(factory); }