diff --git a/modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java b/modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java index 0442a7d35ebf6..cab05732ba1c4 100644 --- a/modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java +++ b/modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java @@ -236,10 +236,10 @@ static class ConcatenatedIterables implements Iterable { this.iterables = iterables; } - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({ "unchecked" }) @Override public Iterator iterator() { - Iterator[] iterators = (Iterator[]) new Iterator[iterables.length]; + Iterator[] iterators = (Iterator[]) new Iterator[iterables.length]; for (int i = 0; i < iterables.length; i++) { iterators[i] = iterables[i].iterator(); } diff --git a/modules/cache-common/src/test/java/org/opensearch/cache/common/tier/MockDiskCache.java b/modules/cache-common/src/test/java/org/opensearch/cache/common/tier/MockDiskCache.java index 2a3b1caf73732..548c5d846dda5 100644 --- a/modules/cache-common/src/test/java/org/opensearch/cache/common/tier/MockDiskCache.java +++ b/modules/cache-common/src/test/java/org/opensearch/cache/common/tier/MockDiskCache.java @@ -81,12 +81,7 @@ public void invalidateAll() { @Override public Iterable keys() { - return new Iterable() { - @Override - public Iterator iterator() { - return new CacheKeyIterator<>(cache, removalListener); - } - }; + return () -> new CacheKeyIterator<>(cache, removalListener); } @Override @@ -169,11 +164,11 @@ public Builder setValueSerializer(Serializer valueSerializer) { * @param Type of key * @param Type of value */ - class CacheKeyIterator implements Iterator { + static class CacheKeyIterator implements Iterator { private final Iterator> entryIterator; private final Map cache; private final RemovalListener removalListener; - private K lastKey; + private K currentKey; public CacheKeyIterator(Map cache, RemovalListener removalListener) { this.entryIterator = cache.entrySet().iterator(); @@ -192,19 +187,19 @@ public K next() { throw new NoSuchElementException(); } Map.Entry entry = entryIterator.next(); - lastKey = entry.getKey(); - return lastKey; + currentKey = entry.getKey(); + return currentKey; } @Override public void remove() { - if (lastKey == null) { + if (currentKey == null) { throw new IllegalStateException("No element to remove"); } - V value = cache.get(lastKey); - cache.remove(lastKey); - this.removalListener.onRemoval(new RemovalNotification<>(lastKey, value, RemovalReason.INVALIDATED)); - lastKey = null; + V value = cache.get(currentKey); + cache.remove(currentKey); + this.removalListener.onRemoval(new RemovalNotification<>(currentKey, value, RemovalReason.INVALIDATED)); + currentKey = null; } } }