Example usage for java.util.stream Collectors toCollection

List of usage examples for java.util.stream Collectors toCollection

Introduction

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

Prototype

public static <T, C extends Collection<T>> Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) 

Source Link

Document

Returns a Collector that accumulates the input elements into a new Collection , in encounter order.

Usage

From source file:io.mapzone.controller.vm.provisions.MaxProcesses.java

@Override
public Status execute() throws Exception {
    checked.set(this);
    assert process
            .isPresent() : "No process in context. Make sure that MaxProcesses executes after ProcessStarted.";

    HostRecord host = process.get().instance.get().host.get();
    if (host.statistics.get() == null || host.statistics.get().olderThan(10, TimeUnit.SECONDS)) {

        host.updateStatistics();/*from  w  w  w  . ja  va  2  s . c  om*/

        // lowest start time (oldest) first
        LinkedList<ProcessRecord> sortedProcesses = host.instances.stream().filter(i -> i.process.get() != null)
                .map(i -> i.process.get()).sorted((p1, p2) -> p1.started.get().compareTo(p2.started.get()))
                .collect(Collectors.toCollection(LinkedList::new));
        log.info("    PROCESSES RUNNING: " + sortedProcesses.size() + " ("
                + host.statistics.get().lastChecked.get() + ")");

        // stop processes, oldest first
        while (sortedProcesses.size() > MAX_PROCESSES) {
            ProcessRecord p = sortedProcesses.remove(0);

            log.info("    stopping process: " + p.instance.get().project.get() + " -- started at "
                    + p.started.get());
            StopProcessOperation op = new StopProcessOperation();
            op.process.set(p);
            op.vmUow.set(vmUow());
            op.execute(null, null);
        }
    }

    return OK_STATUS;
}

From source file:net.lldp.checksims.submission.ValidityIgnoringSubmission.java

@Override
public boolean equals(Object other) {
    if (!(other instanceof Submission)) {
        return false;
    }/*from  w  w  w. j  av  a2s.co  m*/

    AbstractSubmissionDecorator otherSubmission = new ValidityIgnoringSubmission((Submission) other,
            getTokenizer());

    if (!otherSubmission.getTokenType().equals(this.getTokenType())
            || !otherSubmission.getName().equals(this.getName())
            || !(otherSubmission.getNumTokens() == this.getNumTokens())
            || !(otherSubmission.getContentAsString().equals(this.getContentAsString()))) {
        return false;
    }

    Supplier<TokenList> tokenListSupplier = () -> new TokenList(this.getTokenType());
    TokenList thisList = this.getContentAsTokens().stream().map(ValidityIgnoringToken::new)
            .collect(Collectors.toCollection(tokenListSupplier));
    TokenList otherList = otherSubmission.getContentAsTokens().stream().map(ValidityIgnoringToken::new)
            .collect(Collectors.toCollection(tokenListSupplier));

    return thisList.equals(otherList);
}

From source file:net.lldp.checksims.submission.ValidityEnsuringSubmission.java

@Override
public boolean equals(Object other) {
    if (!(other instanceof Submission)) {
        return false;
    }//from   w  w  w  .  j  a  v a 2s .c o m

    AbstractSubmissionDecorator otherSubmission = new ValidityEnsuringSubmission((Submission) other,
            getTokenizer());

    if (!otherSubmission.getTokenType().equals(this.getTokenType())
            || !otherSubmission.getName().equals(this.getName())
            || !(otherSubmission.getNumTokens() == this.getNumTokens())
            || !(otherSubmission.getContentAsString().equals(this.getContentAsString()))) {
        return false;
    }

    Supplier<TokenList> tokenListSupplier = () -> new TokenList(this.getTokenType());
    TokenList thisList = this.getContentAsTokens().stream().map(ValidityEnsuringToken::new)
            .collect(Collectors.toCollection(tokenListSupplier));
    TokenList otherList = otherSubmission.getContentAsTokens().stream().map(ValidityEnsuringToken::new)
            .collect(Collectors.toCollection(tokenListSupplier));

    return thisList.equals(otherList);
}

From source file:org.jaqpot.core.service.validator.ParameterValidator.java

public void validateDataset(Dataset dataset, List<String> requiredFeatures) {
    if (dataset.getFeatures() == null) {
        throw new IllegalArgumentException("Input dataset does not have features");
    }/*from   w  w  w  .j  av  a2s .c  o m*/
    HashSet<String> features = dataset.getFeatures().stream().map(FeatureInfo::getURI)
            .collect(Collectors.toCollection(HashSet::new));

    if (!features.containsAll(requiredFeatures)) {
        throw new IllegalArgumentException("Dataset is not compatible with model");
    }
}

