Search in sources :

Example 61 with Spliterator

use of java.util.Spliterator in project force-oneself by Force-oneself.

the class IntPipeline method forEachWithCancel.

@Override
final void forEachWithCancel(Spliterator<Integer> spliterator, Sink<Integer> sink) {
    Spliterator.OfInt spl = adapt(spliterator);
    IntConsumer adaptedSink = adapt(sink);
    do {
    } while (!sink.cancellationRequested() && spl.tryAdvance(adaptedSink));
}
Also used : Spliterator(java.util.Spliterator) IntConsumer(java.util.function.IntConsumer) ObjIntConsumer(java.util.function.ObjIntConsumer)

Example 62 with Spliterator

use of java.util.Spliterator in project atlas by apache.

the class ElasticSearch7Index method getFilter.

public Map<String, Object> getFilter(Condition<?> condition, KeyInformation.StoreRetriever information) {
    if (condition instanceof PredicateCondition) {
        final PredicateCondition<String, ?> atom = (PredicateCondition) condition;
        Object value = atom.getValue();
        final String key = atom.getKey();
        final JanusGraphPredicate predicate = atom.getPredicate();
        if (value == null && predicate == Cmp.NOT_EQUAL) {
            return compat.exists(key);
        } else if (value instanceof Number) {
            Preconditions.checkArgument(predicate instanceof Cmp, "Relation not supported on numeric types: %s", predicate);
            return getRelationFromCmp((Cmp) predicate, key, value);
        } else if (value instanceof String) {
            final Mapping mapping = getStringMapping(information.get(key));
            final String fieldName;
            if (mapping == Mapping.TEXT && !(Text.HAS_CONTAINS.contains(predicate) || predicate instanceof Cmp))
                throw new IllegalArgumentException("Text mapped string values only support CONTAINS and Compare queries and not: " + predicate);
            if (mapping == Mapping.STRING && Text.HAS_CONTAINS.contains(predicate))
                throw new IllegalArgumentException("String mapped string values do not support CONTAINS queries: " + predicate);
            if (mapping == Mapping.TEXTSTRING && !(Text.HAS_CONTAINS.contains(predicate) || (predicate instanceof Cmp && predicate != Cmp.EQUAL))) {
                fieldName = getDualMappingName(key);
            } else {
                fieldName = key;
            }
            if (predicate == Text.CONTAINS || predicate == Cmp.EQUAL) {
                return compat.match(fieldName, value);
            } else if (predicate == Text.NOT_CONTAINS) {
                return compat.boolMust(ImmutableList.of(compat.exists(fieldName), compat.boolMustNot(compat.match(fieldName, value))));
            } else if (predicate == Text.CONTAINS_PHRASE) {
                return compat.matchPhrase(fieldName, value);
            } else if (predicate == Text.NOT_CONTAINS_PHRASE) {
                return compat.boolMust(ImmutableList.of(compat.exists(fieldName), compat.boolMustNot(compat.matchPhrase(fieldName, value))));
            } else if (predicate == Text.CONTAINS_PREFIX) {
                if (!ParameterType.TEXT_ANALYZER.hasParameter(information.get(key).getParameters()))
                    value = ((String) value).toLowerCase();
                return compat.prefix(fieldName, value);
            } else if (predicate == Text.NOT_CONTAINS_PREFIX) {
                if (!ParameterType.TEXT_ANALYZER.hasParameter(information.get(key).getParameters()))
                    value = ((String) value).toLowerCase();
                return compat.boolMust(ImmutableList.of(compat.exists(fieldName), compat.boolMustNot(compat.prefix(fieldName, value))));
            } else if (predicate == Text.CONTAINS_REGEX) {
                if (!ParameterType.TEXT_ANALYZER.hasParameter(information.get(key).getParameters()))
                    value = ((String) value).toLowerCase();
                return compat.regexp(fieldName, value);
            } else if (predicate == Text.NOT_CONTAINS_REGEX) {
                if (!ParameterType.TEXT_ANALYZER.hasParameter(information.get(key).getParameters()))
                    value = ((String) value).toLowerCase();
                return compat.boolMust(ImmutableList.of(compat.exists(fieldName), compat.boolMustNot(compat.regexp(fieldName, value))));
            } else if (predicate == Text.PREFIX) {
                return compat.prefix(fieldName, value);
            } else if (predicate == Text.NOT_PREFIX) {
                return compat.boolMust(ImmutableList.of(compat.exists(fieldName), compat.boolMustNot(compat.prefix(fieldName, value))));
            } else if (predicate == Text.REGEX) {
                return compat.regexp(fieldName, value);
            } else if (predicate == Text.NOT_REGEX) {
                return compat.boolMust(ImmutableList.of(compat.exists(fieldName), compat.boolMustNot(compat.regexp(fieldName, value))));
            } else if (predicate == Cmp.NOT_EQUAL) {
                return compat.boolMustNot(compat.match(fieldName, value));
            } else if (predicate == Text.FUZZY || predicate == Text.CONTAINS_FUZZY) {
                return compat.fuzzyMatch(fieldName, value);
            } else if (predicate == Text.NOT_FUZZY || predicate == Text.NOT_CONTAINS_FUZZY) {
                return compat.boolMust(ImmutableList.of(compat.exists(fieldName), compat.boolMustNot(compat.fuzzyMatch(fieldName, value))));
            } else if (predicate == Cmp.LESS_THAN) {
                return compat.lt(fieldName, value);
            } else if (predicate == Cmp.LESS_THAN_EQUAL) {
                return compat.lte(fieldName, value);
            } else if (predicate == Cmp.GREATER_THAN) {
                return compat.gt(fieldName, value);
            } else if (predicate == Cmp.GREATER_THAN_EQUAL) {
                return compat.gte(fieldName, value);
            } else
                throw new IllegalArgumentException("Predicate is not supported for string value: " + predicate);
        } else if (value instanceof Geoshape && Mapping.getMapping(information.get(key)) == Mapping.DEFAULT) {
            // geopoint
            final Geoshape shape = (Geoshape) value;
            Preconditions.checkArgument(predicate instanceof Geo && predicate != Geo.CONTAINS, "Relation not supported on geopoint types: %s", predicate);
            final Map<String, Object> query;
            switch(shape.getType()) {
                case CIRCLE:
                    final Geoshape.Point center = shape.getPoint();
                    query = compat.geoDistance(key, center.getLatitude(), center.getLongitude(), shape.getRadius());
                    break;
                case BOX:
                    final Geoshape.Point southwest = shape.getPoint(0);
                    final Geoshape.Point northeast = shape.getPoint(1);
                    query = compat.geoBoundingBox(key, southwest.getLatitude(), southwest.getLongitude(), northeast.getLatitude(), northeast.getLongitude());
                    break;
                case POLYGON:
                    final List<List<Double>> points = IntStream.range(0, shape.size()).mapToObj(i -> ImmutableList.of(shape.getPoint(i).getLongitude(), shape.getPoint(i).getLatitude())).collect(Collectors.toList());
                    query = compat.geoPolygon(key, points);
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported or invalid search shape type for geopoint: " + shape.getType());
            }
            return predicate == Geo.DISJOINT ? compat.boolMustNot(query) : query;
        } else if (value instanceof Geoshape) {
            Preconditions.checkArgument(predicate instanceof Geo, "Relation not supported on geoshape types: %s", predicate);
            final Geoshape shape = (Geoshape) value;
            final Map<String, Object> geo;
            switch(shape.getType()) {
                case CIRCLE:
                    final Geoshape.Point center = shape.getPoint();
                    geo = ImmutableMap.of(ES_TYPE_KEY, "circle", ES_GEO_COORDS_KEY, ImmutableList.of(center.getLongitude(), center.getLatitude()), "radius", shape.getRadius() + "km");
                    break;
                case BOX:
                    final Geoshape.Point southwest = shape.getPoint(0);
                    final Geoshape.Point northeast = shape.getPoint(1);
                    geo = ImmutableMap.of(ES_TYPE_KEY, "envelope", ES_GEO_COORDS_KEY, ImmutableList.of(ImmutableList.of(southwest.getLongitude(), northeast.getLatitude()), ImmutableList.of(northeast.getLongitude(), southwest.getLatitude())));
                    break;
                case LINE:
                    final List lineCoords = IntStream.range(0, shape.size()).mapToObj(i -> ImmutableList.of(shape.getPoint(i).getLongitude(), shape.getPoint(i).getLatitude())).collect(Collectors.toList());
                    geo = ImmutableMap.of(ES_TYPE_KEY, "linestring", ES_GEO_COORDS_KEY, lineCoords);
                    break;
                case POLYGON:
                    final List polyCoords = IntStream.range(0, shape.size()).mapToObj(i -> ImmutableList.of(shape.getPoint(i).getLongitude(), shape.getPoint(i).getLatitude())).collect(Collectors.toList());
                    geo = ImmutableMap.of(ES_TYPE_KEY, "polygon", ES_GEO_COORDS_KEY, ImmutableList.of(polyCoords));
                    break;
                case POINT:
                    geo = ImmutableMap.of(ES_TYPE_KEY, "point", ES_GEO_COORDS_KEY, ImmutableList.of(shape.getPoint().getLongitude(), shape.getPoint().getLatitude()));
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported or invalid search shape type: " + shape.getType());
            }
            return compat.geoShape(key, geo, (Geo) predicate);
        } else if (value instanceof Date || value instanceof Instant) {
            Preconditions.checkArgument(predicate instanceof Cmp, "Relation not supported on date types: %s", predicate);
            if (value instanceof Instant) {
                value = Date.from((Instant) value);
            }
            return getRelationFromCmp((Cmp) predicate, key, value);
        } else if (value instanceof Boolean) {
            final Cmp numRel = (Cmp) predicate;
            switch(numRel) {
                case EQUAL:
                    return compat.term(key, value);
                case NOT_EQUAL:
                    return compat.boolMustNot(compat.term(key, value));
                default:
                    throw new IllegalArgumentException("Boolean types only support EQUAL or NOT_EQUAL");
            }
        } else if (value instanceof UUID) {
            if (predicate == Cmp.EQUAL) {
                return compat.term(key, value);
            } else if (predicate == Cmp.NOT_EQUAL) {
                return compat.boolMustNot(compat.term(key, value));
            } else {
                throw new IllegalArgumentException("Only equal or not equal is supported for UUIDs: " + predicate);
            }
        } else
            throw new IllegalArgumentException("Unsupported type: " + value);
    } else if (condition instanceof Not) {
        return compat.boolMustNot(getFilter(((Not) condition).getChild(), information));
    } else if (condition instanceof And) {
        final List queries = StreamSupport.stream(condition.getChildren().spliterator(), false).map(c -> getFilter(c, information)).collect(Collectors.toList());
        return compat.boolMust(queries);
    } else if (condition instanceof Or) {
        final List queries = StreamSupport.stream(condition.getChildren().spliterator(), false).map(c -> getFilter(c, information)).collect(Collectors.toList());
        return compat.boolShould(queries);
    } else
        throw new IllegalArgumentException("Invalid condition: " + condition);
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) INDEX_MAX_RESULT_SET_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE) Arrays(java.util.Arrays) Date(java.util.Date) Spliterators(java.util.Spliterators) ES_LANG_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_LANG_KEY) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) Geoshape(org.janusgraph.core.attribute.Geoshape) AbstractESCompat(org.janusgraph.diskstorage.es.compat.AbstractESCompat) ESCompatUtils(org.janusgraph.diskstorage.es.compat.ESCompatUtils) BaseTransaction(org.janusgraph.diskstorage.BaseTransaction) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) Cardinality(org.janusgraph.core.Cardinality) IndexEntry(org.janusgraph.diskstorage.indexing.IndexEntry) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation) Map(java.util.Map) IndexQuery(org.janusgraph.diskstorage.indexing.IndexQuery) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) And(org.janusgraph.graphdb.query.condition.And) Mapping(org.janusgraph.core.schema.Mapping) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ES_GEO_COORDS_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_GEO_COORDS_KEY) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Sets(com.google.common.collect.Sets) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) List(java.util.List) ES_SCRIPT_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_SCRIPT_KEY) Parameter(org.janusgraph.core.schema.Parameter) Stream(java.util.stream.Stream) INDEX_NAME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_NAME) Spliterator(java.util.Spliterator) PreInitializeConfigOptions(org.janusgraph.graphdb.configuration.PreInitializeConfigOptions) Not(org.janusgraph.graphdb.query.condition.Not) IntStream(java.util.stream.IntStream) Condition(org.janusgraph.graphdb.query.condition.Condition) AttributeUtils(org.janusgraph.graphdb.database.serialize.AttributeUtils) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) Rectangle(org.locationtech.spatial4j.shape.Rectangle) ImmutableList(com.google.common.collect.ImmutableList) Cmp(org.janusgraph.core.attribute.Cmp) IndexFeatures(org.janusgraph.diskstorage.indexing.IndexFeatures) Or(org.janusgraph.graphdb.query.condition.Or) JanusGraphException(org.janusgraph.core.JanusGraphException) StreamSupport(java.util.stream.StreamSupport) Geo(org.janusgraph.core.attribute.Geo) BackendException(org.janusgraph.diskstorage.BackendException) JanusGraphPredicate(org.janusgraph.graphdb.query.JanusGraphPredicate) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Configuration(org.janusgraph.diskstorage.configuration.Configuration) BaseTransactionConfigurable(org.janusgraph.diskstorage.BaseTransactionConfigurable) RawQuery(org.janusgraph.diskstorage.indexing.RawQuery) ES_TYPE_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_TYPE_KEY) IOException(java.io.IOException) DefaultTransaction(org.janusgraph.diskstorage.util.DefaultTransaction) ES_DOC_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_DOC_KEY) Text(org.janusgraph.core.attribute.Text) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) ESScriptResponse(org.janusgraph.diskstorage.es.script.ESScriptResponse) Preconditions(com.google.common.base.Preconditions) IndexMapping(org.janusgraph.diskstorage.es.mapping.IndexMapping) ParameterType(org.janusgraph.graphdb.types.ParameterType) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) IndexMutation(org.janusgraph.diskstorage.indexing.IndexMutation) Or(org.janusgraph.graphdb.query.condition.Or) Mapping(org.janusgraph.core.schema.Mapping) IndexMapping(org.janusgraph.diskstorage.es.mapping.IndexMapping) JanusGraphPredicate(org.janusgraph.graphdb.query.JanusGraphPredicate) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) UUID(java.util.UUID) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) Cmp(org.janusgraph.core.attribute.Cmp) Instant(java.time.Instant) Geoshape(org.janusgraph.core.attribute.Geoshape) Date(java.util.Date) Geo(org.janusgraph.core.attribute.Geo) Not(org.janusgraph.graphdb.query.condition.Not) And(org.janusgraph.graphdb.query.condition.And) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 63 with Spliterator

