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:Main.java

public static <T> List<T> subListOn(List<T> list, Predicate<T> predicate) {
    Optional<T> first = list.stream().filter(predicate).findFirst();
    if (!first.isPresent())
        return list;
    return list.subList(0, list.indexOf(first.get()));
}

From source file:Main.java

static public <E> String mkString(List<E> list, Function<E, String> stringify, String delimiter) {
    return list.stream().map(stringify).collect(Collectors.joining(delimiter));
}

From source file:de.dhbw.vetaraus.SanitizeUtils.java

public static List<Case> sanitizeCases(List<Case> cases) {
    return cases.stream()
            .map(c -> new Case(c.getNumber(), sanitizeRecordValue(c.getAge()),
                    sanitizeRecordValue(c.getGender()), sanitizeRecordValue(c.getMarried()),
                    sanitizeRecordValue(c.getChildCount()), sanitizeRecordValue(c.getDegree()),
                    sanitizeRecordValue(c.getOccupation()), sanitizeRecordValue(c.getIncome()), c.getTariff()))
            .collect(Collectors.toList());
}

From source file:com.synopsys.integration.util.EnumUtils.java

public static <T extends Enum<T>> List<T> convert(List<String> values, Class<T> enumClass) {
    return values.stream().map(String::trim).filter(StringUtils::isNotBlank)
            .map(token -> Enum.valueOf(enumClass, token)).collect(Collectors.toList());
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <TargetType, CurrentType> List<TargetType> cast(List<CurrentType> list,
        Class<TargetType> targetClass) {
    return list.stream().map(e -> (TargetType) e).collect(Collectors.toList());
}

From source file:com.github.blindpirate.gogradle.util.CollectionUtils.java

public static <T> List<T> flatten(List<List<T>> lists) {
    return lists.stream().collect(ArrayList::new, ArrayList::addAll, ArrayList::addAll);
}

From source file:com.khartec.waltz.jobs.sample.FlowGenerator.java

private static EntityReference randomAppPick(List<Application> apps, long orgUnitId) {
    List<Application> appsForOU = apps.stream().filter(a -> a.organisationalUnitId() == orgUnitId)
            .collect(toList());//from ww  w  .  j  a v a 2s.  co m
    return randomPick(appsForOU).toEntityReference();
}

From source file:newcontroller.handler.impl.HttpMessageConvertersHelper.java

static HttpMessageConverter<?> findConverter(List<HttpMessageConverter<?>> converters, Class<?> clazz,
        MediaType mediaType) {//from  www. j  a v  a2 s  . c o m
    return converters.stream().filter(converter -> converter.canWrite(clazz, mediaType)).findFirst()
            .orElseThrow(() -> new IllegalStateException(
                    "Cannot find HttpMessageConverter for clazz=" + clazz + ", mediaType=" + mediaType));
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.provider.KubernetesModelUtil.java

private static boolean anyDown(List<Map<String, String>> healthsList) {
    return healthsList.stream().anyMatch(h -> stateEquals(h, HealthState.Down));
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.provider.KubernetesModelUtil.java

private static boolean anyStarting(List<Map<String, String>> healthsList) {
    return healthsList.stream().anyMatch(h -> stateEquals(h, HealthState.Starting));
}