From source file:de.thomasvolk.genexample.model.WagonFactory.java

public Wagon lese(String text) {
    String[] lines = text.split("\\r?\\n");
    List<Sitzplatz> sitzplatzListe = new ArrayList<>();
    int breite = lines.length;
    int position = breite - 1;
    int anzahlReihen = 0;
    for (String line : lines) {
        int reiheInZeile = 0;
        for (char eigenschaft : line.toCharArray()) {
            Sitzplatz sitzplatz = erzeuge(reiheInZeile, position, breite, eigenschaft);
            if (sitzplatz != null) {
                sitzplatzListe.add(sitzplatz);
            }/*from   w ww  .j  a v a2s.  c  o  m*/
            reiheInZeile++;
        }
        if (reiheInZeile > anzahlReihen) {
            anzahlReihen = reiheInZeile;
        }
        position--;
    }
    Sitzplatz[] sitzPLaetze = sitzplatzListe.stream().sorted((s1, s2) -> s1.getNummer() - s2.getNummer())
            .collect(Collectors.toCollection(ArrayList::new)).toArray(new Sitzplatz[sitzplatzListe.size()]);
    return new Wagon(sitzPLaetze, anzahlReihen, breite);
}

From source file:io.appform.nautilus.funnel.administration.TenancyManager.java

public List<String> tenants() {
    SearchResponse response = connection.client().prepareSearch(ESUtils.getAllIndices())
            .setIndicesOptions(IndicesOptions.lenientExpandOpen()).setTypes(TypeUtils.typeName(Session.class))
            .setQuery(QueryBuilders.matchAllQuery())
            .addAggregation(AggregationBuilders.terms(AGGREGATION_NAME).field("tenant")).setSize(0).execute()
            .actionGet();//from   www  . j  av a2  s .  c  om
    if (response.status() == RestStatus.OK && null != response.getAggregations()) {
        Terms terms = response.getAggregations().get(AGGREGATION_NAME);
        return terms.getBuckets().stream().map(Terms.Bucket::getKeyAsString)
                .collect(Collectors.toCollection(ArrayList::new));
    }
    return Collections.emptyList();
}

From source file:Callers.Caller.java

/**
 * Call the selected genotypes//from  w w  w. j  a v  a 2s  .  c o  m
 * @param list The genotypes to call
 * @return The probabilities of each genotype
 */
public List<SingleGenotypeProbability> call(List<SingleGenotypeReads> list) {
    Progress progress = ProgressFactory.get(list.size());
    return list.stream().parallel().map(sgr -> {
        SingleGenotypeProbability sgp = new SingleGenotypeProbability(sgr.getSample(), sgr.getSNP(),
                callSingle(sgr.getReads(), sgr.getSample(), sgr.getSNP()));
        progress.done();
        return sgp;
    }).collect(Collectors.toCollection(ArrayList::new));
}

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.thoughtworks.go.server.service.WebpackAssetsService.java

public Set<String> getCSSAssetPathsFor(String... assetNames) throws IOException {
    return getAssetPathsFor(assetNames).stream().filter(assetName -> assetName.endsWith(".css"))
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:org.pentaho.js.require.RebuildCacheCallable.java

private static void makePathsAbsolute(Map<String, Object> result, String baseUrl) {
    HashMap<String, String> paths = (HashMap<String, String>) result.get("paths");
    paths.forEach((moduleId, location) -> {
        if (checkNeedsBaseUrl(location)) {
            paths.put(moduleId, baseUrl + location);
        }//from   w  w w  .j  av a  2 s  .  c om
    });

    ArrayList<Object> packages = (ArrayList<Object>) result.get("packages");
    final ArrayList<Object> convertedPackages = packages.stream().filter(Objects::nonNull)
            .map(packageDefinition -> {
                if (packageDefinition instanceof HashMap) {
                    final HashMap<String, String> complexPackageDefinition = (HashMap<String, String>) packageDefinition;

                    if (complexPackageDefinition.containsKey("location")) {
                        String location = complexPackageDefinition.get("location");
                        if (checkNeedsBaseUrl(location)) {
                            complexPackageDefinition.put("location", baseUrl + location);
                            return complexPackageDefinition;
                        }
                    }
                }

                return packageDefinition;
            }).collect(Collectors.toCollection(ArrayList<Object>::new));

    result.put("packages", convertedPackages);
}