本文整理了Java中java.util.stream.Collectors.toCollection()
方法的一些代码示例,展示了Collectors.toCollection()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collectors.toCollection()
方法的具体详情如下:
包路径:java.util.stream.Collectors
类名称:Collectors
方法名:toCollection
暂无
代码示例来源:origin: ctripcorp/apollo
public static List<OpenNamespaceDTO> batchTransformFromNamespaceBOs(List<NamespaceBO>
namespaceBOs) {
if (CollectionUtils.isEmpty(namespaceBOs)) {
return Collections.emptyList();
}
List<OpenNamespaceDTO> openNamespaceDTOs =
namespaceBOs.stream().map(OpenApiBeanUtils::transformFromNamespaceBO)
.collect(Collectors.toCollection(LinkedList::new));
return openNamespaceDTOs;
}
代码示例来源:origin: jersey/jersey
private static <T> Set<T> getProviderClasses(final Collection<ServiceHolder<T>> providers) {
return providers.stream()
.map(Providers::holder2service)
.collect(Collectors.toCollection(LinkedHashSet::new));
}
代码示例来源:origin: apache/storm
/**
* Return a set of all worker directories in root log directory.
*/
public Set<File> getAllWorkerDirs() {
File[] rootDirFiles = logRootDir.listFiles();
if (rootDirFiles != null) {
return Arrays.stream(rootDirFiles).flatMap(topoDir -> {
File[] topoFiles = topoDir.listFiles();
return topoFiles != null ? Arrays.stream(topoFiles) : Stream.empty();
}).collect(toCollection(TreeSet::new));
}
return new TreeSet<>();
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Returns the declared fields of a given class excluding any synthetic or static fields.
*
* Synthetic fields are fields that are generated by the compiler for access purposes, or by instrumentation tools e.g. JaCoCo adds in a $jacocoData field
* and therefore should be ignored when comparing fields.
*
* Static fields are used as constants, and are not associated with an object.
*
* @param clazz the class we want the declared fields.
* @return the declared fields of given class excluding any synthetic fields.
*/
private static Set<Field> getDeclaredFieldsIgnoringSyntheticAndStatic(Class<?> clazz) {
return stream(clazz.getDeclaredFields()).filter(field -> !(field.isSynthetic()
|| Modifier.isStatic(field.getModifiers())))
.collect(toCollection(LinkedHashSet::new));
}
代码示例来源:origin: spring-projects/spring-loaded
public static int run() {
List<Integer> integers = Arrays.asList(1, 2, 3);
List<Integer> collected = integers.stream().collect(Collectors.toCollection(ArrayList::new));
return collected.size();
}
代码示例来源:origin: Graylog2/graylog2-server
private static ReferenceList toReferenceList(Collection<Object> list) {
// TODO: Support nested objects in list
return list.stream()
.map(ValueReference::of)
.filter(Objects::nonNull)
.collect(Collectors.toCollection(ReferenceList::new));
}
代码示例来源:origin: jersey/jersey
private static <T> Set<T> getProviderClasses(final Collection<ServiceHolder<T>> providers) {
return providers.stream()
.map(Providers::holder2service)
.collect(Collectors.toCollection(LinkedHashSet::new));
}
代码示例来源:origin: gocd/gocd
public RolesConfig ofType(String pluginType) throws InvalidPluginTypeException {
if (isBlank(pluginType)) {
return this;
}
Class<? extends Role> roleClass = ROLE_FILTER_MAP.get(pluginType);
if (roleClass == null) {
throw new InvalidPluginTypeException("Bad role type `" + pluginType + "`. Valid values are " + StringUtils.join(ROLE_FILTER_MAP.keySet(), ", "));
}
return this.stream().filter(role -> role.getClass().isAssignableFrom(roleClass)).collect(Collectors.toCollection(RolesConfig::new));
}
}
代码示例来源:origin: spring-projects/spring-loaded
public static int run() {
List<Integer> integers = Arrays.asList(1, 2, 3, 4);
List<Integer> collected = integers.stream().collect(Collectors.toCollection(ArrayList::new));
return collected.size();
}
代码示例来源:origin: apache/storm
@VisibleForTesting
Set<File> selectDirsForCleanup(long nowMillis) {
FileFilter fileFilter = mkFileFilterForLogCleanup(nowMillis);
return Arrays.stream(logRootDir.listFiles())
.flatMap(topoDir -> Arrays.stream(topoDir.listFiles(fileFilter)))
.collect(toCollection(TreeSet::new));
}
代码示例来源:origin: org.assertj/assertj-core
private static Set<String> fieldsToName(Set<Field> fields) {
return fields.stream().map(Field::getName).collect(toCollection(LinkedHashSet::new));
}
代码示例来源:origin: apache/incubator-druid
SegmentsCostCache(ArrayList<Bucket> sortedBuckets)
{
this.sortedBuckets = Preconditions.checkNotNull(sortedBuckets, "buckets should not be null");
this.intervals = sortedBuckets.stream().map(Bucket::getInterval).collect(Collectors.toCollection(ArrayList::new));
Preconditions.checkArgument(
BUCKET_ORDERING.isOrdered(sortedBuckets),
"buckets must be ordered by interval"
);
}
代码示例来源:origin: joel-costigliola/assertj-core
/**
* Returns the declared fields of a given class excluding any synthetic or static fields.
*
* Synthetic fields are fields that are generated by the compiler for access purposes, or by instrumentation tools e.g. JaCoCo adds in a $jacocoData field
* and therefore should be ignored when comparing fields.
*
* Static fields are used as constants, and are not associated with an object.
*
* @param clazz the class we want the declared fields.
* @return the declared fields of given class excluding any synthetic fields.
*/
private static Set<Field> getDeclaredFieldsIgnoringSyntheticAndStatic(Class<?> clazz) {
return stream(clazz.getDeclaredFields()).filter(field -> !(field.isSynthetic()
|| Modifier.isStatic(field.getModifiers())))
.collect(toCollection(LinkedHashSet::new));
}
代码示例来源:origin: shekhargulati/99-problems
public static <T> T kthStream(final List<T> list, final int k) {
return list.stream().limit(k + 1).collect(Collectors.toCollection(LinkedList::new)).getLast();
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Creates a <em>mutable</em> {@link ArrayList} containing the given elements.
*
* @param <T> the generic type of the {@code ArrayList} to create.
* @param elements the elements to store in the {@code ArrayList}.
* @return the created {@code ArrayList}, or {@code null} if the given {@code Iterator} is {@code null}.
*/
public static <T> ArrayList<T> newArrayList(Iterator<? extends T> elements) {
if (elements == null) {
return null;
}
return Streams.stream(elements).collect(toCollection(ArrayList::new));
}
代码示例来源:origin: prestodb/presto
@VisibleForTesting
JoinEnumerationResult createJoinAccordingToPartitioning(LinkedHashSet<PlanNode> sources, List<Symbol> outputSymbols, Set<Integer> partitioning)
{
List<PlanNode> sourceList = ImmutableList.copyOf(sources);
LinkedHashSet<PlanNode> leftSources = partitioning.stream()
.map(sourceList::get)
.collect(toCollection(LinkedHashSet::new));
LinkedHashSet<PlanNode> rightSources = sources.stream()
.filter(source -> !leftSources.contains(source))
.collect(toCollection(LinkedHashSet::new));
return createJoin(leftSources, rightSources, outputSymbols);
}
代码示例来源:origin: SonarSource/sonarqube
private static Set<String> getRootQualifiers(ResourceTypes resourceTypes) {
return resourceTypes.getRoots().stream()
.map(ResourceType::getQualifier)
.collect(Collectors.toCollection(TreeSet::new));
}
代码示例来源:origin: org.assertj/assertj-core
private void assertIterableContainsGivenValues(Iterable<?> actual, Object[] values, AssertionInfo info) {
Set<Object> notFound = stream(values).filter(value -> !iterableContains(actual, value))
.collect(toCollection(LinkedHashSet::new));
if (notFound.isEmpty())
return;
throw failures.failure(info, shouldContain(actual, values, notFound, comparisonStrategy));
}
代码示例来源:origin: org.springframework.boot/spring-boot
/**
* Return the classes from all the specified configurations in the order that they
* would be registered.
* @param configurations the source configuration
* @return configuration classes in registration order
*/
public static Class<?>[] getClasses(Collection<Configurations> configurations) {
List<Configurations> ordered = new ArrayList<>(configurations);
ordered.sort(COMPARATOR);
List<Configurations> collated = collate(ordered);
LinkedHashSet<Class<?>> classes = collated.stream()
.flatMap(Configurations::streamClasses)
.collect(Collectors.toCollection(LinkedHashSet::new));
return ClassUtils.toClassArray(classes);
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Creates a <em>mutable</em> {@code HashSet} containing the given elements.
*
* @param <T> the generic type of the {@code HashSet} to create.
* @param elements the elements to store in the {@code HashSet}.
* @return the created {@code HashSet}, or {@code null} if the given array of elements is {@code null}.
*/
public static <T> HashSet<T> newHashSet(Iterable<? extends T> elements) {
if (elements == null) {
return null;
}
return Streams.stream(elements).collect(toCollection(HashSet::new));
}
内容来源于网络,如有侵权,请联系作者删除!