Search in sources :

Example 51 with Spliterator

use of java.util.Spliterator in project mapdb by jankotek.

the class LinkedBlockingQueue8Test method testSpliterator_characteristics.

/**
 * Spliterator characteristics are as advertised
 */
public void testSpliterator_characteristics() {
    LinkedBlockingQueue q = new LinkedBlockingQueue();
    Spliterator s = q.spliterator();
    int characteristics = s.characteristics();
    int required = Spliterator.CONCURRENT | Spliterator.NONNULL | Spliterator.ORDERED;
    assertEquals(required, characteristics & required);
    assertTrue(s.hasCharacteristics(required));
    assertEquals(0, characteristics & (Spliterator.DISTINCT | Spliterator.IMMUTABLE | Spliterator.SORTED));
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Spliterator(java.util.Spliterator)

Example 52 with Spliterator

use of java.util.Spliterator in project timbuctoo by HuygensING.

the class ChangeLog method getProvenanceChanges.

protected Stream<Change> getProvenanceChanges(DataSet dataSet, String[] subjects, CustomProvenance provenance, Map<String, JsonNode> values) {
    TypeNameStore typeNameStore = dataSet.getTypeNameStore();
    Stream<Change> customProv = provenance.getFields().stream().filter(field -> field.getValueType() != null).flatMap(field -> {
        String graphQlPred = typeNameStore.makeGraphQlnameForPredicate(field.getUri(), Direction.OUT, field.isList());
        return Stream.of(subjects).map(subject -> new Change(subject, field.getUri(), getValues(dataSet, values.get(graphQlPred)), Stream.empty()));
    });
    Stream<Change> customProvNested = provenance.getFields().stream().filter(field -> field.getObject() != null).flatMap(field -> {
        String graphQlPred = typeNameStore.makeGraphQlnameForPredicate(field.getUri(), Direction.OUT, field.isList());
        JsonNode objectValues = values.get(graphQlPred);
        if (objectValues.isArray()) {
            Spliterator<JsonNode> spliterator = Spliterators.spliteratorUnknownSize(objectValues.iterator(), Spliterator.ORDERED);
            return StreamSupport.stream(spliterator, false).flatMap(newObjectValues -> getChangesForProvObject(dataSet, newObjectValues, subjects, field));
        }
        return getChangesForProvObject(dataSet, objectValues, subjects, field);
    });
    return Stream.concat(customProv, customProvNested);
}
Also used : Change(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change) JsonSubTypes(com.fasterxml.jackson.annotation.JsonSubTypes) RdfConstants(nl.knaw.huygens.timbuctoo.v5.util.RdfConstants) Spliterators(java.util.Spliterators) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Collectors(java.util.stream.Collectors) List(java.util.List) Lists(com.google.common.collect.Lists) Stream(java.util.stream.Stream) JsonTypeInfo(com.fasterxml.jackson.annotation.JsonTypeInfo) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Spliterator(java.util.Spliterator) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore) JsonNode(com.fasterxml.jackson.databind.JsonNode) Change(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore)

Example 53 with Spliterator

use of java.util.Spliterator in project timbuctoo by HuygensING.

the class ChangeLog method getProvenanceChanges.

protected Stream<Change> getProvenanceChanges(DataSet dataSet, Graph graph, String[] subjects, CustomProvenance provenance, Map<String, JsonNode> values) {
    TypeNameStore typeNameStore = dataSet.getTypeNameStore();
    Stream<Change> customProv = provenance.getFields().stream().filter(field -> field.getValueType() != null).flatMap(field -> {
        String graphQlPred = typeNameStore.makeGraphQlnameForPredicate(field.getUri(), Direction.OUT, field.isList());
        return Stream.of(subjects).map(subject -> new Change(graph, subject, field.getUri(), getValues(dataSet, values.get(graphQlPred)), Stream.empty()));
    });
    Stream<Change> customProvNested = provenance.getFields().stream().filter(field -> field.getObject() != null).flatMap(field -> {
        String graphQlPred = typeNameStore.makeGraphQlnameForPredicate(field.getUri(), Direction.OUT, field.isList());
        JsonNode objectValues = values.get(graphQlPred);
        if (objectValues.isArray()) {
            Spliterator<JsonNode> spliterator = Spliterators.spliteratorUnknownSize(objectValues.iterator(), Spliterator.ORDERED);
            return StreamSupport.stream(spliterator, false).flatMap(newObjectValues -> getChangesForProvObject(dataSet, newObjectValues, graph, subjects, field));
        }
        return getChangesForProvObject(dataSet, objectValues, graph, subjects, field);
    });
    return Stream.concat(customProv, customProvNested);
}
Also used : Change(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change) JsonSubTypes(com.fasterxml.jackson.annotation.JsonSubTypes) Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) RdfConstants(nl.knaw.huygens.timbuctoo.v5.util.RdfConstants) Spliterators(java.util.Spliterators) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Collectors(java.util.stream.Collectors) List(java.util.List) Lists(com.google.common.collect.Lists) Stream(java.util.stream.Stream) JsonTypeInfo(com.fasterxml.jackson.annotation.JsonTypeInfo) Map(java.util.Map) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Spliterator(java.util.Spliterator) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore) JsonNode(com.fasterxml.jackson.databind.JsonNode) Change(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore)

Example 54 with Spliterator

use of java.util.Spliterator in project jnosql-diana by eclipse.

the class SettingsConverter method success.

@Override
public Settings success(String value) {
    Config config = BeanManagers.getInstance(Config.class);
    final Spliterator<String> spliterator = config.getPropertyNames().spliterator();
    final String settingsPrefix = getSettingsPrefix(value);
    final Map<String, Object> settings = stream(spliterator, false).filter(isSettings(settingsPrefix)).distinct().collect(toMap(s -> s.replace(value + ".settings.", ""), s -> config.getValue(s, String.class)));
    return Settings.of(settings);
}
Also used : Converter(org.eclipse.microprofile.config.spi.Converter) Collectors.toMap(java.util.stream.Collectors.toMap) StreamSupport.stream(java.util.stream.StreamSupport.stream) Predicate(java.util.function.Predicate) Map(java.util.Map) BeanManagers(org.eclipse.jnosql.mapping.util.BeanManagers) Settings(jakarta.nosql.Settings) Config(org.eclipse.microprofile.config.Config) Spliterator(java.util.Spliterator) StringUtils(org.eclipse.jnosql.mapping.util.StringUtils) Config(org.eclipse.microprofile.config.Config)

Example 55 with Spliterator

use of java.util.Spliterator in project nexus-public by sonatype.

the class DatastoreMetadataRebuilderTest method infiniteContinuation.

private Continuation infiniteContinuation(Object returnItem) {
    Continuation continuation = mock(Continuation.class);
    Iterator iterator = mock(Iterator.class);
    Spliterator spliterator = mock(Spliterator.class);
    when(continuation.spliterator()).thenReturn(spliterator);
    when(continuation.iterator()).thenReturn(iterator);
    when(iterator.hasNext()).thenReturn(true);
    when(iterator.next()).thenReturn(returnItem);
    return continuation;
}
Also used : Continuation(org.sonatype.nexus.common.entity.Continuation) Iterator(java.util.Iterator) 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