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

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

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

Collection.addAll介绍

[英]Attempts to add all of the objects contained in Collectionto the contents of this Collection (optional). If the passed Collectionis changed during the process of adding elements to this Collection, the behavior is not defined.
[中]尝试将Collection中包含的所有对象添加到此集合的内容(可选)。如果在向该集合添加元素的过程中更改了传递的集合,则不会定义该行为。

代码示例

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

  1. protected void addSizedFiles(Collection<File> files)
  2. {
  3. if (files == null || files.isEmpty()) {
  4. return;
  5. }
  6. long size = 0L;
  7. for (File file : files) {
  8. size += file.length();
  9. }
  10. this.files.addAll(files);
  11. this.size += size;
  12. }

代码示例来源:origin: hibernate/hibernate-orm

  1. protected void addQuerySpaces(Serializable... spaces) {
  2. if ( spaces != null ) {
  3. if ( querySpaces == null ) {
  4. querySpaces = new ArrayList<>();
  5. }
  6. querySpaces.addAll( Arrays.asList( (String[]) spaces ) );
  7. }
  8. }

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

  1. /**
  2. * Determine the cache operation(s) for the given {@link CacheOperationProvider}.
  3. * <p>This implementation delegates to configured
  4. * {@link CacheAnnotationParser CacheAnnotationParsers}
  5. * for parsing known annotations into Spring's metadata attribute class.
  6. * <p>Can be overridden to support custom annotations that carry caching metadata.
  7. * @param provider the cache operation provider to use
  8. * @return the configured caching operations, or {@code null} if none found
  9. */
  10. @Nullable
  11. protected Collection<CacheOperation> determineCacheOperations(CacheOperationProvider provider) {
  12. Collection<CacheOperation> ops = null;
  13. for (CacheAnnotationParser annotationParser : this.annotationParsers) {
  14. Collection<CacheOperation> annOps = provider.getCacheOperations(annotationParser);
  15. if (annOps != null) {
  16. if (ops == null) {
  17. ops = annOps;
  18. }
  19. else {
  20. Collection<CacheOperation> combined = new ArrayList<>(ops.size() + annOps.size());
  21. combined.addAll(ops);
  22. combined.addAll(annOps);
  23. ops = combined;
  24. }
  25. }
  26. }
  27. return ops;
  28. }

代码示例来源:origin: Sable/soot

  1. private void replaceConstraints(Collection constraints, TypeDecl before, TypeDecl after) {
  2. Collection newConstraints = new ArrayList();
  3. for(Iterator i2 = constraints.iterator(); i2.hasNext(); ) {
  4. TypeDecl U = (TypeDecl)i2.next();
  5. if(U == before) { // TODO: fix parameterized type
  6. i2.remove();
  7. newConstraints.add(after);
  8. }
  9. }
  10. constraints.addAll(newConstraints);
  11. }

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

  1. assert set.size() == 1;
  2. assert set.addAll(c);
  3. assert !set.addAll(c);
  4. assert set.size() == 1 + c.size();
  5. assert set.isEmpty();
  6. Collection<Integer> c1 = Arrays.asList(1, 3, 5, 7, 9);
  7. assert set.size() == cnt;
  8. assert set.size() == set.toArray().length;
  9. assert set.addAll(c1);
  10. assert set.size() == c2.size();
  11. set.clear();
  12. assert set.isEmpty();
  13. set.iterator().next();
  14. set.add(null);

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

  1. @Test
  2. public void queryOnlyWhenIndexIsAvailable() throws Exception {
  3. setUpMockBucket(0);
  4. setUpMockBucket(1);
  5. when(indexForPR.isIndexAvailable(0)).thenReturn(true);
  6. when(indexForPR.isIndexAvailable(1)).thenReturn(true);
  7. Set<Integer> buckets = new LinkedHashSet<>(Arrays.asList(0, 1));
  8. InternalRegionFunctionContext ctx = Mockito.mock(InternalRegionFunctionContext.class);
  9. when(ctx.getLocalBucketSet((any()))).thenReturn(buckets);
  10. await().until(() -> {
  11. final Collection<IndexRepository> repositories = new HashSet<>();
  12. try {
  13. repositories.addAll(repoManager.getRepositories(ctx));
  14. } catch (BucketNotFoundException | LuceneIndexCreationInProgressException e) {
  15. }
  16. return repositories.size() == 2;
  17. });
  18. Iterator<IndexRepository> itr = repoManager.getRepositories(ctx).iterator();
  19. IndexRepositoryImpl repo0 = (IndexRepositoryImpl) itr.next();
  20. IndexRepositoryImpl repo1 = (IndexRepositoryImpl) itr.next();
  21. assertNotNull(repo0);
  22. assertNotNull(repo1);
  23. assertNotEquals(repo0, repo1);
  24. checkRepository(repo0, 0, 1);
  25. checkRepository(repo1, 0, 1);
  26. }

