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

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

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

Collection.removeIf介绍

暂无

代码示例

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

  1. /**
  2. * Removes all mappings from this map whose values are zero.
  3. *
  4. * <p>This method is not atomic: the map may be visible in intermediate states, where some of the
  5. * zero values have been removed and others have not.
  6. */
  7. public void removeAllZeros() {
  8. map.values().removeIf(x -> x == 0);
  9. }

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

  1. @Override
  2. public boolean removeIf(java.util.function.Predicate<? super E> filter) {
  3. checkNotNull(filter);
  4. return unfiltered.removeIf(element -> predicate.apply(element) && filter.test(element));
  5. }

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

  1. @Override
  2. public boolean removeIf(java.util.function.Predicate<? super T> filter) {
  3. checkNotNull(filter);
  4. return fromCollection.removeIf(element -> filter.test(function.apply(element)));
  5. }

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

  1. /**
  2. * Removes all mappings from this map whose values are zero.
  3. *
  4. * <p>This method is not atomic: the map may be visible in intermediate states, where some of the
  5. * zero values have been removed and others have not.
  6. */
  7. public void removeAllZeros() {
  8. map.values().removeIf(x -> x == 0);
  9. }

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

  1. @Override
  2. public boolean removeIf(Predicate<? super E> filter) {
  3. synchronized (mutex) {
  4. return delegate().removeIf(filter);
  5. }
  6. }

代码示例来源:origin: neo4j/neo4j

  1. void cancelAllJobs()
  2. {
  3. registry.values().removeIf( future ->
  4. {
  5. future.cancel( true );
  6. return true;
  7. } );
  8. }

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

  1. @Override
  2. public boolean removeIf(Predicate<? super E> filter) {
  3. synchronized (mutex) {
  4. return delegate().removeIf(filter);
  5. }
  6. }

代码示例来源:origin: Netflix/zuul

  1. public boolean removeIf(Predicate<? super Map.Entry<HeaderName, String>> filter) {
  2. return delegate.entries().removeIf(filter);
  3. }

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

  1. @Override
  2. public boolean removeIf(java.util.function.Predicate<? super E> filter) {
  3. checkNotNull(filter);
  4. return unfiltered.removeIf(element -> predicate.apply(element) && filter.test(element));
  5. }

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

  1. @Override
  2. public boolean removeIf(java.util.function.Predicate<? super T> filter) {
  3. checkNotNull(filter);
  4. return fromCollection.removeIf(element -> filter.test(function.apply(element)));
  5. }

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

  1. /**
  2. * Removes, from an iterable, every element that satisfies the provided predicate.
  3. *
  4. * <p>Removals may or may not happen immediately as each element is tested against the predicate.
  5. * The behavior of this method is not specified if {@code predicate} is dependent on {@code
  6. * removeFrom}.
  7. *
  8. * <p><b>Java 8 users:</b> if {@code removeFrom} is a {@link Collection}, use {@code
  9. * removeFrom.removeIf(predicate)} instead.
  10. *
  11. * @param removeFrom the iterable to (potentially) remove elements from
  12. * @param predicate a predicate that determines whether an element should be removed
  13. * @return {@code true} if any elements were removed from the iterable
  14. * @throws UnsupportedOperationException if the iterable does not support {@code remove()}.
  15. * @since 2.0
  16. */
  17. @CanIgnoreReturnValue
  18. public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate) {
  19. if (removeFrom instanceof Collection) {
  20. return ((Collection<T>) removeFrom).removeIf(predicate);
  21. }
  22. return Iterators.removeIf(removeFrom.iterator(), predicate);
  23. }

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

  1. @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  2. public void testRemoveIf_alwaysFalse() {
  3. assertFalse("removeIf(x -> false) should return false", collection.removeIf(x -> false));
  4. expectUnchanged();
  5. }

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

  1. @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  2. @CollectionSize.Require(ZERO)
  3. public void testRemoveIf_unsupportedEmptyCollection() {
  4. try {
  5. assertFalse(
  6. "removeIf(Predicate) should return false or throw " + "UnsupportedOperationException",
  7. collection.removeIf(
  8. x -> {
  9. throw new AssertionError("predicate should never be called");
  10. }));
  11. } catch (UnsupportedOperationException tolerated) {
  12. }
  13. expectUnchanged();
  14. }

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

  1. @CollectionFeature.Require({SUPPORTS_ITERATOR_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
  2. @CollectionSize.Require(SEVERAL)
  3. public void testRemoveIfSomeMatchesConcurrentWithIteration() {
  4. try {
  5. Iterator<E> iterator = collection.iterator();
  6. assertTrue(collection.removeIf(Predicate.isEqual(samples.e0())));
  7. iterator.next();
  8. fail("Expected ConcurrentModificationException");
  9. } catch (ConcurrentModificationException expected) {
  10. // success
  11. }
  12. }

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

  1. @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  2. @CollectionSize.Require(absent = ZERO)
  3. public void testRemoveIf_allPresent() {
  4. assertTrue("removeIf(x -> true) should return true", collection.removeIf(x -> true));
  5. expectContents();
  6. }

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

  1. @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  2. @CollectionSize.Require(absent = ZERO)
  3. public void testRemoveIf_alwaysTrueUnsupported() {
  4. try {
  5. collection.removeIf(x -> true);
  6. fail("removeIf(x -> true) should throw " + "UnsupportedOperationException");
  7. } catch (UnsupportedOperationException expected) {
  8. }
  9. expectUnchanged();
  10. assertTrue(collection.contains(samples.e0()));
  11. }
  12. }

代码示例来源:origin: spring-projects/spring-framework

  1. protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
  2. if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) {
  3. return;
  4. }
  5. ConfigurationClass existingClass = this.configurationClasses.get(configClass);
  6. if (existingClass != null) {
  7. if (configClass.isImported()) {
  8. if (existingClass.isImported()) {
  9. existingClass.mergeImportedBy(configClass);
  10. }
  11. // Otherwise ignore new imported config class; existing non-imported class overrides it.
  12. return;
  13. }
  14. else {
  15. // Explicit bean definition found, probably replacing an import.
  16. // Let's remove the old one and go with the new one.
  17. this.configurationClasses.remove(configClass);
  18. this.knownSuperclasses.values().removeIf(configClass::equals);
  19. }
  20. }
  21. // Recursively process the configuration class and its superclass hierarchy.
  22. SourceClass sourceClass = asSourceClass(configClass);
  23. do {
  24. sourceClass = doProcessConfigurationClass(configClass, sourceClass);
  25. }
  26. while (sourceClass != null);
  27. this.configurationClasses.put(configClass, configClass);
  28. }

代码示例来源:origin: Netflix/zuul

  1. public boolean removeIf(Predicate<? super Map.Entry<HeaderName, String>> filter) {
  2. return delegate.entries().removeIf(filter);
  3. }

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

  1. @CacheSpec
  2. @CheckNoStats
  3. @Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
  4. public void values_removeIf_null(Map<Integer, Integer> map, CacheContext context) {
  5. map.values().removeIf(null);
  6. }

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

  1. @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  2. @CollectionSize.Require(absent = ZERO)
  3. public void testRemoveIf_sometimesTrue() {
  4. assertTrue(
  5. "removeIf(isEqual(present)) should return true",
  6. collection.removeIf(Predicate.isEqual(samples.e0())));
  7. expectMissing(samples.e0());
  8. }

相关文章