本文整理了Java中java.util.Collection.addAll()
方法的一些代码示例,展示了Collection.addAll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collection.addAll()
方法的具体详情如下:
包路径:java.util.Collection
类名称: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
protected void addSizedFiles(Collection<File> files)
{
if (files == null || files.isEmpty()) {
return;
}
long size = 0L;
for (File file : files) {
size += file.length();
}
this.files.addAll(files);
this.size += size;
}
代码示例来源:origin: hibernate/hibernate-orm
protected void addQuerySpaces(Serializable... spaces) {
if ( spaces != null ) {
if ( querySpaces == null ) {
querySpaces = new ArrayList<>();
}
querySpaces.addAll( Arrays.asList( (String[]) spaces ) );
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the cache operation(s) for the given {@link CacheOperationProvider}.
* <p>This implementation delegates to configured
* {@link CacheAnnotationParser CacheAnnotationParsers}
* for parsing known annotations into Spring's metadata attribute class.
* <p>Can be overridden to support custom annotations that carry caching metadata.
* @param provider the cache operation provider to use
* @return the configured caching operations, or {@code null} if none found
*/
@Nullable
protected Collection<CacheOperation> determineCacheOperations(CacheOperationProvider provider) {
Collection<CacheOperation> ops = null;
for (CacheAnnotationParser annotationParser : this.annotationParsers) {
Collection<CacheOperation> annOps = provider.getCacheOperations(annotationParser);
if (annOps != null) {
if (ops == null) {
ops = annOps;
}
else {
Collection<CacheOperation> combined = new ArrayList<>(ops.size() + annOps.size());
combined.addAll(ops);
combined.addAll(annOps);
ops = combined;
}
}
}
return ops;
}
代码示例来源:origin: Sable/soot
private void replaceConstraints(Collection constraints, TypeDecl before, TypeDecl after) {
Collection newConstraints = new ArrayList();
for(Iterator i2 = constraints.iterator(); i2.hasNext(); ) {
TypeDecl U = (TypeDecl)i2.next();
if(U == before) { // TODO: fix parameterized type
i2.remove();
newConstraints.add(after);
}
}
constraints.addAll(newConstraints);
}
代码示例来源:origin: apache/ignite
assert set.size() == 1;
assert set.addAll(c);
assert !set.addAll(c);
assert set.size() == 1 + c.size();
assert set.isEmpty();
Collection<Integer> c1 = Arrays.asList(1, 3, 5, 7, 9);
assert set.size() == cnt;
assert set.size() == set.toArray().length;
assert set.addAll(c1);
assert set.size() == c2.size();
set.clear();
assert set.isEmpty();
set.iterator().next();
set.add(null);
代码示例来源:origin: apache/geode
@Test
public void queryOnlyWhenIndexIsAvailable() throws Exception {
setUpMockBucket(0);
setUpMockBucket(1);
when(indexForPR.isIndexAvailable(0)).thenReturn(true);
when(indexForPR.isIndexAvailable(1)).thenReturn(true);
Set<Integer> buckets = new LinkedHashSet<>(Arrays.asList(0, 1));
InternalRegionFunctionContext ctx = Mockito.mock(InternalRegionFunctionContext.class);
when(ctx.getLocalBucketSet((any()))).thenReturn(buckets);
await().until(() -> {
final Collection<IndexRepository> repositories = new HashSet<>();
try {
repositories.addAll(repoManager.getRepositories(ctx));
} catch (BucketNotFoundException | LuceneIndexCreationInProgressException e) {
}
return repositories.size() == 2;
});
Iterator<IndexRepository> itr = repoManager.getRepositories(ctx).iterator();
IndexRepositoryImpl repo0 = (IndexRepositoryImpl) itr.next();
IndexRepositoryImpl repo1 = (IndexRepositoryImpl) itr.next();
assertNotNull(repo0);
assertNotNull(repo1);
assertNotEquals(repo0, repo1);
checkRepository(repo0, 0, 1);
checkRepository(repo1, 0, 1);
}
代码示例来源:origin: commons-collections/commons-collections
resetFull();
try {
Iterator iter = collection.iterator();
Object o = getOtherElements()[0];
collection.add(o);
confirmed.add(o);
iter.next();
fail("next after add should raise ConcurrentModification");
} catch (ConcurrentModificationException e) {
Iterator iter = collection.iterator();
collection.addAll(Arrays.asList(getOtherElements()));
confirmed.addAll(Arrays.asList(getOtherElements()));
iter.next();
fail("next after addAll should raise ConcurrentModification");
} catch (ConcurrentModificationException e) {
Iterator iter = collection.iterator();
collection.clear();
iter.next();
fail("next after clear should raise ConcurrentModification");
} catch (ConcurrentModificationException e) {
try {
Iterator iter = collection.iterator();
List sublist = Arrays.asList(getFullElements()).subList(2,5);
collection.removeAll(sublist);
iter.next();
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public Collection<String> doSharding(final Collection<String> availableTargetNames, final Collection<ShardingValue> shardingValues) {
Collection<String> shardingResult = shardingAlgorithm.doSharding(availableTargetNames, shardingValues.iterator().next());
Collection<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
result.addAll(shardingResult);
return result;
}
}
代码示例来源:origin: kiegroup/jbpm
public Collection<NodeInstance> getNodeInstances(boolean recursive) {
Collection<NodeInstance> result = nodeInstances;
if (recursive) {
result = new ArrayList<NodeInstance>(result);
for (Iterator<NodeInstance> iterator = nodeInstances.iterator(); iterator.hasNext(); ) {
NodeInstance nodeInstance = iterator.next();
if (nodeInstance instanceof NodeInstanceContainer) {
result.addAll(((NodeInstanceContainer)
nodeInstance).getNodeInstances(true));
}
}
}
return Collections.unmodifiableCollection(result);
}
代码示例来源:origin: org.apache.lucene/lucene-core
BooleanClause c = cIter.next();
ScorerSupplier subScorer = w.scorerSupplier(context);
if (subScorer == null) {
scorers.get(c.getOccur()).add(subScorer);
if (scorers.get(Occur.SHOULD).size() == minShouldMatch) {
scorers.get(Occur.MUST).addAll(scorers.get(Occur.SHOULD));
scorers.get(Occur.SHOULD).clear();
minShouldMatch = 0;
if (scorers.get(Occur.FILTER).isEmpty() && scorers.get(Occur.MUST).isEmpty() && scorers.get(Occur.SHOULD).isEmpty()) {
} else if (scorers.get(Occur.SHOULD).size() < minShouldMatch) {
if (!needsScores && minShouldMatch == 0 && scorers.get(Occur.MUST).size() + scorers.get(Occur.FILTER).size() > 0) {
scorers.get(Occur.SHOULD).clear();
代码示例来源:origin: google/guava
@CanIgnoreReturnValue
@Override
public boolean putAll(@Nullable K key, Iterable<? extends V> values) {
checkNotNull(values);
// make sure we only call values.iterator() once
// and we only call get(key) if values is nonempty
if (values instanceof Collection) {
Collection<? extends V> valueCollection = (Collection<? extends V>) values;
return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
} else {
Iterator<? extends V> valueItr = values.iterator();
return valueItr.hasNext() && Iterators.addAll(get(key), valueItr);
}
}
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Parse insert values.
*
* @param insertStatement insert statement
*/
public void parse(final InsertStatement insertStatement) {
Collection<Keyword> valueKeywords = new LinkedList<>();
valueKeywords.add(DefaultKeyword.VALUES);
valueKeywords.addAll(Arrays.asList(getSynonymousKeywordsForValues()));
if (lexerEngine.skipIfEqual(valueKeywords.toArray(new Keyword[valueKeywords.size()]))) {
parseValues(insertStatement);
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public GridClientData pinNodes(GridClientNode node, GridClientNode... nodes) throws GridClientException {
Collection<GridClientNode> pinnedNodes = new ArrayList<>(nodes != null ? nodes.length + 1 : 1);
if (node != null)
pinnedNodes.add(node);
if (nodes != null && nodes.length != 0)
pinnedNodes.addAll(Arrays.asList(nodes));
return createProjection(pinnedNodes.isEmpty() ? null : pinnedNodes,
null, null, new GridClientDataFactory(flags));
}
代码示例来源:origin: apache/incubator-dubbo
Collection collection = (Collection) value;
if (type.isArray()) {
int length = collection.size();
Object array = Array.newInstance(type.getComponentType(), length);
int i = 0;
try {
Collection result = (Collection) type.newInstance();
result.addAll(collection);
return result;
} catch (Throwable e) {
collection.add(Array.get(value, i));
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Parse select rest.
*/
public final void parse() {
Collection<Keyword> unsupportedRestKeywords = new LinkedList<>();
unsupportedRestKeywords.addAll(Arrays.asList(DefaultKeyword.UNION, DefaultKeyword.INTERSECT, DefaultKeyword.EXCEPT, DefaultKeyword.MINUS));
unsupportedRestKeywords.addAll(Arrays.asList(getUnsupportedKeywordsRest()));
lexerEngine.unsupportedIfEqual(unsupportedRestKeywords.toArray(new Keyword[unsupportedRestKeywords.size()]));
}
代码示例来源:origin: neo4j/neo4j
ControllableStep( String name, LongAdder progress, Configuration config, StatsProvider... additionalStatsProviders )
{
this.name = name;
this.progress = progress;
this.batchSize = config.batchSize(); // just to be able to report correctly
statsProviders.add( this );
statsProviders.addAll( Arrays.asList( additionalStatsProviders ) );
}
代码示例来源:origin: stagemonitor/stagemonitor
private static void initIncludesAndExcludes() {
CorePlugin corePlugin = Stagemonitor.getPlugin(CorePlugin.class);
excludeContaining = new ArrayList<String>(corePlugin.getExcludeContaining().size());
excludeContaining.addAll(corePlugin.getExcludeContaining());
excludes = new ArrayList<String>(corePlugin.getExcludePackages().size());
excludes.add("org.stagemonitor");
excludes.addAll(corePlugin.getExcludePackages());
includes = new ArrayList<String>(corePlugin.getIncludePackages().size());
includes.addAll(corePlugin.getIncludePackages());
if (includes.isEmpty()) {
logger.warn("No includes for instrumentation configured. Please set the stagemonitor.instrument.include property.");
}
}
代码示例来源:origin: stackoverflow.com
private List<File> getListFiles2(File parentDir) {
List<File> inFiles = new ArrayList<>();
Queue<File> files = new LinkedList<>();
files.addAll(Arrays.asList(parentDir.listFiles()));
while (!files.isEmpty()) {
File file = files.remove();
if (file.isDirectory()) {
files.addAll(Arrays.asList(file.listFiles()));
} else if (file.getName().endsWith(".csv")) {
inFiles.add(file);
}
}
return inFiles;
}
代码示例来源:origin: spring-projects/spring-security
retainList = new ArrayList(collection.size());
logger.debug("Filtering collection with " + collection.size()
+ " elements");
collection.clear();
collection.addAll(retainList);
rootObject.getAuthentication(), Arrays.asList(array));
代码示例来源:origin: Bilibili/DanmakuFlameMaster
public void setItems(Collection<BaseDanmaku> items) {
if (mDuplicateMergingEnabled && mSortType != ST_BY_LIST) {
synchronized (this.mLockObject) {
this.items.clear();
this.items.addAll(items);
items = this.items;
}
} else {
this.items = items;
}
if (items instanceof List) {
mSortType = ST_BY_LIST;
}
mSize.set(items == null ? 0 : items.size());
}
内容来源于网络,如有侵权,请联系作者删除!