代码示例来源:origin: commons-collections/commons-collections

  1. resetFull();
  2. try {
  3. Iterator iter = collection.iterator();
  4. Object o = getOtherElements()[0];
  5. collection.add(o);
  6. confirmed.add(o);
  7. iter.next();
  8. fail("next after add should raise ConcurrentModification");
  9. } catch (ConcurrentModificationException e) {
  10. Iterator iter = collection.iterator();
  11. collection.addAll(Arrays.asList(getOtherElements()));
  12. confirmed.addAll(Arrays.asList(getOtherElements()));
  13. iter.next();
  14. fail("next after addAll should raise ConcurrentModification");
  15. } catch (ConcurrentModificationException e) {
  16. Iterator iter = collection.iterator();
  17. collection.clear();
  18. iter.next();
  19. fail("next after clear should raise ConcurrentModification");
  20. } catch (ConcurrentModificationException e) {
  21. try {
  22. Iterator iter = collection.iterator();
  23. List sublist = Arrays.asList(getFullElements()).subList(2,5);
  24. collection.removeAll(sublist);
  25. iter.next();

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

  1. @Override
  2. public Collection<String> doSharding(final Collection<String> availableTargetNames, final Collection<ShardingValue> shardingValues) {
  3. Collection<String> shardingResult = shardingAlgorithm.doSharding(availableTargetNames, shardingValues.iterator().next());
  4. Collection<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
  5. result.addAll(shardingResult);
  6. return result;
  7. }
  8. }

代码示例来源:origin: kiegroup/jbpm

  1. public Collection<NodeInstance> getNodeInstances(boolean recursive) {
  2. Collection<NodeInstance> result = nodeInstances;
  3. if (recursive) {
  4. result = new ArrayList<NodeInstance>(result);
  5. for (Iterator<NodeInstance> iterator = nodeInstances.iterator(); iterator.hasNext(); ) {
  6. NodeInstance nodeInstance = iterator.next();
  7. if (nodeInstance instanceof NodeInstanceContainer) {
  8. result.addAll(((NodeInstanceContainer)
  9. nodeInstance).getNodeInstances(true));
  10. }
  11. }
  12. }
  13. return Collections.unmodifiableCollection(result);
  14. }

代码示例来源:origin: org.apache.lucene/lucene-core

  1. BooleanClause c = cIter.next();
  2. ScorerSupplier subScorer = w.scorerSupplier(context);
  3. if (subScorer == null) {
  4. scorers.get(c.getOccur()).add(subScorer);
  5. if (scorers.get(Occur.SHOULD).size() == minShouldMatch) {
  6. scorers.get(Occur.MUST).addAll(scorers.get(Occur.SHOULD));
  7. scorers.get(Occur.SHOULD).clear();
  8. minShouldMatch = 0;
  9. if (scorers.get(Occur.FILTER).isEmpty() && scorers.get(Occur.MUST).isEmpty() && scorers.get(Occur.SHOULD).isEmpty()) {
  10. } else if (scorers.get(Occur.SHOULD).size() < minShouldMatch) {
  11. if (!needsScores && minShouldMatch == 0 && scorers.get(Occur.MUST).size() + scorers.get(Occur.FILTER).size() > 0) {
  12. scorers.get(Occur.SHOULD).clear();

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

  1. @CanIgnoreReturnValue
  2. @Override
  3. public boolean putAll(@Nullable K key, Iterable<? extends V> values) {
  4. checkNotNull(values);
  5. // make sure we only call values.iterator() once
  6. // and we only call get(key) if values is nonempty
  7. if (values instanceof Collection) {
  8. Collection<? extends V> valueCollection = (Collection<? extends V>) values;
  9. return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
  10. } else {
  11. Iterator<? extends V> valueItr = values.iterator();
  12. return valueItr.hasNext() && Iterators.addAll(get(key), valueItr);
  13. }
  14. }

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

  1. /**
  2. * Parse insert values.
  3. *
  4. * @param insertStatement insert statement
  5. */
  6. public void parse(final InsertStatement insertStatement) {
  7. Collection<Keyword> valueKeywords = new LinkedList<>();
  8. valueKeywords.add(DefaultKeyword.VALUES);
  9. valueKeywords.addAll(Arrays.asList(getSynonymousKeywordsForValues()));
  10. if (lexerEngine.skipIfEqual(valueKeywords.toArray(new Keyword[valueKeywords.size()]))) {
  11. parseValues(insertStatement);
  12. }
  13. }

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

  1. /** {@inheritDoc} */
  2. @Override public GridClientData pinNodes(GridClientNode node, GridClientNode... nodes) throws GridClientException {
  3. Collection<GridClientNode> pinnedNodes = new ArrayList<>(nodes != null ? nodes.length + 1 : 1);
  4. if (node != null)
  5. pinnedNodes.add(node);
  6. if (nodes != null && nodes.length != 0)
  7. pinnedNodes.addAll(Arrays.asList(nodes));
  8. return createProjection(pinnedNodes.isEmpty() ? null : pinnedNodes,
  9. null, null, new GridClientDataFactory(flags));
  10. }

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

  1. Collection collection = (Collection) value;
  2. if (type.isArray()) {
  3. int length = collection.size();
  4. Object array = Array.newInstance(type.getComponentType(), length);
  5. int i = 0;
  6. try {
  7. Collection result = (Collection) type.newInstance();
  8. result.addAll(collection);
  9. return result;
  10. } catch (Throwable e) {
  11. collection.add(Array.get(value, i));

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

  1. /**
  2. * Parse select rest.
  3. */
  4. public final void parse() {
  5. Collection<Keyword> unsupportedRestKeywords = new LinkedList<>();
  6. unsupportedRestKeywords.addAll(Arrays.asList(DefaultKeyword.UNION, DefaultKeyword.INTERSECT, DefaultKeyword.EXCEPT, DefaultKeyword.MINUS));
  7. unsupportedRestKeywords.addAll(Arrays.asList(getUnsupportedKeywordsRest()));
  8. lexerEngine.unsupportedIfEqual(unsupportedRestKeywords.toArray(new Keyword[unsupportedRestKeywords.size()]));
  9. }

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

  1. ControllableStep( String name, LongAdder progress, Configuration config, StatsProvider... additionalStatsProviders )
  2. {
  3. this.name = name;
  4. this.progress = progress;
  5. this.batchSize = config.batchSize(); // just to be able to report correctly
  6. statsProviders.add( this );
  7. statsProviders.addAll( Arrays.asList( additionalStatsProviders ) );
  8. }

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

  1. private static void initIncludesAndExcludes() {
  2. CorePlugin corePlugin = Stagemonitor.getPlugin(CorePlugin.class);
  3. excludeContaining = new ArrayList<String>(corePlugin.getExcludeContaining().size());
  4. excludeContaining.addAll(corePlugin.getExcludeContaining());
  5. excludes = new ArrayList<String>(corePlugin.getExcludePackages().size());
  6. excludes.add("org.stagemonitor");
  7. excludes.addAll(corePlugin.getExcludePackages());
  8. includes = new ArrayList<String>(corePlugin.getIncludePackages().size());
  9. includes.addAll(corePlugin.getIncludePackages());
  10. if (includes.isEmpty()) {
  11. logger.warn("No includes for instrumentation configured. Please set the stagemonitor.instrument.include property.");
  12. }
  13. }

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

  1. private List<File> getListFiles2(File parentDir) {
  2. List<File> inFiles = new ArrayList<>();
  3. Queue<File> files = new LinkedList<>();
  4. files.addAll(Arrays.asList(parentDir.listFiles()));
  5. while (!files.isEmpty()) {
  6. File file = files.remove();
  7. if (file.isDirectory()) {
  8. files.addAll(Arrays.asList(file.listFiles()));
  9. } else if (file.getName().endsWith(".csv")) {
  10. inFiles.add(file);
  11. }
  12. }
  13. return inFiles;
  14. }

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

  1. retainList = new ArrayList(collection.size());
  2. logger.debug("Filtering collection with " + collection.size()
  3. + " elements");
  4. collection.clear();
  5. collection.addAll(retainList);
  6. rootObject.getAuthentication(), Arrays.asList(array));

代码示例来源:origin: Bilibili/DanmakuFlameMaster

  1. public void setItems(Collection<BaseDanmaku> items) {
  2. if (mDuplicateMergingEnabled && mSortType != ST_BY_LIST) {
  3. synchronized (this.mLockObject) {
  4. this.items.clear();
  5. this.items.addAll(items);
  6. items = this.items;
  7. }
  8. } else {
  9. this.items = items;
  10. }
  11. if (items instanceof List) {
  12. mSortType = ST_BY_LIST;
  13. }
  14. mSize.set(items == null ? 0 : items.size());
  15. }

相关文章