java.util.Collection.spliterator()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(195)

本文整理了Java中java.util.Collection.spliterator()方法的一些代码示例,展示了Collection.spliterator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collection.spliterator()方法的具体详情如下:
包路径:java.util.Collection
类名称:Collection
方法名:spliterator

Collection.spliterator介绍

暂无

代码示例

代码示例来源:origin: google/guava

@Override
public Spliterator<E> spliterator() {
 synchronized (mutex) {
  return delegate().spliterator();
 }
}

代码示例来源:origin: google/guava

@Override
public Spliterator<K> spliterator() {
 return CollectSpliterators.map(multimap.entries().spliterator(), Map.Entry::getKey);
}

代码示例来源:origin: google/guava

@Override
public Spliterator<E> spliterator() {
 return CollectSpliterators.filter(unfiltered.spliterator(), predicate);
}

代码示例来源:origin: google/guava

@Override
public Spliterator<T> spliterator() {
 return CollectSpliterators.map(fromCollection.spliterator(), function);
}

代码示例来源:origin: prestodb/presto

@Override
public Spliterator<E> spliterator() {
 synchronized (mutex) {
  return delegate().spliterator();
 }
}

代码示例来源:origin: prestodb/presto

@Override
public Spliterator<E> spliterator() {
 return CollectSpliterators.filter(unfiltered.spliterator(), predicate);
}

代码示例来源:origin: prestodb/presto

@Override
public Spliterator<T> spliterator() {
 return CollectSpliterators.map(fromCollection.spliterator(), function);
}

代码示例来源:origin: google/guava

@Override
Spliterator<V> valueSpliterator() {
 return CollectSpliterators.flatMap(
   map.values().spliterator(), Collection::spliterator, Spliterator.SIZED, size());
}

代码示例来源:origin: google/guava

@Override
Spliterator<Entry<K, V>> entrySpliterator() {
 return CollectSpliterators.flatMap(
   map.entrySet().spliterator(),
   keyToValueCollectionEntry -> {
    K key = keyToValueCollectionEntry.getKey();
    Collection<V> valueCollection = keyToValueCollectionEntry.getValue();
    return CollectSpliterators.map(
      valueCollection.spliterator(), (V value) -> Maps.immutableEntry(key, value));
   },
   Spliterator.SIZED,
   size());
}

代码示例来源:origin: google/guava

@Override
Spliterator<Entry<K, V>> entrySpliterator() {
 return CollectSpliterators.flatMap(
   asMap().entrySet().spliterator(),
   keyToValueCollectionEntry -> {
    K key = keyToValueCollectionEntry.getKey();
    Collection<V> valueCollection = keyToValueCollectionEntry.getValue();
    return CollectSpliterators.map(
      valueCollection.spliterator(), (V value) -> Maps.immutableEntry(key, value));
   },
   Spliterator.SIZED | (this instanceof SetMultimap ? Spliterator.DISTINCT : 0),
   size());
}

代码示例来源:origin: prestodb/presto

@Override
Spliterator<V> valueSpliterator() {
 return CollectSpliterators.flatMap(
   map.values().spliterator(), Collection::spliterator, Spliterator.SIZED, size());
}

代码示例来源:origin: google/guava

@CollectionFeature.Require(SUPPORTS_ADD)
public void testSpliteratorNotImmutable_CollectionAllowsAdd() {
 // If add is supported, verify that IMMUTABLE is not reported.
 synchronized (collection) { // for Collections.synchronized
  assertFalse(collection.spliterator().hasCharacteristics(Spliterator.IMMUTABLE));
 }
}

代码示例来源:origin: prestodb/presto

@Override
public Spliterator<K> spliterator() {
 return CollectSpliterators.map(multimap.entries().spliterator(), Map.Entry::getKey);
}