use of java.util.Spliterator in project hibernate-orm by hibernate.

the class AbstractSelectionQuery method stream.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Stream stream() {
    final ScrollableResultsImplementor scrollableResults = scroll(ScrollMode.FORWARD_ONLY);
    final ScrollableResultsIterator iterator = new ScrollableResultsIterator<>(scrollableResults);
    final Spliterator spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.NONNULL);
    final Stream stream = StreamSupport.stream(spliterator, false);
    return (Stream) stream.onClose(scrollableResults::close);
}
Also used : ScrollableResultsIterator(org.hibernate.query.internal.ScrollableResultsIterator) Stream(java.util.stream.Stream) Spliterator(java.util.Spliterator)

Example 64 with Spliterator

use of java.util.Spliterator in project Valkyrien-Skies-2 by ValkyrienSkies.

the class MixinServerWorld method postTick.

@Inject(method = "tick", at = @At("TAIL"))
private void postTick(final BooleanSupplier shouldKeepTicking, final CallbackInfo ci) {
    // First update the IPlayer wrapper list
    updateVSPlayerWrappers();
    // Find newly loaded chunks
    final List<ChunkHolder> loadedChunksList = Lists.newArrayList(((ThreadedAnvilChunkStorageAccessor) serverChunkManager.threadedAnvilChunkStorage).callEntryIterator());
    // Create DenseVoxelShapeUpdate for new loaded chunks
    final List<IVoxelShapeUpdate> newLoadedChunks = new ArrayList<>();
    for (final ChunkHolder chunkHolder : loadedChunksList) {
        final Optional<WorldChunk> worldChunkOptional = chunkHolder.getTickingFuture().getNow(ChunkHolder.UNLOADED_WORLD_CHUNK).left();
        if (worldChunkOptional.isPresent()) {
            final WorldChunk worldChunk = worldChunkOptional.get();
            final int chunkX = worldChunk.getPos().x;
            final int chunkZ = worldChunk.getPos().z;
            final ChunkSection[] chunkSections = worldChunk.getSectionArray();
            // For now just assume chunkY goes from 0 to 16
            for (int chunkY = 0; chunkY < 16; chunkY++) {
                final ChunkSection chunkSection = chunkSections[chunkY];
                final Vector3ic chunkPos = new Vector3i(chunkX, chunkY, chunkZ);
                if (!knownChunkRegions.contains(chunkPos)) {
                    if (chunkSection != null) {
                        // Add this chunk to the ground rigid body
                        final DenseVoxelShapeUpdate voxelShapeUpdate = VSGameUtilsKt.toDenseVoxelUpdate(chunkSection, chunkPos);
                        newLoadedChunks.add(voxelShapeUpdate);
                    } else {
                        final EmptyVoxelShapeUpdate emptyVoxelShapeUpdate = new EmptyVoxelShapeUpdate(chunkPos.x(), chunkPos.y(), chunkPos.z(), false, false);
                        newLoadedChunks.add(emptyVoxelShapeUpdate);
                    }
                    knownChunkRegions.add(chunkPos);
                }
            }
        }
    }
    // Then tick the ship world
    shipObjectWorld.tickShips(newLoadedChunks);
    // Send ships to clients
    final IVSPacket shipDataPacket = VSPacketShipDataList.Companion.create(shipObjectWorld.getQueryableShipData().iterator());
    for (final ServerPlayerEntity playerEntity : players) {
        VSNetworking.shipDataPacketToClientSender.sendToClient(shipDataPacket, playerEntity);
    }
    // Then determine the chunk watch/unwatch tasks, and then execute them
    final ImmutableList<IPlayer> playersToTick = ImmutableList.copyOf(vsPlayerWrappers.values());
    final Pair<Spliterator<ChunkWatchTask>, Spliterator<ChunkUnwatchTask>> chunkWatchAndUnwatchTasksPair = shipObjectWorld.tickShipChunkLoading(playersToTick);
    // Use Spliterator instead of iterators so that we can multi thread the execution of these tasks
    final Spliterator<ChunkWatchTask> chunkWatchTasks = chunkWatchAndUnwatchTasksPair.getFirst();
    final Spliterator<ChunkUnwatchTask> chunkUnwatchTasks = chunkWatchAndUnwatchTasksPair.getSecond();
    // But for now just do it single threaded
    chunkWatchTasks.forEachRemaining(chunkWatchTask -> {
        System.out.println("Watch task for " + chunkWatchTask.getChunkX() + " : " + chunkWatchTask.getChunkZ());
        final Packet<?>[] chunkPacketBuffer = new Packet[2];
        final ChunkPos chunkPos = new ChunkPos(chunkWatchTask.getChunkX(), chunkWatchTask.getChunkZ());
        // TODO: Move this somewhere else
        serverChunkManager.setChunkForced(chunkPos, true);
        for (final IPlayer player : chunkWatchTask.getPlayersNeedWatching()) {
            final MinecraftPlayer minecraftPlayer = (MinecraftPlayer) player;
            final ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) minecraftPlayer.getPlayerEntityReference().get();
            if (serverPlayerEntity != null) {
                ((ThreadedAnvilChunkStorageAccessor) serverChunkManager.threadedAnvilChunkStorage).callSendWatchPackets(serverPlayerEntity, chunkPos, chunkPacketBuffer, false, true);
            }
        }
        chunkWatchTask.onExecuteChunkWatchTask();
    });
    chunkUnwatchTasks.forEachRemaining(chunkUnwatchTask -> {
        System.out.println("Unwatch task for " + chunkUnwatchTask.getChunkX() + " : " + chunkUnwatchTask.getChunkZ());
        chunkUnwatchTask.onExecuteChunkUnwatchTask();
    });
}
Also used : IPlayer(org.valkyrienskies.core.game.IPlayer) ChunkWatchTask(org.valkyrienskies.core.chunk_tracking.ChunkWatchTask) ChunkHolder(net.minecraft.server.world.ChunkHolder) EmptyVoxelShapeUpdate(org.valkyrienskies.physics_api.voxel_updates.EmptyVoxelShapeUpdate) ArrayList(java.util.ArrayList) ChunkUnwatchTask(org.valkyrienskies.core.chunk_tracking.ChunkUnwatchTask) WorldChunk(net.minecraft.world.chunk.WorldChunk) Vector3ic(org.joml.Vector3ic) MinecraftPlayer(org.valkyrienskies.mod.common.util.MinecraftPlayer) IVoxelShapeUpdate(org.valkyrienskies.physics_api.voxel_updates.IVoxelShapeUpdate) ChunkPos(net.minecraft.util.math.ChunkPos) ThreadedAnvilChunkStorageAccessor(org.valkyrienskies.mod.mixin.accessors.server.world.ThreadedAnvilChunkStorageAccessor) Spliterator(java.util.Spliterator) DenseVoxelShapeUpdate(org.valkyrienskies.physics_api.voxel_updates.DenseVoxelShapeUpdate) Packet(net.minecraft.network.Packet) IVSPacket(org.valkyrienskies.core.networking.IVSPacket) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Vector3i(org.joml.Vector3i) IVSPacket(org.valkyrienskies.core.networking.IVSPacket) ChunkSection(net.minecraft.world.chunk.ChunkSection) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 65 with Spliterator

