本文整理匯總了Java中java.util.Spliterator.ORDERED屬性的典型用法代碼示例。如果您正苦於以下問題:Java Spliterator.ORDERED屬性的具體用法?Java Spliterator.ORDERED怎麽用?Java Spliterator.ORDERED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.util.Spliterator
的用法示例。
在下文中一共展示了Spliterator.ORDERED屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: iterate
/**
* Returns an infinite sequential ordered {@code IntStream} produced by iterative
* application of a function {@code f} to an initial element {@code seed},
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
* {@code f(f(seed))}, etc.
*
* <p>The first element (position {@code 0}) in the {@code IntStream} will be
* the provided {@code seed}. For {@code n > 0}, the element at position
* {@code n}, will be the result of applying the function {@code f} to the
* element at position {@code n - 1}.
*
* <p>The action of applying {@code f} for one element
* <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
* the action of applying {@code f} for subsequent elements. For any given
* element the action may be performed in whatever thread the library
* chooses.
*
* @param seed the initial element
* @param f a function to be applied to the previous element to produce
* a new element
* @return a new sequential {@code IntStream}
*/
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
Objects.requireNonNull(f);
Spliterator.OfInt spliterator = new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
int prev;
boolean started;
@Override
public boolean tryAdvance(IntConsumer action) {
Objects.requireNonNull(action);
int t;
if (started)
t = f.applyAsInt(prev);
else {
t = seed;
started = true;
}
action.accept(prev = t);
return true;
}
};
return StreamSupport.intStream(spliterator, false);
}
示例2: distinct
public static <T> Stream<T> distinct(Stream<T> src, Comparator<T> cmp) {
Spliterator<T> iter = src.spliterator();
Spliterator<T> res = new AbstractSpliterator<T>(Long.MAX_VALUE, Spliterator.ORDERED ) {
// ArrayList<T> distinctData = new ArrayList<>();
TreeSet<T> distinctData = new TreeSet<>(cmp);
@Override
public boolean tryAdvance(Consumer<? super T> action) {
return iter.tryAdvance( item -> {
// Versão 1: if (!contains(distinctData, cmp, item)) {
// Versão 2: if(!distinctData.stream().anyMatch(e -> cmp.compare(e, item) == 0)) {
// Versão 3:
if (!distinctData.contains(item)) {
distinctData.add(item);
action.accept(item);
}
});
}
};
return StreamSupport.stream(res, false);
}
示例3: ofNode
public static OfDouble ofNode(String name, Node.OfDouble node) {
int characteristics = Spliterator.SIZED | Spliterator.ORDERED;
return new AbstractTestData.DoubleTestData<>(name, node,
n -> StreamSupport.doubleStream(n::spliterator, characteristics, false),
n -> StreamSupport.doubleStream(n::spliterator, characteristics, true),
Node.OfDouble::spliterator,
n -> (int) n.count());
}
示例4: testSpliterator_characteristics
/**
* Spliterator characteristics are as advertised
*/
public void testSpliterator_characteristics() {
LinkedBlockingDeque q = new LinkedBlockingDeque();
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));
}
示例5: zip
/**
* Returns a stream in which each element is the result of passing the corresponding element of
* each of {@code streamA} and {@code streamB} to {@code function}.
*
* <p>For example:
*
* <pre>{@code
* Streams.zip(
* Stream.of("foo1", "foo2", "foo3"),
* Stream.of("bar1", "bar2"),
* (arg1, arg2) -> arg1 + ":" + arg2)
* }</pre>
*
* <p>will return {@code Stream.of("foo1:bar1", "foo2:bar2")}.
*
* <p>The resulting stream will only be as long as the shorter of the two input streams; if one
* stream is longer, its extra elements will be ignored.
*
* <p>The resulting stream is not <a
* href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a>.
* This may harm parallel performance.
*/
public static <A, B, R> Stream<R> zip(
Stream<A> streamA, Stream<B> streamB, BiFunction<? super A, ? super B, R> function) {
checkNotNull(streamA);
checkNotNull(streamB);
checkNotNull(function);
boolean isParallel = streamA.isParallel() || streamB.isParallel(); // same as Stream.concat
Spliterator<A> splitrA = streamA.spliterator();
Spliterator<B> splitrB = streamB.spliterator();
int characteristics =
splitrA.characteristics()
& splitrB.characteristics()
& (Spliterator.SIZED | Spliterator.ORDERED);
Iterator<A> itrA = Spliterators.iterator(splitrA);
Iterator<B> itrB = Spliterators.iterator(splitrB);
return StreamSupport.stream(
new AbstractSpliterator<R>(
Math.min(splitrA.estimateSize(), splitrB.estimateSize()), characteristics) {
@Override
public boolean tryAdvance(Consumer<? super R> action) {
if (itrA.hasNext() && itrB.hasNext()) {
action.accept(function.apply(itrA.next(), itrB.next()));
return true;
}
return false;
}
},
isParallel);
}
示例6: characteristics
public int characteristics() {
return Spliterator.DISTINCT | Spliterator.ORDERED |
Spliterator.SORTED;
}
示例7: characteristics
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED |
Spliterator.IMMUTABLE | Spliterator.NONNULL |
Spliterator.DISTINCT | Spliterator.SORTED;
}
示例8: CodePointsSpliterator
CodePointsSpliterator(byte[] array, int origin, int fence, int acs) {
this.array = array;
this.index = origin;
this.fence = fence;
this.cs = acs | Spliterator.ORDERED;
}
示例9: characteristics
public final int characteristics() {
return s.characteristics() &
~(Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.ORDERED);
}
示例10: characteristics
public int characteristics() {
return (side == 0 ? Spliterator.SIZED : 0) |
Spliterator.DISTINCT | Spliterator.ORDERED;
}
示例11: characteristics
public int characteristics() {
return Spliterator.ORDERED | Spliterator.NONNULL |
Spliterator.CONCURRENT;
}
示例12: characteristics
@Override
public int characteristics() {
return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;
}
示例13: characteristics
@Override
public int characteristics() {
return Spliterator.SIZED | Spliterator.SUBSIZED |
Spliterator.ORDERED | Spliterator.IMMUTABLE;
}
示例14: characteristics
@Override
public int characteristics() {
return (s.characteristics() & ~(Spliterator.SIZED | Spliterator.SUBSIZED |
Spliterator.SORTED | Spliterator.ORDERED))
| Spliterator.DISTINCT;
}