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:it.unibo.alchemist.test.TestInSimulator.java

@SafeVarargs
private static <T> void runSimulation(final String relativeFilePath, final double finalTime,
        final Consumer<Environment<Object>>... checkProcedures) throws InstantiationException,
        IllegalAccessException, InvocationTargetException, ClassNotFoundException, SAXException, IOException,
        ParserConfigurationException, InterruptedException, ExecutionException {
    final Resource res = XTEXT.getResource(URI.createURI("classpath:/simulations/" + relativeFilePath), true);
    final IGenerator generator = INJECTOR.getInstance(IGenerator.class);
    final InMemoryFileSystemAccess fsa = INJECTOR.getInstance(InMemoryFileSystemAccess.class);
    generator.doGenerate(res, fsa);/*  ww w.  j av a  2  s  . co m*/
    final Collection<CharSequence> files = fsa.getTextFiles().values();
    if (files.size() != 1) {
        fail();
    }
    final ByteArrayInputStream strIS = new ByteArrayInputStream(
            files.stream().findFirst().get().toString().getBytes(Charsets.UTF_8));
    final Environment<Object> env = EnvironmentBuilder.build(strIS).get().getEnvironment();
    final Simulation<Object> sim = new Engine<>(env, new DoubleTime(finalTime));
    sim.addCommand(new StateCommand<>().run().build());
    /*
     * Use this thread: intercepts failures.
     */
    sim.run();
    Arrays.stream(checkProcedures).forEachOrdered(p -> p.accept(env));
}

From source file:com.teradata.benchto.service.model.AggregatedMeasurement.java

public static AggregatedMeasurement aggregate(MeasurementUnit unit, Collection<Double> values) {
    if (values.size() < 2) {
        Double value = Iterables.getOnlyElement(values);
        return new AggregatedMeasurement(unit, value, value, value, 0.0, 0.0);
    }// www.java 2  s .  c  o  m
    DescriptiveStatistics statistics = new DescriptiveStatistics(
            values.stream().mapToDouble(Double::doubleValue).toArray());

    double stdDevPercent = 0.0;
    if (statistics.getStandardDeviation() > 0.0) {
        stdDevPercent = (statistics.getStandardDeviation() / statistics.getMean()) * 100;
    }

    return new AggregatedMeasurement(unit, statistics.getMin(), statistics.getMax(), statistics.getMean(),
            statistics.getStandardDeviation(), stdDevPercent);
}

From source file:it.issue.IssueSearchTest.java

private static Component findComponent(Collection<Component> components, String key) {
    return components.stream().filter(input -> key.equals(input.key())).findFirst()
            .orElseThrow(() -> new IllegalStateException("Component key not found: " + key));
}

From source file:com.ejisto.core.classloading.ClassTransformerImpl.java

private static Collection<String> loadAllRegisteredClassNames(String contextPath,
        MockedFieldsRepository mockedFieldsRepository) {
    Collection<MockedField> fields = mockedFieldsRepository.load(requestAllClasses(contextPath));
    Set<String> classes = fields.stream().map(MockedField::getClassName).collect(Collectors.toSet());
    trace(format("filtered classes for %s: %s of %s", contextPath, classes, fields));
    return classes;
}

From source file:de.bund.bfr.math.MathUtils.java

public static Set<String> getSymbols(Collection<String> terms) {
    return terms.stream().map(t -> MathUtils.getSymbols(t)).flatMap(Set::stream)
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:com.github.sevntu.checkstyle.ordering.MethodOrder.java

private static String methodsSignatureList(Collection<Method> methods) {
    return methods.stream().map(Object::toString).collect(Collectors.joining("; ", "[", "]"));
}

From source file:com.ikanow.aleph2.example.flume_harvester.utils.FlumeUtils.java

/** Utility to delete generate directories
 * @param bucket/*w  w  w . j  av  a2  s .  c o  m*/
 * @param spool_dirs
 */
public static void deleteGeneratedDirs(final DataBucketBean bucket, final Collection<SpoolDirConfig> spool_dirs,
        boolean test_mode) {
    spool_dirs.stream().forEach(v -> {
        if (test_mode) {
            FileUtils.deleteQuietly(new File(v.path() + "/" + getTestDirSuffix(bucket)));
        }
        FileUtils.deleteQuietly(new File(v.path() + "/" + getTrackingDirSuffix(bucket)));
    });
}

From source file:com.shenit.commons.utils.CollectionUtils.java

/**
 * Get last element of a collection// w ww .  j  av a 2s  .c o  m
 * @param cols
 * @return
 */
public static <T> T last(Collection<T> cols) {
    if (cols == null)
        return null;
    return cols.stream().parallel().skip(cols.size() - 1).findFirst().get();
}

From source file:com.ejisto.util.IOUtils.java

private static List<WebApplicationDescriptorElement> toWebApplicationDescriptorElement(Collection<File> in) {
    return in.stream().map(f -> new WebApplicationDescriptorElement(f.getName())).collect(Collectors.toList());
}

From source file:eu.ggnet.dwoss.report.assist.ReportUtil.java

/**
 * Returns a Set of all Warrenty Positions in the Collection that is given to the method.
 * <p>//from w w  w. j av  a2 s.c o  m
 * A Warranty is in the Set of Reportable Warranty if
 * <ul>
 * <li>SingleRefence from Type {@link SingleReferenceType#WARRANTY} is not null</li>
 * <li>SingleReferenced Unit is in the reportable Amount of ReportLines</li>
 * <li>Reporting Date is after the from Parameter and before the till Parameter</li>
 * </ul>
 * <p>
 * @param warrentyLines all unreported Reportlines that represent warrenty.
 * @param unitLines     all ReportLine's that are already in amount of Reportlines which should be reported.
 * @return all Warrentys which can be reported in this report.
 */
public static NavigableSet<ReportLine> filterWarrenty(Collection<ReportLine> warrentyLines,
        Collection<ReportLine> unitLines) {
    L.info("Warranties in filter: {}", warrentyLines);
    return warrentyLines.stream()
            .filter((t) -> t != null && t.getReference(WARRANTY) != null
                    && (unitLines.contains(t.getReference(WARRANTY))
                            || !t.getReference(WARRANTY).getReports().isEmpty()))
            .collect(Collectors.toCollection(() -> new TreeSet<ReportLine>()));
}