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

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

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

Collections.addAll介绍

[英]Adds all the specified elements to the specified collection.
[中]将所有指定的元素添加到指定的集合。

代码示例

代码示例来源:origin: org.powermock/powermock-api-mockito

private void addOtherElementToBeReturned(List<Object> elements, Object[] toBeReturnedOthers) {
  if (toBeReturnedOthers == null) {
    elements.add(toBeReturnedOthers);
    return;
  }
  Collections.addAll(elements, toBeReturnedOthers);
}

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

@Override
public void addHeader(Header header) {
 List<Header> temp = new ArrayList<>();
 Collections.addAll(temp, headers);
 temp.add(header);
 headers = temp.toArray(new Header[temp.size()]);
}

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

String[] f(String[] first, String[] second) {
  List<String> both = new ArrayList<String>(first.length + second.length);
  Collections.addAll(both, first);
  Collections.addAll(both, second);
  return both.toArray(new String[both.size()]);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

private List<List<Double>> convertToListOfLists(final List<Double[]> points) {
  List<List<Double>> listOfLists = new ArrayList<List<Double>>(points.size());
  for (Double[] cur : points) {
    List<Double> list = new ArrayList<Double>(cur.length);
    Collections.addAll(list, cur);
    listOfLists.add(list);
  }
  return listOfLists;
}

代码示例来源:origin: org.codehaus.groovy/groovy

public Java8() {
  super();
  List<Class<?>> dgmClasses = new ArrayList<>();
  Collections.addAll(dgmClasses, (Class<?>[]) super.getPluginDefaultGroovyMethods());
  dgmClasses.add(PluginDefaultGroovyMethods.class);
  PLUGIN_DGM = dgmClasses.toArray(new Class<?>[0]);
}

代码示例来源:origin: k9mail/k-9

private static Address[] addressFromStringArray(List<String> addresses) {
  ArrayList<Address> result = new ArrayList<>(addresses.size());
  for (String addressStr : addresses) {
    Collections.addAll(result, Address.parseUnencoded(addressStr));
  }
  return result.toArray(new Address[result.size()]);
}

代码示例来源:origin: lets-blade/blade

public Ansi and(Ansi other) {
  List<String> both = new ArrayList<String>();
  Collections.addAll(both, codes);
  Collections.addAll(both, other.codes);
  return new Ansi(both.toArray(new String[]{}));
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Gets the current settings of KDtree.
 * 
 * @return an array of strings suitable for passing to setOptions
 */
@Override
public String[] getOptions() {
 Vector<String> result = new Vector<String>();
 result.add("-S");
 result.add(m_Splitter.getClass().getName());
 Collections.addAll(result, super.getOptions());
 return result.toArray(new String[result.size()]);
}

代码示例来源:origin: bluelinelabs/LoganSquare

protected Object[] expandStringArgs(Object... args) {
  List<Object> argList = new ArrayList<>();
  for (Object arg : args) {
    if (arg instanceof Object[]) {
      Collections.addAll(argList, (Object[])arg);
    } else {
      argList.add(arg);
    }
  }
  return argList.toArray(new Object[argList.size()]);
}

代码示例来源:origin: EngineHub/WorldEdit

newSequence.add(subInvokable);
    newSequence.add(invokable);
    Collections.addAll(newSequence, ((Sequence) invokable).sequence);
  } else {
    newSequence.add(invokable);
  newValueMap.put(caseValue, newSequence.size());
  Collections.addAll(newSequence, ((Sequence) invokable).sequence);
} else {
  newSequence.add(invokable);

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

/**
 * Returns all methods. Cached. Lazy.
 */
public MethodDescriptor[] getAllMethodDescriptors() {
  if (allMethods == null) {
    List<MethodDescriptor> allMethodsList = new ArrayList<>();
    for (MethodDescriptor[] methodDescriptors : methodsMap.values()) {
      Collections.addAll(allMethodsList, methodDescriptors);
    }
    MethodDescriptor[] allMethods = allMethodsList.toArray(new MethodDescriptor[allMethodsList.size()]);
    Arrays.sort(allMethods, new Comparator<MethodDescriptor>() {
      public int compare(MethodDescriptor md1, MethodDescriptor md2) {
        return md1.getMethod().getName().compareTo(md2.getMethod().getName());
      }
    });
    this.allMethods = allMethods;
  }
  return allMethods;
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Add default filters to apply to each request.
 *
 * @param filter            The filter to add
 * @param additionalFilters An optional array of additional filters to add
 */
public static void filters(Filter filter, Filter... additionalFilters) {
  Validate.notNull(filter, "Filter cannot be null");
  RestAssured.filters.add(filter);
  if (additionalFilters != null) {
    Collections.addAll(RestAssured.filters, additionalFilters);
  }
}

代码示例来源:origin: OryxProject/oryx

static Rescorer of(List<Rescorer> rescorers) {
 List<Rescorer> expandedRescorers = new ArrayList<>();
 for (Rescorer rescorer : rescorers) {
  // Assuming at most one level of nesting here
  if (rescorer instanceof MultiRescorer) {
   Collections.addAll(expandedRescorers, ((MultiRescorer) rescorer).getRescorers());
  } else {
   expandedRescorers.add(rescorer);
  }
 }
 return new MultiRescorer(expandedRescorers.toArray(EMPTY_RESCORER_ARRAY));
}

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

public ChainWALEntryFilter(List<WALEntryFilter> filters) {
 ArrayList<WALEntryFilter> rawFilters = new ArrayList<>(filters.size());
 // flatten the chains
 for (WALEntryFilter filter : filters) {
  if (filter instanceof ChainWALEntryFilter) {
   Collections.addAll(rawFilters, ((ChainWALEntryFilter) filter).filters);
  } else {
   rawFilters.add(filter);
  }
 }
 this.filters = rawFilters.toArray(new WALEntryFilter[rawFilters.size()]);
 initCellFilters();
}

代码示例来源:origin: lets-blade/blade

public Ansi and(Ansi other) {
  List<String> both = new ArrayList<String>();
  Collections.addAll(both, codes);
  Collections.addAll(both, other.codes);
  return new Ansi(both.toArray(new String[]{}));
}

代码示例来源:origin: nz.ac.waikato.cms.weka/multiInstanceLearning

/**
 * Gets the current settings of the classifier.
 * 
 * @return an array of strings suitable for passing to setOptions
 */
@Override
public String[] getOptions() {
 Vector<String> result = new Vector<String>();
 result.add("-N");
 result.add("" + m_filterType);
 Collections.addAll(result, super.getOptions());
 return result.toArray(new String[result.size()]);
}

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

private void setServicePackagePrefixes( String packages ) {
  List<String> packagePrefixes = new ArrayList<String>();
  Collections.addAll(packagePrefixes, package_prefixes);
  String[] prefixes = packages.split( ";" );
  for ( String prefix : prefixes ) {
    if ( !packagePrefixes.contains( prefix ) ) {
      packagePrefixes.add( prefix );
    }
  }
  package_prefixes = packagePrefixes.toArray( new String[packagePrefixes.size()] );
}

代码示例来源:origin: osmandapp/Osmand

String name = parser.getName();
if (name.equals("poi_category")) {
  lastCategory = new PoiCategory(this, parser.getAttributeValue("", "name"), categories.size());
  lastCategory.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top")));
  lastCategory.setNotEditableOsm("true".equals(parser.getAttributeValue("", "no_edit")));
  lastCategory.setDefaultTag(parser.getAttributeValue("", "default_tag"));
  if(!Algorithms.isEmpty(parser.getAttributeValue("", "poi_additional_category"))) {
    Collections.addAll(lastCategoryPoiAdditionalsCategories, parser.getAttributeValue("", "poi_additional_category").split(","));
    lastCategoryPoiAdditionalsCategories.removeAll(lastCategory.getExcludedPoiAdditionalCategories());
  categories.add(lastCategory);
} else if (name.equals("poi_filter")) {
  PoiFilter tp = new PoiFilter(this, lastCategory, parser.getAttributeValue("", "name"));
  lastFilterPoiAdditionalsCategories.addAll(lastCategoryPoiAdditionalsCategories);
  if(!Algorithms.isEmpty(parser.getAttributeValue("", "poi_additional_category"))) {
    Collections.addAll(lastFilterPoiAdditionalsCategories, parser.getAttributeValue("", "poi_additional_category").split(","));
      categoryPoiAdditionalMap.put(lastPoiAdditionalCategory, categoryAdditionals);
    categoryAdditionals.add(baseType);
    lastTypePoiAdditionalsCategories.addAll(lastFilterPoiAdditionalsCategories);
    if(!Algorithms.isEmpty(parser.getAttributeValue("", "poi_additional_category"))) {
      Collections.addAll(lastTypePoiAdditionalsCategories, parser.getAttributeValue("", "poi_additional_category").split(","));

代码示例来源:origin: jenkinsci/jenkins

public void setInstallations(MavenInstallation... installations) {
  List<MavenInstallation> tmpList = new ArrayList<Maven.MavenInstallation>();
  // remote empty Maven installation : 
  if(installations != null) {
    Collections.addAll(tmpList, installations);
    for(MavenInstallation installation : installations) {
      if(Util.fixEmptyAndTrim(installation.getName()) == null) {
        tmpList.remove(installation);
      }
    }
  }
  this.installations = tmpList.toArray(new MavenInstallation[tmpList.size()]);
  save();
}

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

/**
 * Create a composite logger that delegates to a primary or falls back on a
 * secondary logger if logging for the primary logger is not enabled.
 * <p>This may be used for fallback logging from lower level packages that
 * logically should log together with some higher level package but the two
 * don't happen to share a suitable parent package (e.g. logging for the web
 * and lower level http and codec packages). For such cases the primary,
 * class-based logger can be wrapped with a shared fallback logger.
 * @param primaryLogger primary logger to try first
 * @param secondaryLogger secondary logger
 * @param tertiaryLoggers optionally, more fallback loggers
 * @return the resulting logger to use
 */
public static Log getCompositeLog(Log primaryLogger, Log secondaryLogger, Log... tertiaryLoggers) {
  List<Log> loggers = new ArrayList<>(2 + tertiaryLoggers.length);
  loggers.add(primaryLogger);
  loggers.add(secondaryLogger);
  Collections.addAll(loggers, tertiaryLoggers);
  return new CompositeLog(loggers);
}

相关文章

Collections类方法