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


Java Spliterators.iterator方法代碼示例

本文整理匯總了Java中java.util.Spliterators.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java Spliterators.iterator方法的具體用法?Java Spliterators.iterator怎麽用?Java Spliterators.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Spliterators的用法示例。


在下文中一共展示了Spliterators.iterator方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: zip

import java.util.Spliterators; //導入方法依賴的package包/類
/**
 * Returns a stream in which each element is the result of passing the corresponding elementY 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>Note that if you are calling {@link Stream#forEach} on the resulting stream, you might want
 * to consider using {@link #forEachPair} instead of this method.
 *
 * <p><b>Performance note:</b> 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:zugzug90,項目名稱:guava-mock,代碼行數:54,代碼來源:Streams.java

示例2: zip

import java.util.Spliterators; //導入方法依賴的package包/類
/**
 * 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,代碼行數:51,代碼來源:Streams.java

示例3: cellSet

import java.util.Spliterators; //導入方法依賴的package包/類
@Override
public Set<Cell<R, C, V>> cellSet() {
    return new AbstractSet<Cell<R, C, V>>() {
        @Override
        public int size() {
            return TableView.this.size();
        }

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

        @Override
        public boolean contains(Object o) {
            if(!(o instanceof Cell)) return false;
            final Cell cell = (Cell) o;
            return Objects.equals(get(cell.getRowKey(), cell.getColumnKey()), cell.getValue());
        }

        @Override
        public Stream<Cell<R, C, V>> stream() {
            return map.entrySet()
                      .stream()
                      .flatMap(row -> row.getValue()
                                         .entrySet()
                                         .stream()
                                         .map(col -> Tables.immutableCell(row.getKey(),
                                                                          col.getKey(),
                                                                          col.getValue())));
        }

        @Override
        public Spliterator<Cell<R, C, V>> spliterator() {
            return stream().spliterator();
        }

        @Override
        public Iterator<Cell<R, C, V>> iterator() {
            return Spliterators.iterator(spliterator());
        }
    };
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:44,代碼來源:TableView.java

示例4: iterator

import java.util.Spliterators; //導入方法依賴的package包/類
@Override
public final PrimitiveIterator.OfLong iterator() {
    return Spliterators.iterator(spliterator());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:LongPipeline.java

示例5: iterator

import java.util.Spliterators; //導入方法依賴的package包/類
@Override
public final PrimitiveIterator.OfDouble iterator() {
    return Spliterators.iterator(spliterator());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:DoublePipeline.java

示例6: iterator

import java.util.Spliterators; //導入方法依賴的package包/類
@Override
public PrimitiveIterator.OfDouble iterator() {
    return Spliterators.iterator(spliterator());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TestData.java

示例7: iterator

import java.util.Spliterators; //導入方法依賴的package包/類
@Override
public PrimitiveIterator.OfLong iterator() {
    return Spliterators.iterator(spliterator());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:5,代碼來源:SpinedBuffer.java

示例8: iterator

import java.util.Spliterators; //導入方法依賴的package包/類
@Override
public final Iterator<P_OUT> iterator() {
    return Spliterators.iterator(spliterator());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:ReferencePipeline.java

示例9: iterator

import java.util.Spliterators; //導入方法依賴的package包/類
@Override
public PrimitiveIterator.OfInt iterator() {
    return Spliterators.iterator(spliterator());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:SpinedBuffer.java

示例10: iterator

import java.util.Spliterators; //導入方法依賴的package包/類
@Override
public final PrimitiveIterator.OfInt iterator() {
    return Spliterators.iterator(spliterator());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:IntPipeline.java


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