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);
}
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));
}
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;
}
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;
}
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();
}
Aggregations