All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.client.hotrod.impl.RemoteCacheKeySet Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.client.hotrod.impl;

import java.util.AbstractSet;
import java.util.Collection;
import java.util.Spliterator;
import java.util.stream.Stream;

import org.infinispan.commons.util.CloseableIterator;
import org.infinispan.commons.util.CloseableIteratorSet;
import org.infinispan.commons.util.CloseableSpliterator;
import org.infinispan.commons.util.Closeables;
import org.infinispan.commons.util.IntSet;
import org.infinispan.commons.util.RemovableCloseableIterator;

class RemoteCacheKeySet extends AbstractSet implements CloseableIteratorSet {
   private final InternalRemoteCache remoteCache;
   private final IntSet segments;

   RemoteCacheKeySet(InternalRemoteCache remoteCache, IntSet segments) {
      this.remoteCache = remoteCache;
      this.segments = segments;
   }

   @Override
   public CloseableIterator iterator() {
      CloseableIterator keyIterator = remoteCache.keyIterator(segments);
      return new RemovableCloseableIterator<>(keyIterator, this::remove);
   }

   @Override
   public CloseableSpliterator spliterator() {
      return Closeables.spliterator(iterator(), Long.MAX_VALUE, Spliterator.NONNULL | Spliterator.CONCURRENT |
            Spliterator.DISTINCT);
   }

   @Override
   public Stream stream() {
      return Closeables.stream(spliterator(), false);
   }

   @Override
   public Stream parallelStream() {
      return Closeables.stream(spliterator(), true);
   }

   @Override
   public int size() {
      return remoteCache.size();
   }

   @Override
   public void clear() {
      remoteCache.clear();
   }

   @Override
   public boolean contains(Object o) {
      return remoteCache.containsKey(o);
   }

   @Override
   public boolean remove(Object o) {
      return remoteCache.remove(o) != null;
   }

   @Override
   public boolean removeAll(Collection c) {
      boolean removedSomething = false;
      for (Object key : c) {
         removedSomething |= remove(key);
      }
      return removedSomething;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy