java.util.HashSet.forEach()方法的使用及代码示例

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

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

HashSet.forEach介绍

暂无

代码示例

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

/**
 * Release a single reference to the current request scope instance.
 * <p>
 * Once all instance references are released, the instance will be recycled.
 */
@Override
public void release() {
  if (referenceCounter.decrementAndGet() < 1) {
    try {
      new HashSet<>(store.keySet()).forEach(this::remove);
    } finally {
      logger.debugLog("Released scope instance {0}", this);
    }
  }
}

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

/**
 * Release a single reference to the current request scope instance.
 * <p>
 * Once all instance references are released, the instance will be recycled.
 */
@Override
public void release() {
  if (referenceCounter.decrementAndGet() < 1) {
    try {
      new HashSet<>(store.keySet()).forEach(this::remove);
    } finally {
      logger.debugLog("Released scope instance {0}", this);
    }
  }
}

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

public void predict(Set<String> predictedRelationsRaw, Set<String> goldRelationsRaw) {
 Set<String> predictedRelations = new HashSet<>(predictedRelationsRaw);
 predictedRelations.remove(NO_RELATION);
 Set<String> goldRelations = new HashSet<>(goldRelationsRaw);
 goldRelations.remove(NO_RELATION);
 // Register the prediction
 for (String pred : predictedRelations) {
  if (goldRelations.contains(pred)) {
   correctCount.incrementCount(pred);
  }
  predictedCount.incrementCount(pred);
 }
 goldRelations.forEach(goldCount::incrementCount);
 HashSet<String> allRelations = new HashSet<String>(){{ addAll(predictedRelations); addAll(goldRelations); }};
 allRelations.forEach(totalCount::incrementCount);
 // Register the confusion matrix
 if (predictedRelations.size() == 1 && goldRelations.size() == 1) {
  confusion.add(predictedRelations.iterator().next(), goldRelations.iterator().next());
 }
 if (predictedRelations.size() == 1 && goldRelations.isEmpty()) {
  confusion.add(predictedRelations.iterator().next(), "NR");
 }
 if (predictedRelations.isEmpty() && goldRelations.size() == 1) {
  confusion.add("NR", goldRelations.iterator().next());
 }
}

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

CommandFactory(
  final List<AgentCommandArguments> agentCommandArguments,
  final ApplicationContext applicationContext
) {
  this.agentCommandArgumentsBeans = agentCommandArguments;
  this.applicationContext = applicationContext;
  agentCommandArguments.forEach(
    commandArgs -> {
      Sets.newHashSet(commandArgs.getClass().getAnnotation(Parameters.class).commandNames()).forEach(
        commandName -> {
          commandMap.put(commandName, commandArgs.getConsumerClass());
        }
      );
    }
  );
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

private String buildDiffs() {
    final StringBuilder builder = new StringBuilder();
    builder.append("acquired but not released:\n");
    HashSet<String> keyDiff = new HashSet<>(acquiredCounts.keySet());
    keyDiff.removeAll(releasedCounts.keySet());
    keyDiff.forEach(k -> {
      builder.append(k).append("(").append(acquiredCounts.get(k)).append(")\n");
    });
    builder.append("released but not acquired:\n");
    keyDiff.clear();
    keyDiff.addAll(releasedCounts.keySet());
    keyDiff.removeAll(acquiredCounts.keySet());
    keyDiff.forEach(k -> {
      builder.append(k).append("(").append(releasedCounts.get(k)).append(")\n");
    });
    return builder.toString();
  }
}

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

@Test
public void headersWhenDisableThenNoSecurityHeaders() {
  new HashSet<>(this.expectedHeaders.keySet()).forEach(this::expectHeaderNamesNotPresent);
  this.headers.disable();
  assertHeaders();
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
  public void destroyAllData() {
    // Make a defensive copy of keys, as the map gets cleared when
    // removing components.
    new HashSet<>(activeComponents.keySet())
        .forEach(component -> removeComponent(component));
  }
};

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

attributeNames.forEach(name -> block.add(".addAttribute($L)\n", name));
expressionNames.forEach(name -> block.add(".addExpression($L)\n", name));
block.add(".build()");
ParameterizedTypeName type = parameterizedTypeName(Type.class, targetName);

代码示例来源:origin: palatable/lambda

/**
 * A lens that focuses on the keys of a map.
 *
 * @param <K> the key type
 * @param <V> the value type
 * @return a lens that focuses on the keys of a map
 */
public static <K, V> Lens.Simple<Map<K, V>, Set<K>> keys() {
  return simpleLens(m -> new HashSet<>(m.keySet()), (m, ks) -> {
    HashSet<K> ksCopy = new HashSet<>(ks);
    Map<K, V> updated = new HashMap<>(m);
    Set<K> keys = updated.keySet();
    keys.retainAll(ksCopy);
    ksCopy.removeAll(keys);
    ksCopy.forEach(k -> updated.put(k, null));
    return updated;
  });
}

