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

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

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

Set.addAll介绍

[英]Adds the objects in the specified collection which do not exist yet in this set.
[中]添加指定集合中此集合中尚不存在的对象。

代码示例

代码示例来源:origin: square/okhttp

public void redactHeader(String name) {
 Set<String> newHeadersToRedact = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
 newHeadersToRedact.addAll(headersToRedact);
 newHeadersToRedact.add(name);
 headersToRedact = newHeadersToRedact;
}

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

/**
 * Update the exposed {@link #cacheNames} set with the given name.
 * <p>This will always be called within a full {@link #cacheMap} lock
 * and effectively behaves like a {@code CopyOnWriteArraySet} with
 * preserved order but exposed as an unmodifiable reference.
 * @param name the name of the cache to be added
 */
private void updateCacheNames(String name) {
  Set<String> cacheNames = new LinkedHashSet<>(this.cacheNames.size() + 1);
  cacheNames.addAll(this.cacheNames);
  cacheNames.add(name);
  this.cacheNames = Collections.unmodifiableSet(cacheNames);
}

代码示例来源:origin: stackoverflow.com

Set<String> set = new HashSet<>();
set.addAll(Arrays.asList("leo","bale","hanks"));
Predicate<String> pred = set::contains;
boolean exists = pred.test("leo");

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

private void handleDependencyMaterial(Set<String> scmMaterialSet, DependencyMaterialConfig depMaterial, DependencyFanInNode node, Set<DependencyMaterialConfig> visitedNodes) {
  if (visitedNodes.contains(depMaterial)) {
    scmMaterialSet.addAll(dependencyMaterialFingerprintMap.get(depMaterial));
    return;
  }
  visitedNodes.add(depMaterial);
  final Set<String> scmMaterialFingerprintSet = new HashSet<>();
  buildRestOfTheGraph(node, cruiseConfig.pipelineConfigByName(depMaterial.getPipelineName()), scmMaterialFingerprintSet, visitedNodes);
  dependencyMaterialFingerprintMap.put(depMaterial, scmMaterialFingerprintSet);
  scmMaterialSet.addAll(scmMaterialFingerprintSet);
}

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

public void addSeedWords(String label, Collection<CandidatePhrase> seeds) throws Exception {
 if(!seedLabelDictionary.containsKey(label)){
  throw new Exception("label not present in the model");
 }
 Set<CandidatePhrase> seedWords = new HashSet<>(seedLabelDictionary.get(label));
 seedWords.addAll(seeds);
 seedLabelDictionary.put(label, Collections.unmodifiableSet(seedWords));
}

代码示例来源:origin: stackoverflow.com

Set<Integer> numbers = new TreeSet<Integer>();
 numbers.add(2);
 numbers.add(5);
 System.out.println(numbers); // "[2, 5]"
 System.out.println(numbers.contains(7)); // "false"
 System.out.println(numbers.add(5)); // "false"
 System.out.println(numbers.size()); // "2"
 int sum = 0;
 for (int n : numbers) {
   sum += n;
 }
 System.out.println("Sum = " + sum); // "Sum = 7"
 numbers.addAll(Arrays.asList(1,2,3,4,5));
 System.out.println(numbers); // "[1, 2, 3, 4, 5]"
 numbers.removeAll(Arrays.asList(4,5,6,7));
 System.out.println(numbers); // "[1, 2, 3]"
 numbers.retainAll(Arrays.asList(2,3,4,5));
 System.out.println(numbers); // "[2, 3]"

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

private void unregisterClientIDFromMap(Long clientID, Map interestMap, Set keysUnregistered) {
 if (interestMap.get(clientID) != null) {
  Map removed = (Map) interestMap.remove(clientID);
  if (removed != null) {
   keysUnregistered.addAll(removed.keySet());
  }
 }
}

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

if (!cl.ner().equals(ne)) continue;
 neStrings.add(m.lowercaseNormalizedSpanString());
Map<Integer, Set<Mention>> headPositions = Generics.newHashMap();
for (Mention p : predicts) {
 if (!headPositions.containsKey(p.headIndex)) headPositions.put(p.headIndex, Generics.newHashSet());
 headPositions.get(p.headIndex).add(p);
for (int hPos : headPositions.keySet()) {
 Set<Mention> shares = headPositions.get(hPos);
 if (shares.size() > 1) {
  Counter<Mention> probs = new ClassicCounter<>();
  for (Mention p : shares) {
  remove.addAll(probs.keySet());

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

/**
 * add allowed functions per column
 * @param columnName
 * @param udfs
 */
public void addComparisonOp(String columnName, String... udfs) {
 Set<String> allowed = columnToUDFs.get(columnName);
 if (allowed == null || allowed == udfNames) {
  // override
  columnToUDFs.put(columnName, new HashSet<String>(Arrays.asList(udfs)));
 } else {
  allowed.addAll(Arrays.asList(udfs));
 }
}

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

String attrName = (String) attrNames.nextElement();
  if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) {
    attrsToCheck.add(attrName);
attrsToCheck.addAll((Set<String>) attributesSnapshot.keySet());
  Object attrValue = attributesSnapshot.get(attrName);
  if (attrValue == null){
    request.removeAttribute(attrName);

代码示例来源:origin: stackoverflow.com

public static <K,R,S,T> Map<K, R> zipWith(Function2<R,S,T> fn, 
    Map<K, S> m1, Map<K, T> m2, Map<K, R> results){
  Set<K> keySet = new HashSet<K>();
  keySet.addAll(m1.keySet());
  keySet.addAll(m2.keySet());
  results.clear();
  for (K key : keySet) {
    results.put(key, fn.eval(m1.get(key), m2.get(key)));
  }
  return results;
 }

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

private Set<AsyncLoadBalanceClient> registerClients(final NodeIdentifier nodeId) {
  final Set<AsyncLoadBalanceClient> clients = new HashSet<>();
  for (int i=0; i < clientsPerNode; i++) {
    final AsyncLoadBalanceClient client = clientFactory.createClient(nodeId);
    clients.add(client);
    logger.debug("Added client {} for communicating with Node {}", client, nodeId);
  }
  clientMap.put(nodeId, clients);
  allClients.addAll(clients);
  if (running) {
    clients.forEach(AsyncLoadBalanceClient::start);
  }
  return clients;
}

代码示例来源:origin: vipshop/vjtools

private synchronized NameValueMap getCachedAttributes(ObjectName objName, Set<String> attrNames)
    throws InstanceNotFoundException, ReflectionException, IOException {
  NameValueMap values = cachedValues.get(objName);
  if (values != null && values.keySet().containsAll(attrNames)) {
    return values;
  }
  attrNames = new TreeSet<String>(attrNames);
  Set<String> oldNames = cachedNames.get(objName);
  if (oldNames != null) {
    attrNames.addAll(oldNames);
  }
  values = new NameValueMap();
  final AttributeList attrs = conn.getAttributes(objName, attrNames.toArray(new String[attrNames.size()]));
  for (Attribute attr : attrs.asList()) {
    values.put(attr.getName(), attr.getValue());
  }
  cachedValues.put(objName, values);
  cachedNames.put(objName, attrNames);
  return values;
}

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

private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
  AnnotationAttributes attributes = AnnotationAttributes.fromMap(
      metadata.getAnnotationAttributes(CompatibleDubboComponentScan.class.getName()));
  String[] basePackages = attributes.getStringArray("basePackages");
  Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
  String[] value = attributes.getStringArray("value");
  // Appends value array attributes
  Set<String> packagesToScan = new LinkedHashSet<String>(Arrays.asList(value));
  packagesToScan.addAll(Arrays.asList(basePackages));
  for (Class<?> basePackageClass : basePackageClasses) {
    packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
  }
  if (packagesToScan.isEmpty()) {
    return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName()));
  }
  return packagesToScan;
}

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

/**
 * Validate that the specified bean name and aliases have not been used already
 * within the current level of beans element nesting.
 */
protected void checkNameUniqueness(String beanName, List<String> aliases, Element beanElement) {
  String foundName = null;
  if (StringUtils.hasText(beanName) && this.usedNames.contains(beanName)) {
    foundName = beanName;
  }
  if (foundName == null) {
    foundName = CollectionUtils.findFirstMatch(this.usedNames, aliases);
  }
  if (foundName != null) {
    error("Bean name '" + foundName + "' is already used in this <beans> element", beanElement);
  }
  this.usedNames.add(beanName);
  this.usedNames.addAll(aliases);
}

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

public static Map<GlobalStreamId, Grouping> eventLoggerInputs(StormTopology topology) {
  Map<GlobalStreamId, Grouping> inputs = new HashMap<GlobalStreamId, Grouping>();
  Set<String> allIds = new HashSet<String>();
  allIds.addAll(topology.get_bolts().keySet());
  allIds.addAll(topology.get_spouts().keySet());
  for (String id : allIds) {
    inputs.put(Utils.getGlobalStreamId(id, EVENTLOGGER_STREAM_ID),
          Thrift.prepareFieldsGrouping(Arrays.asList("component-id")));
  }
  return inputs;
}

代码示例来源:origin: MovingBlocks/Terasology

private Set<EventHandlerInfo> selectEventHandlers(Class<? extends Event> eventType, EntityRef entity) {
  Set<EventHandlerInfo> result = Sets.newHashSet();
  result.addAll(generalHandlers.get(eventType));
  SetMultimap<Class<? extends Component>, EventHandlerInfo> handlers = componentSpecificHandlers.get(eventType);
  if (handlers == null) {
    return result;
  }
  for (Class<? extends Component> compClass : handlers.keySet()) {
    if (entity.hasComponent(compClass)) {
      for (EventHandlerInfo eventHandler : handlers.get(compClass)) {
        if (eventHandler.isValidFor(entity)) {
          result.add(eventHandler);
        }
      }
    }
  }
  return result;
}

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

/** The format of the demonyms file is
 *     countryCityOrState ( TAB demonym )*
 *  Lines starting with # are ignored
 *  The file is cased but stored in in-memory data structures uncased.
 *  The results are:
 *  demonyms is a has from each country (etc.) to a set of demonymic Strings;
 *  adjectiveNation is a set of demonymic Strings;
 *  demonymSet has all country (etc.) names and all demonymic Strings.
 */
private void loadDemonymLists(String demonymFile) {
 try (BufferedReader reader = IOUtils.readerFromString(demonymFile)) {
  for (String line; (line = reader.readLine()) != null; ) {
   line = line.toLowerCase(Locale.ENGLISH);
   String[] tokens = line.split("\t");
   if (tokens[0].startsWith("#")) continue;
   Set<String> set = Generics.newHashSet();
   for (String s : tokens) {
    set.add(s);
    demonymSet.add(s);
   }
   demonyms.put(tokens[0], set);
  }
  adjectiveNation.addAll(demonymSet);
  adjectiveNation.removeAll(demonyms.keySet());
 } catch (IOException e) {
  throw new RuntimeIOException(e);
 }
}

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

public DestinationPatternsMessageCondition combine(DestinationPatternsMessageCondition other) {
  Set<String> result = new LinkedHashSet<>();
  if (!this.patterns.isEmpty() && !other.patterns.isEmpty()) {
    for (String pattern1 : this.patterns) {
      for (String pattern2 : other.patterns) {
        result.add(this.pathMatcher.combine(pattern1, pattern2));
  else if (!this.patterns.isEmpty()) {
    result.addAll(this.patterns);
  else if (!other.patterns.isEmpty()) {
    result.addAll(other.patterns);
    result.add("");

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

@Override
 TypeVariable<?> captureAsTypeVariable(Type[] upperBounds) {
  Set<Type> combined = new LinkedHashSet<>(asList(upperBounds));
  // Since this is an artifically generated type variable, we don't bother checking
  // subtyping between declared type bound and actual type bound. So it's possible that we
  // may generate something like <capture#1-of ? extends Foo&SubFoo>.
  // Checking subtype between declared and actual type bounds
  // adds recursive isSubtypeOf() call and feels complicated.
  // There is no contract one way or another as long as isSubtypeOf() works as expected.
  combined.addAll(asList(typeParam.getBounds()));
  if (combined.size() > 1) { // Object is implicit and only useful if it's the only bound.
   combined.remove(Object.class);
  }
  return super.captureAsTypeVariable(combined.toArray(new Type[0]));
 }
};

相关文章