diff --git a/triemap/src/main/java/tech/pantheon/triemap/AbstractKeySet.java b/triemap/src/main/java/tech/pantheon/triemap/AbstractKeySet.java index dc6e19e..d27b75f 100644 --- a/triemap/src/main/java/tech/pantheon/triemap/AbstractKeySet.java +++ b/triemap/src/main/java/tech/pantheon/triemap/AbstractKeySet.java @@ -78,18 +78,24 @@ public final Spliterator spliterator() { abstract int spliteratorCharacteristics(); final Iterator immutableIterator() { - return new Iterator() { - private final ImmutableIterator itr = map().immutableIterator(); - - @Override - public boolean hasNext() { - return itr.hasNext(); - } - - @Override - public K next() { - return itr.next().getKey(); - } - }; + return new Itr<>(map().immutableIterator()); + } + + private static final class Itr implements Iterator { + private final ImmutableIterator delegate; + + Itr(final ImmutableIterator delegate) { + this.delegate = delegate; + } + + @Override + public boolean hasNext() { + return delegate.hasNext(); + } + + @Override + public K next() { + return delegate.next().getKey(); + } } } diff --git a/triemap/src/main/java/tech/pantheon/triemap/MutableKeySet.java b/triemap/src/main/java/tech/pantheon/triemap/MutableKeySet.java index f4dce60..bf8ca42 100644 --- a/triemap/src/main/java/tech/pantheon/triemap/MutableKeySet.java +++ b/triemap/src/main/java/tech/pantheon/triemap/MutableKeySet.java @@ -32,24 +32,7 @@ final class MutableKeySet extends AbstractKeySet { @Override public Iterator iterator() { - return new Iterator() { - private final AbstractIterator itr = map().iterator(); - - @Override - public boolean hasNext() { - return itr.hasNext(); - } - - @Override - public K next() { - return itr.next().getKey(); - } - - @Override - public void remove() { - itr.remove(); - } - }; + return new Itr<>(map().iterator()); } @Override @@ -67,4 +50,27 @@ public boolean remove(final Object o) { int spliteratorCharacteristics() { return Spliterator.DISTINCT | Spliterator.CONCURRENT | Spliterator.NONNULL; } + + private static final class Itr implements Iterator { + private final AbstractIterator delegate; + + Itr(final AbstractIterator delegate) { + this.delegate = delegate; + } + + @Override + public boolean hasNext() { + return delegate.hasNext(); + } + + @Override + public K next() { + return delegate.next().getKey(); + } + + @Override + public void remove() { + delegate.remove(); + } + } }