本文整理了Java中java.util.Collection.removeIf()
方法的一些代码示例,展示了Collection.removeIf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collection.removeIf()
方法的具体详情如下:
包路径:java.util.Collection
类名称:Collection
方法名:removeIf
暂无
代码示例来源:origin: google/guava
/**
* Removes all mappings from this map whose values are zero.
*
* <p>This method is not atomic: the map may be visible in intermediate states, where some of the
* zero values have been removed and others have not.
*/
public void removeAllZeros() {
map.values().removeIf(x -> x == 0);
}
代码示例来源:origin: google/guava
@Override
public boolean removeIf(java.util.function.Predicate<? super E> filter) {
checkNotNull(filter);
return unfiltered.removeIf(element -> predicate.apply(element) && filter.test(element));
}
代码示例来源:origin: google/guava
@Override
public boolean removeIf(java.util.function.Predicate<? super T> filter) {
checkNotNull(filter);
return fromCollection.removeIf(element -> filter.test(function.apply(element)));
}
代码示例来源:origin: prestodb/presto
/**
* Removes all mappings from this map whose values are zero.
*
* <p>This method is not atomic: the map may be visible in intermediate states, where some of the
* zero values have been removed and others have not.
*/
public void removeAllZeros() {
map.values().removeIf(x -> x == 0);
}
代码示例来源:origin: google/guava
@Override
public boolean removeIf(Predicate<? super E> filter) {
synchronized (mutex) {
return delegate().removeIf(filter);
}
}
代码示例来源:origin: neo4j/neo4j
void cancelAllJobs()
{
registry.values().removeIf( future ->
{
future.cancel( true );
return true;
} );
}
代码示例来源:origin: prestodb/presto
@Override
public boolean removeIf(Predicate<? super E> filter) {
synchronized (mutex) {
return delegate().removeIf(filter);
}
}
代码示例来源:origin: Netflix/zuul
public boolean removeIf(Predicate<? super Map.Entry<HeaderName, String>> filter) {
return delegate.entries().removeIf(filter);
}
代码示例来源:origin: prestodb/presto
@Override
public boolean removeIf(java.util.function.Predicate<? super E> filter) {
checkNotNull(filter);
return unfiltered.removeIf(element -> predicate.apply(element) && filter.test(element));
}
代码示例来源:origin: prestodb/presto
@Override
public boolean removeIf(java.util.function.Predicate<? super T> filter) {
checkNotNull(filter);
return fromCollection.removeIf(element -> filter.test(function.apply(element)));
}
代码示例来源:origin: google/guava
/**
* Removes, from an iterable, every element that satisfies the provided predicate.
*
* <p>Removals may or may not happen immediately as each element is tested against the predicate.
* The behavior of this method is not specified if {@code predicate} is dependent on {@code
* removeFrom}.
*
* <p><b>Java 8 users:</b> if {@code removeFrom} is a {@link Collection}, use {@code
* removeFrom.removeIf(predicate)} instead.
*
* @param removeFrom the iterable to (potentially) remove elements from
* @param predicate a predicate that determines whether an element should be removed
* @return {@code true} if any elements were removed from the iterable
* @throws UnsupportedOperationException if the iterable does not support {@code remove()}.
* @since 2.0
*/
@CanIgnoreReturnValue
public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate) {
if (removeFrom instanceof Collection) {
return ((Collection<T>) removeFrom).removeIf(predicate);
}
return Iterators.removeIf(removeFrom.iterator(), predicate);
}
代码示例来源:origin: google/guava
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testRemoveIf_alwaysFalse() {
assertFalse("removeIf(x -> false) should return false", collection.removeIf(x -> false));
expectUnchanged();
}
代码示例来源:origin: google/guava
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(ZERO)
public void testRemoveIf_unsupportedEmptyCollection() {
try {
assertFalse(
"removeIf(Predicate) should return false or throw " + "UnsupportedOperationException",
collection.removeIf(
x -> {
throw new AssertionError("predicate should never be called");
}));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
代码示例来源:origin: google/guava
@CollectionFeature.Require({SUPPORTS_ITERATOR_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(SEVERAL)
public void testRemoveIfSomeMatchesConcurrentWithIteration() {
try {
Iterator<E> iterator = collection.iterator();
assertTrue(collection.removeIf(Predicate.isEqual(samples.e0())));
iterator.next();
fail("Expected ConcurrentModificationException");
} catch (ConcurrentModificationException expected) {
// success
}
}
代码示例来源:origin: google/guava
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveIf_allPresent() {
assertTrue("removeIf(x -> true) should return true", collection.removeIf(x -> true));
expectContents();
}
代码示例来源:origin: google/guava
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveIf_alwaysTrueUnsupported() {
try {
collection.removeIf(x -> true);
fail("removeIf(x -> true) should throw " + "UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
assertTrue(collection.contains(samples.e0()));
}
}
代码示例来源:origin: spring-projects/spring-framework
protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) {
return;
}
ConfigurationClass existingClass = this.configurationClasses.get(configClass);
if (existingClass != null) {
if (configClass.isImported()) {
if (existingClass.isImported()) {
existingClass.mergeImportedBy(configClass);
}
// Otherwise ignore new imported config class; existing non-imported class overrides it.
return;
}
else {
// Explicit bean definition found, probably replacing an import.
// Let's remove the old one and go with the new one.
this.configurationClasses.remove(configClass);
this.knownSuperclasses.values().removeIf(configClass::equals);
}
}
// Recursively process the configuration class and its superclass hierarchy.
SourceClass sourceClass = asSourceClass(configClass);
do {
sourceClass = doProcessConfigurationClass(configClass, sourceClass);
}
while (sourceClass != null);
this.configurationClasses.put(configClass, configClass);
}
代码示例来源:origin: Netflix/zuul
public boolean removeIf(Predicate<? super Map.Entry<HeaderName, String>> filter) {
return delegate.entries().removeIf(filter);
}
代码示例来源:origin: ben-manes/caffeine
@CacheSpec
@CheckNoStats
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void values_removeIf_null(Map<Integer, Integer> map, CacheContext context) {
map.values().removeIf(null);
}
代码示例来源:origin: google/guava
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveIf_sometimesTrue() {
assertTrue(
"removeIf(isEqual(present)) should return true",
collection.removeIf(Predicate.isEqual(samples.e0())));
expectMissing(samples.e0());
}
内容来源于网络,如有侵权,请联系作者删除!