use of java.util.Spliterator in project archiva by apache.

the class CassandraMetadataRepository method createResultSpliterator.

private <T> Spliterator<T> createResultSpliterator(ResultSet result, BiFunction<Row, T, T> converter) throws MetadataRepositoryException {
    final Iterator<Row> it = result.iterator();
    return new Spliterator<T>() {

        private T lastItem = null;

        @Override
        public boolean tryAdvance(Consumer<? super T> action) {
            if (it.hasNext()) {
                while (it.hasNext()) {
                    Row row = it.next();
                    T item = converter.apply(row, lastItem);
                    if (item != null && lastItem != null && item != lastItem) {
                        action.accept(lastItem);
                        lastItem = item;
                        return true;
                    }
                    lastItem = item;
                }
                action.accept(lastItem);
                return true;
            } else {
                return false;
            }
        }

        @Override
        public Spliterator<T> trySplit() {
            return null;
        }

        @Override
        public long estimateSize() {
            return Long.MAX_VALUE;
        }

        @Override
        public int characteristics() {
            return ORDERED + NONNULL;
        }
    };
}
Also used : Consumer(java.util.function.Consumer) Row(com.datastax.oss.driver.api.core.cql.Row) Spliterator(java.util.Spliterator)

Aggregations

Spliterator (java.util.Spliterator)124 List (java.util.List)47 ArrayList (java.util.ArrayList)41 HashSet (java.util.HashSet)36 IntConsumer (java.util.function.IntConsumer)35 Set (java.util.Set)31 Objects (java.util.Objects)25 Collectors (java.util.stream.Collectors)25 Spliterators (java.util.Spliterators)24 Function (java.util.function.Function)24 Iterator (java.util.Iterator)23 Consumer (java.util.function.Consumer)23 Stream (java.util.stream.Stream)23 Map (java.util.Map)22 Arrays (java.util.Arrays)20 LongConsumer (java.util.function.LongConsumer)20 Collections (java.util.Collections)19 StreamSupport (java.util.stream.StreamSupport)19 Comparator (java.util.Comparator)18 Test (org.junit.Test)18