代码示例来源:origin: zstackio/zstack

private void reScanHost(boolean skipExisting) {
  if (!skipExisting) {
    new HashSet<>(trackers.values()).forEach(Tracker::cancel);
  }
  new SQLBatch() {
    @Override
    protected void scripts() {
      long count = sql("select count(h) from HostVO h", Long.class).find();
      sql("select h.uuid from HostVO h", String.class).limit(1000).paginate(count, (List<String> hostUuids) -> {
        List<String> byUs = hostUuids.stream().filter(huuid -> {
          if (skipExisting) {
            return destMaker.isManagedByUs(huuid) && !trackers.containsKey(huuid);
          } else {
            return destMaker.isManagedByUs(huuid);
          }
        }).collect(Collectors.toList());
        trackHost(byUs);
      });
    }
  }.execute();
}

代码示例来源:origin: com.vaadin/flow-data

private void unregisterPassivatedKeys() {
  /*
   * Actually unregister anything that was removed in an update that the
   * client has confirmed that it has applied.
   */
  if (!confirmedUpdates.isEmpty()) {
    confirmedUpdates.forEach(this::doUnregister);
    confirmedUpdates.clear();
  }
}

代码示例来源:origin: neo4j-contrib/neo4j-graph-algorithms

/**
 * run node consumer in tx as long as he returns true
 *
 * @param consumer the node consumer
 * @return child instance to make methods of the child class accessible.
 */
public ME forEachNodeInTx(Consumer<Node> consumer) {
  withinTransaction(() -> nodes.forEach(consumer));
  return self;
}

代码示例来源:origin: docbleach/DocBleach

protected static void removeObProjRecord(Collection<Record> records) {
 new HashSet<>(records)
   .forEach(
     record -> {
      if (!isObProj(record)) {
       return;
      }
      records.remove(record);
      LOGGER.debug("Found and removed ObProj record: {}", record);
     });
}

代码示例来源:origin: org.neo4j/graph-algorithms-core

/**
 * run node consumer in tx as long as he returns true
 *
 * @param consumer the node consumer
 * @return child instance to make methods of the child class accessible.
 */
public ME forEachNodeInTx(Consumer<Node> consumer) {
  withinTransaction(() -> nodes.forEach(consumer));
  return self;
}

代码示例来源:origin: Camelcade/Perl5-IDEA

public PerlBuiltInVariablesService(Project project) {
 myPsiManager = PsiManager.getInstance(project);
 for (int i = 1; i <= 20; i++) {
  String variableName = Integer.toString(i);
  myScalars.put(variableName, new PerlBuiltInVariable(myPsiManager, "$" + variableName));
 }
 PerlBuiltInScalars.BUILT_IN.forEach(name -> myScalars.put(name, new PerlBuiltInVariable(myPsiManager, "$" + name)));
 PerlArrayUtil.BUILT_IN.forEach(name -> myArrays.put(name, new PerlBuiltInVariable(myPsiManager, "@" + name)));
 PerlHashUtil.BUILT_IN.forEach(name -> myHashes.put(name, new PerlBuiltInVariable(myPsiManager, "%" + name)));
 PerlGlobUtil.BUILT_IN.forEach(name -> myGlobs.put(name, new PerlBuiltInVariable(myPsiManager, "*" + name)));
}

代码示例来源:origin: semantic-integration/hypergraphql

public String toString(int i) {
  StringBuilder result = new StringBuilder();
  getForest().forEach(node -> result.append(node.toString(i)));
  return result.toString();
}

代码示例来源:origin: semantic-integration/hypergraphql

public Map<String, String> getFullLdContext() {
  Map<String, String> result = new HashMap<>();
  getForest().forEach(child -> result.putAll(child.getFullLdContext()));
  return result;
}

代码示例来源:origin: semantic-integration/hypergraphql

public Map<String, String> getFullLdContext() {
  Map<String, String> result = new HashMap<>();
  getForest().forEach(child -> result.putAll(child.getFullLdContext()));
  return result;
}

代码示例来源:origin: halirutan/Mathematica-IntelliJ-Plugin

private PsiElement[] findLightSymbolDeclarations(@NotNull LightSymbol lightSymbol) {
 SortedSet<PsiElement> result = new TreeSet<>(Comparator.comparing(PsiElement::getTextOffset));
 GlobalDefinitionCollector coll = new GlobalDefinitionCollector(lightSymbol.getContainingFile());
 if (coll.getAssignments().containsKey(lightSymbol.getName())) {
  coll.getAssignments().get(lightSymbol.getName()).forEach(
    assignmentProperty -> result.add(assignmentProperty.myLhsOfAssignment));
 }
 return result.toArray(PsiElement.EMPTY_ARRAY);
}

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

@After
public void shutdownServers() {
  new HashSet<>(serverRouter.handlerMap.values()).forEach(AbstractServer::shutdown);
}

相关文章