代码示例来源:origin: google/guava

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testSpliteratorNotImmutable_CollectionAllowsRemove() {
 // If remove is supported, verify that IMMUTABLE is not reported.
 synchronized (collection) { // for Collections.synchronized
  assertFalse(collection.spliterator().hasCharacteristics(Spliterator.IMMUTABLE));
 }
}

代码示例来源:origin: prestodb/presto

@Override
Spliterator<Entry<K, V>> entrySpliterator() {
 return CollectSpliterators.flatMap(
   map.entrySet().spliterator(),
   keyToValueCollectionEntry -> {
    K key = keyToValueCollectionEntry.getKey();
    Collection<V> valueCollection = keyToValueCollectionEntry.getValue();
    return CollectSpliterators.map(
      valueCollection.spliterator(), (V value) -> Maps.immutableEntry(key, value));
   },
   Spliterator.SIZED,
   size());
}

代码示例来源:origin: google/guava

public void testEntriesSpliterator() {
 List<Entry<String, Integer>> expectedEntries =
   asList(
     Maps.immutableEntry("foo", 2),
     Maps.immutableEntry("foo", 3),
     Maps.immutableEntry("bar", 4),
     Maps.immutableEntry("bar", 5),
     Maps.immutableEntry("foo", 6));
 Multimap<String, Integer> multimap = LinkedHashMultimap.create();
 for (Entry<String, Integer> entry : expectedEntries) {
  multimap.put(entry.getKey(), entry.getValue());
 }
 List<Entry<String, Integer>> actualEntries = new ArrayList<>();
 multimap.entries().spliterator().forEachRemaining(actualEntries::add);
 assertThat(actualEntries).containsExactlyElementsIn(expectedEntries).inOrder();
}

代码示例来源:origin: google/guava

public void testValuesSpliterator() {
  List<Entry<String, Integer>> expectedEntries =
    asList(
      Maps.immutableEntry("foo", 2),
      Maps.immutableEntry("foo", 3),
      Maps.immutableEntry("bar", 4),
      Maps.immutableEntry("bar", 5),
      Maps.immutableEntry("foo", 6));
  Multimap<String, Integer> multimap = LinkedHashMultimap.create();
  for (Entry<String, Integer> entry : expectedEntries) {
   multimap.put(entry.getKey(), entry.getValue());
  }
  List<Integer> actualValues = new ArrayList<>();
  multimap.values().spliterator().forEachRemaining(actualValues::add);
  assertThat(actualValues)
    .containsExactlyElementsIn(Lists.transform(expectedEntries, Entry::getValue))
    .inOrder();
 }
}

代码示例来源:origin: google/guava

@CollectionFeature.Require(ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testSpliteratorNullable() {
 initCollectionWithNullElement();
 synchronized (collection) { // for Collections.synchronized
  assertFalse(collection.spliterator().hasCharacteristics(Spliterator.NONNULL));
 }
}

代码示例来源:origin: prestodb/presto

@Override
Spliterator<Entry<K, V>> entrySpliterator() {
 return CollectSpliterators.flatMap(
   asMap().entrySet().spliterator(),
   keyToValueCollectionEntry -> {
    K key = keyToValueCollectionEntry.getKey();
    Collection<V> valueCollection = keyToValueCollectionEntry.getValue();
    return CollectSpliterators.map(
      valueCollection.spliterator(), (V value) -> Maps.immutableEntry(key, value));
   },
   Spliterator.SIZED | (this instanceof SetMultimap ? Spliterator.DISTINCT : 0),
   size());
}

代码示例来源:origin: ben-manes/caffeine

@CacheSpec
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
public void valueSpliterator_tryAdvance(Map<Integer, Integer> map, CacheContext context) {
 Spliterator<Integer> spliterator = map.values().spliterator();
 int[] count = new int[1];
 boolean advanced;
 do {
  advanced = spliterator.tryAdvance(value -> count[0]++);
 } while (advanced);
 assertThat(count[0], is(map.size()));
}

相关文章