Search in sources :

Example 91 with Spliterator

use of java.util.Spliterator in project openj9 by eclipse-openj9.

the class StringStreams method testStringCharsSpliteratorEmpty.

@Test
public void testStringCharsSpliteratorEmpty() {
    Spliterator.OfInt s = EMPTY.chars().spliterator();
    final ArrayList<Integer> actualIntegers = new ArrayList<>();
    s.forEachRemaining((IntConsumer) i -> actualIntegers.add(Integer.valueOf(i)));
    checkDigitsOrdered(EMPTY, actualIntegers);
}
Also used : HashSet(java.util.HashSet) Objects(java.util.Objects) List(java.util.List) OfInt(java.util.Spliterator.OfInt) IntConsumer(java.util.function.IntConsumer) Assert.assertEquals(org.testng.Assert.assertEquals) Assert.assertTrue(org.testng.Assert.assertTrue) Set(java.util.Set) VersionCheck(org.openj9.test.util.VersionCheck) Test(org.testng.annotations.Test) Spliterator(java.util.Spliterator) ArrayList(java.util.ArrayList) OfInt(java.util.Spliterator.OfInt) ArrayList(java.util.ArrayList) Spliterator(java.util.Spliterator) Test(org.testng.annotations.Test)

Example 92 with Spliterator

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

the class LongPipeline method forEachWithCancel.

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

Example 93 with Spliterator

use of java.util.Spliterator in project so by onap.

the class JsonUtilForPnfCorrelationId method parseJsonToGelAllPnfCorrelationId.

static List<String> parseJsonToGelAllPnfCorrelationId(String json) {
    if (json == null || json.isEmpty()) {
        return Collections.emptyList();
    }
    JsonElement je = new JsonParser().parse(json);
    JsonArray array = je.getAsJsonArray();
    List<String> list = new ArrayList<>();
    Spliterator<JsonElement> spliterator = array.spliterator();
    spliterator.forEachRemaining(jsonElement -> handleEscapedCharacters(jsonElement).ifPresent(jsonObject -> getPnfCorrelationId(jsonObject).ifPresent(pnfCorrelationId -> list.add(pnfCorrelationId))));
    return list;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) List(java.util.List) Optional(java.util.Optional) JsonParser(com.google.gson.JsonParser) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonParser(com.google.gson.JsonParser)

Example 94 with Spliterator

use of java.util.Spliterator in project jenkins by jenkinsci.

the class AbstractLazyLoadRunMap method keySet.

@Override
public Set<Integer> keySet() {
    Set<Integer> ks = keySet;
    if (ks == null) {
        ks = new AbstractSet<Integer>() {

            @Override
            public Iterator<Integer> iterator() {
                return new Iterator() {

                    private final Iterator<Entry<Integer, R>> it = entrySet().iterator();

                    @Override
                    public boolean hasNext() {
                        return it.hasNext();
                    }

                    @Override
                    public Integer next() {
                        return it.next().getKey();
                    }

                    @Override
                    public void remove() {
                        it.remove();
                    }
                };
            }

            @Override
            public Spliterator<Integer> spliterator() {
                return new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE, Spliterator.DISTINCT | Spliterator.ORDERED | Spliterator.SORTED) {

                    private final Iterator<Integer> it = iterator();

                    @Override
                    public boolean tryAdvance(IntConsumer action) {
                        if (action == null) {
                            throw new NullPointerException();
                        }
                        if (it.hasNext()) {
                            action.accept(it.next());
                            return true;
                        }
                        return false;
                    }

                    @Override
                    public Comparator<Integer> getComparator() {
                        return Collections.reverseOrder();
                    }
                };
            }

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

            @Override
            public boolean isEmpty() {
                return AbstractLazyLoadRunMap.this.isEmpty();
            }

            @Override
            public void clear() {
                AbstractLazyLoadRunMap.this.clear();
            }

            @Override
            public boolean contains(Object k) {
                return AbstractLazyLoadRunMap.this.containsKey(k);
            }
        };
        keySet = ks;
    }
    return ks;
}
Also used : IntConsumer(java.util.function.IntConsumer) Comparator(java.util.Comparator) Spliterators(java.util.Spliterators) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) Spliterator(java.util.Spliterator)

Example 95 with Spliterator

use of java.util.Spliterator in project guava by google.

the class CollectSpliterators method filter.

/**
 * Returns a {@code Spliterator} filtered by the specified predicate.
 */
static <T extends @Nullable Object> Spliterator<T> filter(Spliterator<T> fromSpliterator, Predicate<? super T> predicate) {
    checkNotNull(fromSpliterator);
    checkNotNull(predicate);
    class Splitr implements Spliterator<T>, Consumer<T> {

        @CheckForNull
        T holder = null;

        @Override
        public void accept(@ParametricNullness T t) {
            this.holder = t;
        }

        @Override
        public boolean tryAdvance(Consumer<? super T> action) {
            while (fromSpliterator.tryAdvance(this)) {
                try {
                    // The cast is safe because tryAdvance puts a T into `holder`.
                    T next = uncheckedCastNullableTToT(holder);
                    if (predicate.test(next)) {
                        action.accept(next);
                        return true;
                    }
                } finally {
                    holder = null;
                }
            }
            return false;
        }

        @Override
        @CheckForNull
        public Spliterator<T> trySplit() {
            Spliterator<T> fromSplit = fromSpliterator.trySplit();
            return (fromSplit == null) ? null : filter(fromSplit, predicate);
        }

        @Override
        public long estimateSize() {
            return fromSpliterator.estimateSize() / 2;
        }

        @Override
        @CheckForNull
        public Comparator<? super T> getComparator() {
            return fromSpliterator.getComparator();
        }

        @Override
        public int characteristics() {
            return fromSpliterator.characteristics() & (Spliterator.DISTINCT | Spliterator.NONNULL | Spliterator.ORDERED | Spliterator.SORTED);
        }
    }
    return new Splitr();
}
Also used : NullnessCasts.uncheckedCastNullableTToT(com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT) IntConsumer(java.util.function.IntConsumer) DoubleConsumer(java.util.function.DoubleConsumer) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) 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