当前位置: 首页>>代码示例>>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;未经允许,请勿转载。