Example usage for java.util Collection stream

List of usage examples for java.util Collection stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:edu.emory.bmi.datacafe.core.DataCafeUtil.java

/**
 * Construct a string from a collection//  w  w w .  ja v  a2 s  .c o  m
 *
 * @param collection the collection
 * @return the collection as a comma separated line
 */
public static String constructQueryFromCollection(Collection collection) {
    // This line of code is genius (despite looking ugly).
    // Future maintainer: Be careful if you are trying to refactor it.
    return (String) collection.stream().map(i -> append_string_(i.toString())).collect(Collectors.joining(","));
}

From source file:edu.emory.bmi.datacafe.core.DataCafeUtil.java

/**
 * Construct a string from a collection//from ww w. j a v a2  s  .  c  o  m
 *
 * @param collection the collection
 * @return the collection as a comma separated line
 */
public static String constructStringFromCollection(Collection collection) {
    // This line of code is genius (despite looking ugly).
    // Future maintainer: Be careful if you are trying to refactor it.
    return (String) collection.stream().map(i -> doublequote(doubleTheDoubleQuote(i.toString())))
            .collect(Collectors.joining(","));
}

From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobModelTransform.java

public static List<ExecutedJob> executedJobs(Collection<? extends BatchJobExecution> jobs) {
    if (jobs != null && !jobs.isEmpty()) {
        return jobs.stream().map(jobExecution -> executedJob(jobExecution)).collect(Collectors.toList());
    } else {/*from  www.  ja va  2 s . co  m*/
        return Collections.emptyList();
    }
}

From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobModelTransform.java

public static List<ExecutedJob> executedJobsSimple(Collection<? extends BatchJobExecution> jobs) {
    if (jobs != null && !jobs.isEmpty()) {
        return jobs.stream().map(jobExecution -> executedJobSimple(jobExecution)).collect(Collectors.toList());
    } else {/*ww w .j  a v a  2 s  .com*/
        return Collections.emptyList();
    }
}

From source file:Main.java

/**
 * Selects the list of collection elements that satisfy the given filter.
 * If the filter is <code>null</code>, all the collection elements are returned.
 *
 * @param collection The collection to be filtered
 * @param filter     The filter to be applied
 * @param <T>        The type of collection elements
 * @return A list of elements satisfying the filter
 *//*from w w  w .j  a  va  2 s  . c  o m*/
public static <T> List<T> where(Collection<T> collection, Predicate<T> filter) {
    List<T> result = null;
    if (collection != null) {
        if (filter != null) {
            result = where(collection.stream(), filter);
        } else {
            result = (collection instanceof List ? (List<T>) collection : new ArrayList<>(collection));
        }
    }
    return result;
}

From source file:mtsar.api.csv.TaskCSV.java

public static void write(Collection<Task> tasks, OutputStream output) throws IOException {
    try (final Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
        final Iterable<String[]> iterable = () -> tasks.stream().sorted(ORDER)
                .map(task -> new String[] { Integer.toString(task.getId()), // id
                        task.getStage(), // stage
                        Long.toString(task.getDateTime().toInstant().getEpochSecond()), // datetime
                        String.join("|", task.getTags()), // tags
                        task.getType(), // type
                        task.getDescription(), // description
                        String.join("|", task.getAnswers()), // answers
                }).iterator();//  www  .j av a2s. c o  m

        FORMAT.withHeader(HEADER).print(writer).printRecords(iterable);
    }
}

From source file:com.spotify.heroic.filter.OrFilter.java

static SortedSet<Filter> flatten(final Collection<Filter> filters) {
    final SortedSet<Filter> result = new TreeSet<>();

    filters.stream().flatMap(f -> f.optimize().visit(new Visitor<Stream<Filter>>() {
        @Override//w  w  w . j av a  2  s  . co  m
        public Stream<Filter> visitOr(final OrFilter or) {
            return or.terms().stream().map(Filter::optimize);
        }

        @Override
        public Stream<Filter> visitNot(final NotFilter not) {
            // check for De Morgan's
            return not.getFilter().visit(new Filter.Visitor<Stream<Filter>>() {
                @Override
                public Stream<Filter> visitAnd(final AndFilter and) {
                    return and.terms().stream().map(f -> NotFilter.of(f).optimize());
                }

                @Override
                public Stream<Filter> defaultAction(final Filter filter) {
                    return Stream.of(not.optimize());
                }
            });
        }

        @Override
        public Stream<Filter> defaultAction(final Filter filter) {
            return Stream.of(filter);
        }
    })).forEach(result::add);

    return result;
}

From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobModelTransform.java

public static List<ExecutedStep> executedSteps(Collection<? extends BatchStepExecution> steps) {
    if (steps != null && !steps.isEmpty()) {
        return steps.stream().map(stepExecution -> executedStep(stepExecution)).collect(Collectors.toList());
    } else {/* ww w  .  jav  a 2  s.c o  m*/
        return Collections.emptyList();
    }
}

From source file:de.tudarmstadt.ukp.dkpro.argumentation.io.annotations.SpanAnnotationMatrices.java

public static <T extends SpanTextLabel> Sparse3DObjectMatrix<String, T> createMatrix(
        final Collection<T> spanAnnotationVector) {
    final Sparse3DObjectMatrix<String, T> result = new Sparse3DObjectMatrix<>(
            new Int2ObjectOpenHashMap<>(spanAnnotationVector.size() + 1));
    putAnnotations(result, spanAnnotationVector.stream());
    return result;

}

From source file:mtsar.api.csv.AnswerCSV.java

public static void write(Collection<Answer> answers, OutputStream output) throws IOException {
    try (final Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
        final Iterable<String[]> iterable = () -> answers.stream().sorted(ORDER)
                .map(answer -> new String[] { Integer.toString(answer.getId()), // id
                        answer.getStage(), // stage
                        Long.toString(answer.getDateTime().toInstant().getEpochSecond()), // datetime
                        String.join("|", answer.getTags()), // tags
                        answer.getType(), // type
                        Integer.toString(answer.getTaskId()), // task_id
                        Integer.toString(answer.getWorkerId()), // worker_id
                        String.join("|", answer.getAnswers()) // answers
                }).iterator();// w  ww  . j ava2  s .c  o m

        FORMAT.withHeader(HEADER).print(writer).printRecords(iterable);
    }
}