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

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

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

Set.removeIf介绍

暂无

代码示例

代码示例来源:origin: apache/flink

@Override
public void notifyCheckpointComplete(long completedCheckpointId) {
  synchronized (materializedSstFiles) {
    if (completedCheckpointId > lastCompletedCheckpointId) {
      materializedSstFiles.keySet().removeIf(checkpointId -> checkpointId < completedCheckpointId);
      lastCompletedCheckpointId = completedCheckpointId;
    }
  }
}

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

/**
 * Clear the merged bean definition cache, removing entries for beans
 * which are not considered eligible for full metadata caching yet.
 * <p>Typically triggered after changes to the original bean definitions,
 * e.g. after applying a {@code BeanFactoryPostProcessor}. Note that metadata
 * for beans which have already been created at this point will be kept around.
 * @since 4.2
 */
public void clearMetadataCache() {
  this.mergedBeanDefinitions.keySet().removeIf(bean -> !isBeanEligibleForMetadataCaching(bean));
}

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

void purgeExpiredRegistries() {
  long now = System.currentTimeMillis();
  this.remoteRegistries.entrySet().removeIf(entry -> entry.getValue().isExpired(now));
}

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

/**
 * Clear the introspection cache for the given ClassLoader, removing the
 * introspection results for all classes underneath that ClassLoader, and
 * removing the ClassLoader (and its children) from the acceptance list.
 * @param classLoader the ClassLoader to clear the cache for
 */
public static void clearClassLoader(@Nullable ClassLoader classLoader) {
  acceptedClassLoaders.removeIf(registeredLoader ->
      isUnderneathClassLoader(registeredLoader, classLoader));
  strongClassCache.keySet().removeIf(beanClass ->
      isUnderneathClassLoader(beanClass.getClassLoader(), classLoader));
  softClassCache.keySet().removeIf(beanClass ->
      isUnderneathClassLoader(beanClass.getClassLoader(), classLoader));
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Override
public boolean remove(Predicate<Cookie> predicate) {
 return cookieJar.entrySet().removeIf(v -> predicate.test(v.getValue().cookie));
}

代码示例来源:origin: apache/kafka

synchronized void retainTopics(Collection<String> topics) {
  metadataByPartition.entrySet().removeIf(entry -> !topics.contains(entry.getKey().topic()));
  unauthorizedTopics.retainAll(topics);
  invalidTopics.retainAll(topics);
  computeClusterView();
}

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

/**
 * Deregisters a cache entry listener based on the supplied configuration.
 *
 * @param configuration the listener's configuration.
 */
public void deregister(CacheEntryListenerConfiguration<K, V> configuration) {
 requireNonNull(configuration);
 dispatchQueues.keySet().removeIf(registration ->
   configuration.equals(registration.getConfiguration()));
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Removes all keys whose count is 0. After incrementing and decrementing
 * counts or adding and subtracting Counters, there may be keys left whose
 * count is 0, though normally this is undesirable. This method cleans up
 * the map.
 * <p>
 * Maybe in the future we should try to do this more on-the-fly, though it's
 * not clear whether a distinction should be made between "never seen" (i.e.
 * null count) and "seen with 0 count". Certainly there's no distinction in
 * getCount() but there is in containsKey().
 */
public void removeZeroCounts() {
 map.keySet().removeIf(e -> getCount(e) == 0);
}

代码示例来源:origin: org.springframework/spring-beans

/**
 * Clear the merged bean definition cache, removing entries for beans
 * which are not considered eligible for full metadata caching yet.
 * <p>Typically triggered after changes to the original bean definitions,
 * e.g. after applying a {@code BeanFactoryPostProcessor}. Note that metadata
 * for beans which have already been created at this point will be kept around.
 * @since 4.2
 */
public void clearMetadataCache() {
  this.mergedBeanDefinitions.keySet().removeIf(bean -> !isBeanEligibleForMetadataCaching(bean));
}

代码示例来源:origin: apache/incubator-druid

@Override
public void close(String namespace)
{
 if (config.isEvictOnClose()) {
  cache.asMap().keySet().removeIf(key -> key.namespace.equals(namespace));
 }
}

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

private void cleanupMonitorListeners( Object monitorListener, Method key )
{
  methodMonitorListeners.computeIfPresent( key, ( method1, handlers ) ->
  {
    handlers.removeIf( handler -> monitorListener.equals( handler.getMonitorListener() ) );
    return handlers.isEmpty() ? null : handlers;
  } );
}

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

private void markSeen( Class<? extends AnyValue> typeToCheck, Set<Class<? extends AnyValue>> seen )
{
  seen.removeIf( t -> t.isAssignableFrom( typeToCheck ) );
}

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

result.removeIf(expression -> !expression.match(contentType));
return (!result.isEmpty() ? new ConsumesRequestCondition(result) : null);

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

/**
 * Checks if any of the contained media type expressions match the given
 * request 'Content-Type' header and returns an instance that is guaranteed
 * to contain matching expressions only. The match is performed via
 * {@link MediaType#includes(MediaType)}.
 * @param exchange the current exchange
 * @return the same instance if the condition contains no expressions;
 * or a new condition with matching expressions only;
 * or {@code null} if no expressions match.
 */
@Override
public ConsumesRequestCondition getMatchingCondition(ServerWebExchange exchange) {
  if (CorsUtils.isPreFlightRequest(exchange.getRequest())) {
    return PRE_FLIGHT_MATCH;
  }
  if (isEmpty()) {
    return this;
  }
  Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
  result.removeIf(expression -> !expression.match(exchange));
  return (!result.isEmpty() ? new ConsumesRequestCondition(result) : null);
}

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

private static boolean fileContains( File file, String... expectedStrings ) throws IOException
{
  Set<String> expectedStringSet = asSet( expectedStrings );
  try ( Stream<String> lines = Files.lines( file.toPath() ) )
  {
    lines.forEach( line -> expectedStringSet.removeIf( line::contains ) );
  }
  return expectedStringSet.isEmpty();
}

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

@Override
public synchronized void dropPartition(String databaseName, String tableName, List<String> parts, boolean deleteData)
{
  partitions.entrySet().removeIf(entry ->
      entry.getKey().matches(databaseName, tableName) && entry.getValue().getValues().equals(parts));
}

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

@CacheSpec
@CheckNoStats
@Test(dataProvider = "caches")
public void entrySet_removeIf(Map<Integer, Integer> map, CacheContext context) {
 Predicate<Entry<Integer, Integer>> isEven = entry -> (entry.getValue() % 2) == 0;
 boolean hasEven = map.entrySet().stream().anyMatch(isEven);
 boolean removedIfEven = map.entrySet().removeIf(isEven);
 assertThat(map.entrySet().stream().anyMatch(isEven), is(false));
 assertThat(removedIfEven, is(hasEven));
 if (removedIfEven) {
  assertThat(map.size(), is(lessThan(context.original().size())));
 }
}

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

@CacheSpec
@CheckNoStats
@Test(dataProvider = "caches", expectedExceptions = NullPointerException.class)
public void entrySet_removeIf_null(Map<Integer, Integer> map, CacheContext context) {
 map.entrySet().removeIf(null);
}

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

public void testRemoveIfWithConcurrentRemoval() {
 LocalCache<Integer, Integer> map =
   makeLocalCache(createCacheBuilder().concurrencyLevel(1).initialCapacity(1));
 map.put(0, 1);
 map.put(1, 1);
 map.put(2, 1);
 map.entrySet()
   .removeIf(
     entry -> {
      assertThat(entry.getValue()).isNotNull();
      map.remove((entry.getKey() + 1) % 3);
      return false;
     });
 assertEquals(1, map.size());
}

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

public void testRemoveIfWithConcurrentModification() {
 LocalCache<Integer, Integer> map =
   makeLocalCache(createCacheBuilder().concurrencyLevel(1).initialCapacity(1));
 map.put(1, 1);
 map.put(2, 1);
 map.put(3, 1);
 map.entrySet()
   .removeIf(
     entry -> {
      if (entry.getValue().equals(1)) {
       map.put(entry.getKey(), 2);
       return true;
      } else {
       return false;
      }
     });
 assertEquals(3, map.size());
 assertFalse(map.containsValue(1));
}

相关文章