Example usage for java.util List stream

List of usage examples for java.util List stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:com.pinterest.rocksplicator.controller.config.ConfigParserTest.java

public static Optional<ShardBean> findShard(List<ShardBean> shards, int id) {
    return shards.stream().filter(s -> s.getId() == id).findAny();
}

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static Map<Integer, Pair<Double, Double>> learnZscoringModel(List<String> training) {
    return training.stream().map(LibSVMUtils::split).map(Triple::getMiddle).flatMap(List::stream)
            .collect(groupingBy(Pair::getKey, ConcurrentHashMap::new,
                    reducing(new ArrayList<Float>(), pair -> asList(pair.getRight()),
                            (p1, p2) -> Stream.of(p1, p2).flatMap(List::stream).collect(toList()))))
            .entrySet().stream()//from  w ww.j  av a 2 s.  c o m
            .map(entry -> Pair.of(entry.getKey(), entry.getValue().stream().mapToDouble(f -> f).toArray()))
            .collect(toMap(Entry::getKey, entry -> Pair.of(new Mean().evaluate(entry.getValue()),
                    new StandardDeviation().evaluate(entry.getValue()))));
}

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static List<String> applyZscoringModel(Map<Integer, Pair<Double, Double>> model, List<String> examples) {
    return examples.stream().map(LibSVMUtils::split).map(triple -> triple.getLeft()
            + String.join(" ", triple.getMiddle().stream().map(pair -> Pair.of(pair.getLeft(),
                    (!model.containsKey(pair.getLeft()) || model.get(pair.getLeft()).getRight() == 0) ? 1f
                            : ((pair.getRight() - model.get(pair.getLeft()).getLeft())
                                    / model.get(pair.getLeft()).getRight())))
                    .filter(pair -> pair.getRight().floatValue() != 0f)
                    .map(pair -> pair.getLeft() + ":" + pair.getRight().floatValue()).collect(toList()))
            + triple.getRight()).collect(toList());
}

From source file:info.archinnov.achilles.internals.parser.validator.BeanValidator.java

public static void validateCqlColumnNotReservedWords(AptUtils aptUtils, TypeName rawClassType,
        List<TypeParsingResult> parsingResults) {
    parsingResults.stream().map(x -> Tuple2.of(x.context.cqlColumn, x.context.fieldName))
            .forEach(x -> aptUtils.validateFalse(RESERVED_KEYWORDS.contains(x._1().toLowerCase()),
                    "The cql column '%s' on field '%s' of class '%s' is a CQL reserved word and cannot be used",
                    x._1(), x._2(), rawClassType));
}

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static List<String> asString(List<Map<Integer, Double>> map) {
    return map.stream().map(LibSVMUtils::asString).collect(toList());
}

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static Map<Integer, Pair<Float, Float>> learnScalingModel(List<String> training) {
    return training.stream().map(LibSVMUtils::split).map(Triple::getMiddle).flatMap(List::stream)
            .collect(groupingBy(Pair::getKey, ConcurrentHashMap::new,
                    reducing(Pair.of(0f, 0f), pair -> Pair.of(pair.getRight(), pair.getRight()),
                            (p1, p2) -> Pair
                                    .of(min(p1.getLeft(), p2.getLeft()), max(p1.getRight(), p2.getRight())))))
            .entrySet().stream()//w  w  w.ja  v  a2 s  . co m
            .filter(entry -> entry.getValue().getLeft().floatValue() != entry.getValue().getRight()
                    .floatValue())
            .collect(toMap(Entry::getKey, entry -> Pair.of(entry.getValue().getLeft(),
                    entry.getValue().getRight() - entry.getValue().getLeft())));
}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.DockerMounts.java

private static Map<String, String> lineToMap(String line) {
    final HashMap<String, String> map = new HashMap<>();
    final String[] properties = line.split(",");

    for (String property : properties) {
        if (stripToEmpty(property).toLowerCase().equals("readonly")) {
            map.put("readOnly", "true");
        } else if (property.contains("=")) {
            final String[] parts = property.split("=", 2);
            switch (stripToEmpty(parts[0]).toLowerCase()) {
            case "type":
                map.put("type", stripToEmpty(parts[1]));
                break;
            case "source":
            case "src":
                map.put("source", stripToEmpty(parts[1]));
                break;
            case "target":
            case "destination":
            case "dst":
                map.put("target", stripToEmpty(parts[1]));
                break;
            default:
                throw new RuntimeException(format(
                        "Invalid mount specification `{0}`. Option `{1}` not implemented.", line, parts[0]));
            }//from w ww .  j a  va  2  s  .c o m
        } else {
            throw new RuntimeException(
                    format("Invalid mount specification `{0}`. Option `{1}` not implemented.", line, property));
        }
    }

    final List<String> mountTypes = Arrays.asList("bind", "volume");
    if (map.containsKey("type") && mountTypes.stream().noneMatch(map.get("type")::contains)) {
        throw new RuntimeException(format(
                "Invalid mount type specification `{0}`. Available options are `{1}`.", line, mountTypes));
    }

    if (map.containsKey("type") && map.get("type").equals("bind") && isBlank(map.get("source"))) {
        throw new RuntimeException(format(
                "Invalid mount source specification `{0}`. Bind mounts have to specify `source`.", line));
    }

    if (isBlank(map.get("target"))) {
        throw new RuntimeException(
                format("Invalid mount target specification `{0}`. `target` has to be specified.", line));
    }

    return map;
}

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static List<String> applyScalingModel(Map<Integer, Pair<Float, Float>> model, List<String> examples) {
    return examples.stream().map(LibSVMUtils::split)
            .map(triple -> triple.getLeft() + String.join(" ",
                    triple.getMiddle().stream()
                            .map(pair -> Pair.of(pair.getLeft(),
                                    !model.containsKey(pair.getLeft()) ? 1f
                                            : ((pair.getRight() - model.get(pair.getLeft()).getLeft())
                                                    / model.get(pair.getLeft()).getRight())))
                            .//from   w  w  w . j  a  v  a2 s  .  co m
                            //map(pair -> Pair.of(pair.getKey(), 2 * pair.getRight() - 1)).
                            filter(pair -> pair.getValue() != 0f)
                            .map(pair -> pair.getLeft() + ":" + pair.getRight()).collect(toList()))
                    + triple.getRight())
            .collect(toList());
}

From source file:org.fede.util.Util.java

private static BigDecimal avg(List<BigDecimal> list) {
    if (list.isEmpty()) {
        return BigDecimal.ZERO;
    }/*  ww  w .  ja v a 2 s. c om*/
    return list.stream().reduce(BigDecimal.ZERO, (left, right) -> left.add(right))
            .setScale(7, RoundingMode.HALF_UP).divide(new BigDecimal(list.size()), MathContext.DECIMAL32);
}

From source file:com.github.horrorho.inflatabledonkey.cloud.clients.SnapshotClient.java

public static List<Snapshot> snapshots(HttpClient httpClient, CloudKitty kitty, ProtectionZone zone,
        Collection<SnapshotID> snapshotIDs) throws IOException {

    if (snapshotIDs.isEmpty()) {
        return new ArrayList<>();
    }//from  ww  w.j  a  v  a 2s.  co m

    List<String> snapshots = snapshotIDs.stream().map(SnapshotID::id).collect(Collectors.toList());

    List<CloudKit.RecordRetrieveResponse> responses = kitty.recordRetrieveRequest(httpClient, "mbksync",
            snapshots);
    logger.debug("-- manifests() - responses: {}", responses);

    return responses.stream().filter(CloudKit.RecordRetrieveResponse::hasRecord)
            .map(CloudKit.RecordRetrieveResponse::getRecord).map(r -> manifests(r, zone))
            .filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
}