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:com.ge.predix.acs.service.policy.evaluation.PolicyEvaluationServiceTest.java

private Object[] requestEvaluationWithAllOfTwoPolicySets(final List<PolicySet> twoPolicySets) {
    return new Object[] { twoPolicySets,
            Stream.of(twoPolicySets.get(0).getName(), twoPolicySets.get(1).getName())
                    .collect(Collectors.toCollection(LinkedHashSet::new)),
            Effect.DENY };// w  w w . j ava2s.co m
}

From source file:com.ge.predix.acs.service.policy.evaluation.PolicyEvaluationServiceTest.java

private Object[] requestEvaluationWithSecondOfTwoPolicySets(final List<PolicySet> twoPolicySets) {
    return new Object[] { twoPolicySets,
            Stream.of(twoPolicySets.get(1).getName()).collect(Collectors.toCollection(LinkedHashSet::new)),
            Effect.DENY };/*ww w  .j  a  va 2 s  .co  m*/
}

From source file:com.flipkart.foxtrot.core.datastore.impl.hbase.HBaseDataStoreTest.java

@Test
public void testBasicBulkGetSet() throws Exception {
    Map<String, Document> idValues = new HashMap<String, Document>();
    List<String> ids = new Vector<String>();
    HashMap<String, Document> actualIdValues = new HashMap<String, Document>();
    List<Document> documents = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        String id = UUID.randomUUID().toString();
        long timestamp = System.currentTimeMillis();
        JsonNode data = mapper.valueToTree(Collections.singletonMap("TEST_NAME", "BULK_GET_TEST"));
        ids.add(id);//from   w  w w.j a v a 2 s  .  c om
        Document document = new Document(id, timestamp, data);
        idValues.put(id, document);
        documents.add(document);
    }
    List<Document> translatedDocs = HBaseDataStore.saveAll(TEST_APP, documents);
    List<String> rawIds = translatedDocs.stream().map(Document::getId)
            .collect(Collectors.toCollection(ArrayList::new));
    List<Document> actualDocuments = HBaseDataStore.getAll(TEST_APP, rawIds);
    for (Document doc : actualDocuments) {
        actualIdValues.put(doc.getId(), doc);
    }
    assertNotNull("List of returned Documents should not be null", actualDocuments);
    for (String id : ids) {
        assertTrue("Requested Id should be present in response", actualIdValues.containsKey(id));
        compare(idValues.get(id), actualIdValues.get(id));
    }
}

From source file:eu.ggnet.dwoss.misc.op.listings.SalesListingProducerOperation.java

/**
 * Create a filejacket from a collection of lines that are filtered by configuration parameters.
 * Lines are filtered by brand and group.
 * <p>/*  w  w w. j  a va2  s.  c o m*/
 * @param config configuration for filtering and file creation
 * @param all    lines to be considered
 * @return a filejacket from a collection of lines that are filtered by configuration parameters.
 */
