org.infinispan.util.CacheCollectionMapper Maven / Gradle / Ivy
package org.infinispan.util;
import java.util.function.Function;
import org.infinispan.CacheCollection;
import org.infinispan.CacheStream;
import org.infinispan.commons.util.CloseableIterator;
import org.infinispan.commons.util.CloseableIteratorMapper;
import org.infinispan.commons.util.CloseableSpliterator;
import org.infinispan.commons.util.CloseableSpliteratorMapper;
/**
* A {@link CacheCollection} that allows for a different set to be mapped as
* a different instance with values replaced on request. This is useful as a
* cache collection that is normally lazily evaluated to prevent having to
* pull all values into memory which can be a lot faster when checking single
* values and can also prevent out of memory issues.
*
* @param Type of elements in collection before transformation
* @param Type of elements in collection after transformation
* @since 9.0
*/
public class CacheCollectionMapper extends CollectionMapper implements CacheCollection {
protected final CacheCollection realCacheCollection;
public CacheCollectionMapper(CacheCollection realCollection, Function super E, ? extends R> mapper) {
super(realCollection, mapper);
this.realCacheCollection = realCollection;
}
@Override
public CloseableSpliterator spliterator() {
return new CloseableSpliteratorMapper<>(realCacheCollection.spliterator(), mapper);
}
@Override
public CloseableIterator iterator() {
return new CloseableIteratorMapper<>(realCacheCollection.iterator(), mapper);
}
@Override
public CacheStream stream() {
return realCacheCollection.stream().map(mapper);
}
@Override
public CacheStream parallelStream() {
return realCacheCollection.parallelStream().map(mapper);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy