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:info.archinnov.achilles.internals.parser.validator.BeanValidator.java

public static void validateComputed(AptUtils aptUtils, TypeName rawClassType,
        List<TypeParsingResult> parsingResults) {
    List<String> fieldNames = parsingResults.stream().map(x -> x.context.fieldName).collect(toList());

    final Set<String> aliases = new HashSet<>();

    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.COMPUTED)
            .map(x -> Tuple2.of(x.context.fieldName, ((ComputedColumnInfo) x.context.columnInfo).alias))
            .forEach(x -> {/*  w ww.j a  v a  2s.c o m*/
                aptUtils.validateFalse(aliases.contains(x._2()),
                        "Alias '%s' in @Computed annotation on field '%s' is already used by another @Computed field",
                        x._2(), x._1());
                if (!aliases.contains(x._2()))
                    aliases.add(x._2());
            });

    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.COMPUTED).forEach(x -> {
        final ComputedColumnInfo columnInfo = (ComputedColumnInfo) x.context.columnInfo;
        for (String column : columnInfo.functionArgs) {
            aptUtils.validateTrue(fieldNames.contains(column),
                    "Target field '%s' in @Computed annotation of field '%s' of class '%s' does not exist",
                    column, x.context.fieldName, rawClassType);
        }
    });
}

From source file:com.cirro.jsonjoin.utils.FileManager.java

public static <T extends Row> Stream<T> loadFileStream(File file, Class<T> valueType) throws IOException {
    List rowList = new ArrayList();
    LineIterator it = FileUtils.lineIterator(file, "UTF-8");
    while (it.hasNext()) {
        String line = it.nextLine();
        Row row = convertToRow(line, valueType);
        rowList.add(row);/* w  ww  . j av  a  2 s.  c  om*/
    }
    return rowList.stream();
}

From source file:de.tynne.benchmarksuite.Main.java

private static void checkNano(PrintStream ps) {
    List<Long> diffs = new ArrayList<>();

    nanoNullLoop(1000000, diffs);//from w w w. j  av a  2s  .  c o m
    diffs.clear();
    nanoNullLoop(1000000, diffs);

    LongSummaryStatistics statistics = diffs.stream().mapToLong(l -> l).summaryStatistics();

    ps.printf("min=%d, avg=%g, max=%d\n", statistics.getMin(), statistics.getAverage(), statistics.getMax());
}

From source file:com.amazon.proposalcalculator.reader.StandByInstances.java

public static List<Price> generate(List<Price> beanList) throws NoSuchMethodException, InstantiationException,
        IllegalAccessException, InvocationTargetException {

    Predicate<Price> predicate = c4LargeToBeCloned();

    List<Price> t2NanoToBeClonedList = beanList.stream().filter(predicate).collect(Collectors.toList());

    beanList = cloneT2Nano(beanList, t2NanoToBeClonedList);

    return beanList;
}

From source file:com.formkiq.core.form.FormFinder.java

/**
 * Find {@link WorkflowOutputFormField}.
 *
 * @param workflow {@link Workflow}//from   w  w w  .j a  v a  2 s  . c  om
 * @param form {@link FormJSON}
 * @param field {@link FormJSONField}
 * @return {@link Optional} of {@link WorkflowOutputFormField}
 */
public static Optional<WorkflowOutputFormField> findWorkflowOutputDocument(final Workflow workflow,
        final FormJSON form, final FormJSONField field) {

    List<WorkflowOutputFormField> fields = stream(workflow);

    return fields.stream().filter(s -> {
        String formUUID = extractLabelAndValue(s.getForm()).getRight();
        int id = NumberUtils.toInt(extractLabelAndValue(s.getField()).getRight(), -1);

        return formUUID.equals(form.getUUID()) && field.getId() == id;
    }).findFirst();
}

From source file:com.epam.catgenome.controller.vo.converter.ProjectConverter.java

/**
 * Converts a {@code List} of {@code Project} entities into {@code List} of {@code ProjectVO}
 * @param projects a {@code List} of {@code Project} entities
 * @return {@code List} of {@code ProjectVO}
 *//*from  ww w  . ja  va 2  s.  c  o  m*/
public static List<ProjectVO> convertTo(List<Project> projects) {
    if (CollectionUtils.isEmpty(projects)) {
        return Collections.emptyList();
    }

    return projects.stream().map(ProjectConverter::convertTo).collect(Collectors.toList());
}

From source file:com.adaptris.core.services.jdbc.JdbcBatchingDataCaptureService.java

protected static long rowsUpdated(int[] rc) throws SQLException {
    List<Integer> result = Arrays.asList(ArrayUtils.toObject(rc));
    if (result.contains(Statement.EXECUTE_FAILED)) {
        throw new SQLException("Batch Execution Failed.");
    }/*from   w ww.ja v a  2  s . c  om*/
    return result.stream().filter(e -> !(e == Statement.SUCCESS_NO_INFO)).mapToLong(i -> i).sum();
}

From source file:es.uvigo.ei.sing.laimages.core.operations.Interpolator.java

private static LineData[] calculateNewLines(ElementData data, int interpolationLevel, double[][] newValues) {
    final boolean isVertical = data.getCoordinates()[0].isVertical();
    int newLineCount = isVertical ? newValues[0].length : newValues.length;
    final LineData[] newLines = new LineData[newLineCount];

    final List<Double> xAxis = data.getXAxis();
    final List<Double> yAxis = data.getYAxis();
    final double minX = xAxis.stream().mapToDouble(Double::valueOf).min()
            .orElseThrow(IllegalStateException::new);
    final double maxX = xAxis.stream().mapToDouble(Double::valueOf).max()
            .orElseThrow(IllegalStateException::new);
    final double minY = yAxis.stream().mapToDouble(Double::valueOf).min()
            .orElseThrow(IllegalStateException::new);
    final double maxY = yAxis.stream().mapToDouble(Double::valueOf).max()
            .orElseThrow(IllegalStateException::new);
    final double tickX = (maxX - minX) / (double) (newValues[0].length - 1);
    final double tickY = (maxY - minY) / (double) (newValues.length - 1);

    for (int i = 0; i < newLineCount; i++) {
        final double[] lineValues = getLineValues(newValues, i, isVertical);

        final int minNumIndex = firstValueIndex(lineValues);
        final int maxNumIndex = lastValueIndex(lineValues);

        final double[] nonNanLineValues = new double[maxNumIndex - minNumIndex + 1];
        System.arraycopy(lineValues, minNumIndex, nonNanLineValues, 0, nonNanLineValues.length);

        newLines[i] = new LineData("Line " + (i + 1), nonNanLineValues,
                isVertical/*w w  w . j a  va2 s . co  m*/
                        ? new VerticalLineCoordinates(tickY, minY + ((double) minNumIndex * tickY),
                                minY + ((double) maxNumIndex * tickY), tickX * ((double) i) + minX)
                        : new HorizontalLineCoordinates(tickX, minX + ((double) minNumIndex * tickX),
                                minX + ((double) maxNumIndex * tickX), tickY * ((double) i) + minY));
    }

    return newLines;
}

From source file:fi.hsl.parkandride.core.service.PredictionServiceTest.java

private static void inParallel(Runnable... commands) throws InterruptedException {
    ExecutorService executor = Executors.newFixedThreadPool(commands.length);
    List<Future<?>> futures = Stream.of(commands).map(executor::submit).collect(toList());
    List<Exception> exceptions = futures.stream().flatMap(future -> {
        try {//from   ww  w  .j  a v a2  s.  co  m
            future.get();
            return Stream.empty();
        } catch (Exception e) {
            return Stream.of(e);
        }
    }).collect(toList());
    if (!exceptions.isEmpty()) {
        AssertionError e = new AssertionError(
                "There were " + exceptions.size() + " uncaught exceptions in the background threads");
        exceptions.forEach(e::addSuppressed);
        throw e;
    }
}

From source file:de.unigoettingen.sub.search.opac.ConfigOpac.java

/**
 * get doctype from title./*from w  w  w.java2s  . c o m*/
 */
public static ConfigOpacDoctype getDoctypeByName(String inTitle) throws FileNotFoundException {
    int countCatalogues = getConfig().getMaxIndex(DOCTYPES_TYPE);
    for (int i = 0; i <= countCatalogues; i++) {
        String title = getConfig().getString(DOCTYPES_TYPE + "(" + i + ")[@title]");
        if (title.equals(inTitle)) {
            /* Sprachen erfassen */
            HashMap<String, String> labels = new HashMap<>();
            int countLabels = getConfig().getMaxIndex(DOCTYPES_TYPE + "(" + i + ").label");
            for (int j = 0; j <= countLabels; j++) {
                String language = getConfig()
                        .getString(DOCTYPES_TYPE + "(" + i + ").label(" + j + ")[@language]");
                String value = getConfig().getString(DOCTYPES_TYPE + "(" + i + ").label(" + j + ")");
                labels.put(language, value);
            }
            String inRulesetType = getConfig().getString(DOCTYPES_TYPE + "(" + i + ")[@rulesetType]");
            String inTifHeaderType = getConfig().getString(DOCTYPES_TYPE + "(" + i + ")[@tifHeaderType]");
            boolean periodical = getConfig().getBoolean(DOCTYPES_TYPE + "(" + i + ")[@isPeriodical]");
            boolean multiVolume = getConfig().getBoolean(DOCTYPES_TYPE + "(" + i + ")[@isMultiVolume]");
            boolean newspaper;
            try {
                newspaper = getConfig().getBoolean(DOCTYPES_TYPE + "(" + i + ")[@isNewspaper]");
            } catch (NoSuchElementException noParameterIsNewspaper) {
                newspaper = false;
            }
            List<Object> configs = getConfig().getList(DOCTYPES_TYPE + "(" + i + ").mapping");
            List<String> mappings = configs.stream().map(object -> Objects.toString(object, null))
                    .collect(Collectors.toList());

            return new ConfigOpacDoctype(inTitle, inRulesetType, inTifHeaderType, periodical, multiVolume,
                    newspaper, labels, mappings);
        }
    }
    return null;
}