當前位置: 首頁>>代碼示例>>Java>>正文


Java Spliterator.ORDERED屬性代碼示例

本文整理匯總了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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:45,代碼來源:IntStream.java

示例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);
}
 
開發者ID:isel-leic-mpd,項目名稱:mpd-2017-i41d,代碼行數:20,代碼來源:StreamUtils.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TestData.java

示例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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:LinkedBlockingDeque8Test.java

示例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);
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:50,代碼來源:Streams.java

示例6: characteristics

public int characteristics() {
    return Spliterator.DISTINCT | Spliterator.ORDERED |
        Spliterator.SORTED;
}
 
開發者ID:dmcmanam,項目名稱:bbst-showdown,代碼行數:4,代碼來源:TreeMapBST.java

示例7: characteristics

@Override
public int characteristics() {
    return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED |
           Spliterator.IMMUTABLE | Spliterator.NONNULL |
           Spliterator.DISTINCT | Spliterator.SORTED;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:Streams.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:StringUTF16.java

示例9: characteristics

public final int characteristics() {
    return s.characteristics() &
           ~(Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.ORDERED);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:4,代碼來源:StreamSpliterators.java

示例10: characteristics

public int characteristics() {
    return (side == 0 ? Spliterator.SIZED : 0) |
        Spliterator.DISTINCT | Spliterator.ORDERED;
}
 
開發者ID:dmcmanam,項目名稱:bbst-showdown,代碼行數:4,代碼來源:TreeMapRedBlack.java

示例11: characteristics

public int characteristics() {
    return Spliterator.ORDERED | Spliterator.NONNULL |
        Spliterator.CONCURRENT;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:4,代碼來源:LinkedTransferQueue.java

示例12: characteristics

@Override
public int characteristics() {
  return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;
}
 
開發者ID:XDean,項目名稱:Java-EX,代碼行數:4,代碼來源:LinkedList.java

示例13: characteristics

@Override
public int characteristics() {
    return Spliterator.SIZED | Spliterator.SUBSIZED |
           Spliterator.ORDERED | Spliterator.IMMUTABLE;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:5,代碼來源:Streams.java

示例14: characteristics

@Override
public int characteristics() {
    return (s.characteristics() & ~(Spliterator.SIZED | Spliterator.SUBSIZED |
                                    Spliterator.SORTED | Spliterator.ORDERED))
           | Spliterator.DISTINCT;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:StreamSpliterators.java


注:本文中的java.util.Spliterator.ORDERED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。