private FileJacket createListing(ListingConfiguration config, Collection<StackedLine> all) {
    try {
        SortedSet<StackedLine> filtered = all.stream()
                .filter(line -> (config.getAllBrands().contains(line.getBrand())
                        && config.getGroups().contains(line.getGroup())))
                .collect(Collectors.toCollection(TreeSet::new));
        if (filtered.isEmpty())
            return null;
        L.info("Creating listing {} with {} lines", config.getName(), filtered.size());
        JRDataSource datasource = new JRBeanCollectionDataSource(filtered);
        JasperPrint jasperPrint = JasperFillManager.fillReport(config.getJasperTemplateFile(),
                config.toReportParamters(), datasource);
        byte[] pdfContend = JasperExportManager.exportReportToPdf(jasperPrint);
        return new FileJacket(config.getFilePrefix() + config.getName(), ".pdf", pdfContend);
    } catch (JRException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.pentaho.amazon.AbstractAmazonJobExecutorController.java

protected AbstractModelList<String> populateRegions() {
    regions.clear();//from   w ww.  j  av a2 s.c om
    regions = Arrays.stream(AmazonRegion.values()).map(v -> v.getHumanReadableRegion())
            .collect(Collectors.toCollection(AbstractModelList<String>::new));

    String region = getJobEntry().getRegion();

    if (region == null && regions.size() > 0) {
        getJobEntry().setRegion(regions.get(0));
    }

    return regions;
}

From source file:com.ge.predix.acs.service.policy.evaluation.PolicyEvaluationServiceTest.java

private Object[] requestEvaluationWithFirstOfTwoPolicySets(final List<PolicySet> twoPolicySets) {
    return new Object[] { twoPolicySets,
            Stream.of(twoPolicySets.get(0).getName()).collect(Collectors.toCollection(LinkedHashSet::new)),
            Effect.NOT_APPLICABLE };//w  w  w.  jav a2 s  .com
}

From source file:com.ge.predix.acs.service.policy.evaluation.PolicyEvaluationServiceTest.java

private Object[] requestEvaluationWithFirstOfOnePolicySets(final List<PolicySet> onePolicySet) {
    return new Object[] { onePolicySet,
            Stream.of(onePolicySet.get(0).getName()).collect(Collectors.toCollection(LinkedHashSet::new)),
            Effect.DENY };//from  w w  w  . jav  a2 s .  c o m
}

From source file:org.pentaho.amazon.AbstractAmazonJobExecutorController.java

protected AbstractModelList<String> populateReleases() {
    releases.clear();/*from  ww  w  .  ja  va2s  . c o m*/
    releases = Arrays.stream(AmazonEmrReleases.values()).map(v -> v.getEmrRelease())
            .collect(Collectors.toCollection(AbstractModelList<String>::new));

    String emrRelease = getJobEntry().getEmrRelease();

    if (emrRelease != null && !releases.contains(emrRelease)) {
        releases.add(0, emrRelease);
    }

    if (emrRelease == null && releases.size() > 0) {
        getJobEntry().setEmrRelease(releases.get(0));
    }
    return releases;
}

From source file:com.netflix.imfutility.itunes.audio.AudioMapXmlProvider.java

/**
 * Generates AudioOption when XML option type is empty.
 *
 * @param xmlOpt      xml option/* www.  j av  a  2  s.c o m*/
 * @param lang        expected language of audio
 * @param isMainAudio defines whether option relates to main audio or alternative
 * @return AudioOption
 */
private AudioOption generateAudioOption(Object xmlOpt, String lang, boolean isMainAudio) {
    AudioOption option = null;

    ArrayList<ChannelType> channels = channelMapper.getChannels(getMapperLayoutOption(xmlOpt, lang)).stream()
            .map(pair -> {
                ChannelType channel = new ChannelType();
                channel.setCPLVirtualTrackId(pair.getLeft().getUuid());
                channel.setCPLVirtualTrackChannel(pair.getRight());
                return channel;
            }).collect(Collectors.toCollection(ArrayList::new));

    if (channels.isEmpty()) {
        if (isMainAudio) {
            throw new ConversionException("Main audio can't be processed. "
                    + "Please check CPL or audiomap.xml, it may contain inappropriate layout or essence descriptors.");
        } else {
            logger.warn("Alternative audio for {} locale can't be processed.", lang);
        }
        return null;
    }

    if (xmlOpt instanceof Option1AType) {
        option = createOption1A(channels.toArray(new ChannelType[0]));
    } else if (xmlOpt instanceof Option2Type) {
        option = createOption2(channels.toArray(new ChannelType[0]));
    } else if (xmlOpt instanceof Option3Type) {
        option = createOption3(channels.toArray(new ChannelType[0]));
    } else if (xmlOpt instanceof Option4Type) {
        option = createOption4(channels.toArray(new ChannelType[0]));
    } else if (xmlOpt instanceof Option5Type) {
        option = createOption5(channels.toArray(new ChannelType[0]));
    } else if (xmlOpt instanceof Option6Type) {
        option = createOption6(channels.toArray(new ChannelType[0]));
    } else {
        // nothing
    }

    return option;
}

From source file:com.evolveum.midpoint.common.refinery.CompositeRefinedObjectClassDefinitionImpl.java

@NotNull
@Override/*from w w w.j av a  2  s . c o  m*/
public CompositeRefinedObjectClassDefinitionImpl deepClone(Map<QName, ComplexTypeDefinition> ctdMap,
        Map<QName, ComplexTypeDefinition> onThisPath, Consumer<ItemDefinition> postCloneAction) {
    RefinedObjectClassDefinition structuralClone = structuralObjectClassDefinition.deepClone(ctdMap, onThisPath,
            postCloneAction);
    List<RefinedObjectClassDefinition> auxiliaryClones = auxiliaryObjectClassDefinitions.stream()
            .map(def -> def.deepClone(ctdMap, onThisPath, postCloneAction))
            .collect(Collectors.toCollection(ArrayList::new));
    return new CompositeRefinedObjectClassDefinitionImpl(structuralClone, auxiliaryClones);
}