Example usage for java.util.stream Collectors toList

List of usage examples for java.util.stream Collectors toList

Introduction

In this page you can find the example usage for java.util.stream Collectors toList.

Prototype

public static <T> Collector<T, ?, List<T>> toList() 

Source Link

Document

Returns a Collector that accumulates the input elements into a new List .

Usage

From source file:com.u2apple.tool.filter.UnnormalDeviceFilter.java

@Override
public List<AndroidDeviceRanking> filter(List<AndroidDeviceRanking> androidDevices) {
    return androidDevices.stream().filter(
            device -> StringUtils.equalsIgnoreCase(device.getRoProductBrand(), device.getRoProductModel()))
            .collect(Collectors.toList());
}

From source file:delfos.rs.contentbased.vsm.booleanvsm.SparseVector.java

public static final <Key extends Comparable<Key>> SparseVector<Key> createFromPairs(
        Pair<Key, Double>... pairs) {

    SparseVector<Key> sparseVector = new SparseVector<>(
            Arrays.stream(pairs).map(entry -> entry.getKey()).collect(Collectors.toList()));
    Arrays.stream(pairs).forEach(pair -> sparseVector.map.put(pair.getKey(), pair.getValue()));

    return sparseVector;
}

From source file:Main.java

/**
 * Convert a sequence of elements to the list.
 *
 * @param <I> Type of objects for input collection
 * @param <O> Type of objects for output collection
 * @param iterable The sequence of elements to convert. If the input
 *     sequence is empty, then the resulting collection will be empty
 * @param transformer The conversion function. If the transfer function is
 *     not set, the resulting collection will be empty
 * @return Reformed collection of input elements
 *//*from  w  ww  . j  ava2  s  .  c om*/
public static <I, O> List<O> transformWithoutNull(final Iterable<I> iterable,
        final Function<I, O> transformer) {
    return StreamSupport
            .stream(Optional.ofNullable(iterable).orElse(Collections.<I>emptySet()).spliterator(), false)
            .map(Optional.ofNullable(transformer).orElse(i -> null)).filter(Objects::nonNull)
            .collect(Collectors.toList());
}

From source file:controllers.api.v2.Dataset.java

public static Promise<Result> listSegments(@Nullable String platform, @Nonnull String prefix) {
    try {/*from  w ww . ja  va2s  . c om*/
        if (StringUtils.isBlank(platform)) {
            return Promise.promise(() -> ok(Json.toJson(DATA_TYPES_DAO.getAllPlatforms().stream()
                    .map(s -> s.get("name")).collect(Collectors.toList()))));
        }

        List<String> names = DATASET_VIEW_DAO.listSegments(platform, "PROD",
                getPlatformPrefix(platform, prefix));

        // if prefix is a dataset name, then return empty list
        if (names.size() == 1 && names.get(0).equalsIgnoreCase(prefix)) {
            return Promise.promise(() -> ok(Json.toJson(Collections.emptyList())));
        }

        return Promise.promise(() -> ok(Json.toJson(names)));
    } catch (Exception e) {
        Logger.error("Fail to list dataset names/sections", e);
        return Promise.promise(() -> internalServerError("Fetch data Error: " + e.toString()));
    }
}

From source file:com.blackducksoftware.integration.hub.detect.detector.clang.CompileCommandsJsonFile.java

public static List<CompileCommand> parseJsonCompilationDatabaseFile(final Gson gson,
        final File compileCommandsJsonFile) throws IOException {
    final String compileCommandsJson = FileUtils.readFileToString(compileCommandsJsonFile,
            StandardCharsets.UTF_8);
    final CompileCommandJsonData[] compileCommands = gson.fromJson(compileCommandsJson,
            CompileCommandJsonData[].class);
    return Arrays.stream(compileCommands).map(rawCommand -> new CompileCommand(rawCommand))
            .collect(Collectors.toList());
}

From source file:acmi.l2.clientmod.l2_version_switcher.Util.java

public static List<FileInfo> getFileInfo(InputStream is) {
    return new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_16)).lines().map(FileInfo::parse)
            .collect(Collectors.toList());
}

From source file:com.thinkbiganalytics.datalake.authorization.service.HadoopAuthorizationService.java

public static List<String> convertNewlineDelimetedTextToList(String text) {
    List<String> result = new ArrayList<>();
    if (StringUtils.isNotEmpty(text)) {
        String listWithCommas = text.replace("\n", ",");
        result = Arrays.asList(listWithCommas.split(",")).stream().collect(Collectors.toList());
    }/*from w  ww .  ja  v  a 2 s  .c  o  m*/
    return result;
}

From source file:com.simiacryptus.mindseye.test.PCAUtil.java

/**
 * Forked from Apache Commons Math//ww w  . j  a va  2s.c o m
 *
 * @param stream the stream
 * @return covariance covariance
 */
@Nonnull
public static RealMatrix getCovariance(@Nonnull final Supplier<Stream<double[]>> stream) {
    final int dimension = stream.get().findAny().get().length;
    final List<DoubleStatistics> statList = IntStream.range(0, dimension * dimension)
            .mapToObj(i -> new DoubleStatistics()).collect(Collectors.toList());
    stream.get().forEach(array -> {
        for (int i = 0; i < dimension; i++) {
            for (int j = 0; j <= i; j++) {
                statList.get(i * dimension + j).accept(array[i] * array[j]);
            }
        }
        RecycleBin.DOUBLES.recycle(array, array.length);
    });
    @Nonnull
    final RealMatrix covariance = new BlockRealMatrix(dimension, dimension);
    for (int i = 0; i < dimension; i++) {
        for (int j = 0; j <= i; j++) {
            final double v = statList.get(i + dimension * j).getAverage();
            covariance.setEntry(i, j, v);
            covariance.setEntry(j, i, v);
        }
    }
    return covariance;
}

From source file:Main.java

/**
 * Collect the return value of all the futures and apply the transformation
 * method on it/*from  w w  w.ja v a 2 s  .co m*/
 *
 * @param transformer
 *            the transformation to apply
 * @param futures
 *            the future
 * @return a future with the collected results
 */
@SafeVarargs
public static <T, O> CompletableFuture<List<T>> collect(Function<O, T> transformer,
        CompletableFuture<O>... futures) {
    return CompletableFuture.allOf(futures).thenApply(
            v -> Stream.of(futures).map(f -> f.join()).map(transformer::apply).collect(Collectors.toList()));
}

From source file:org.obiba.mica.web.model.GitCommitInfoDtos.java

@NotNull
public List<Mica.GitCommitInfoDto> asDto(Iterable<CommitInfo> commitInfos) {
    return StreamSupport.stream(commitInfos.spliterator(), false).map(this::asDto).collect(Collectors.toList());
}