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; }
private static <T> Set<T> getProviderClasses(final Collection<ServiceHolder<T>> providers) { return providers.stream() .map(Providers::holder2service) .collect(Collectors.toCollection(LinkedHashSet::new)); }
/** * 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<>(); }
/** * 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)); }
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(); }
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)); }
private static <T> Set<T> getProviderClasses(final Collection<ServiceHolder<T>> providers) { return providers.stream() .map(Providers::holder2service) .collect(Collectors.toCollection(LinkedHashSet::new)); }
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)); } }
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(); }
@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)); }
private static Set<String> fieldsToName(Set<Field> fields) { return fields.stream().map(Field::getName).collect(toCollection(LinkedHashSet::new)); }
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" ); }
/** * 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)); }
public static <T> T kthStream(final List<T> list, final int k) { return list.stream().limit(k + 1).collect(Collectors.toCollection(LinkedList::new)).getLast(); }
/** * 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)); }
@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); }
private static Set<String> getRootQualifiers(ResourceTypes resourceTypes) { return resourceTypes.getRoots().stream() .map(ResourceType::getQualifier) .collect(Collectors.toCollection(TreeSet::new)); }
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)); }
/** * 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); }
/** * 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)); }