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:com.ikanow.aleph2.storm.samples.topology.JavaScriptTopology2.java

@Override
public Tuple2<Object, Map<String, String>> getTopologyAndConfiguration(DataBucketBean bucket,
        IEnrichmentModuleContext context) {
    TopologyBuilder builder = new TopologyBuilder();

    String contextSignature = context.getEnrichmentContextSignature(Optional.of(bucket), Optional.empty());

    builder.setSpout("timer", new TimerSpout(3000L));
    JavaScriptProviderBean providerBean = BeanTemplateUtils
            .from(bucket.streaming_enrichment_topology().config(), JavaScriptProviderBean.class).get();
    if (providerBean == null) {
        providerBean = new JavaScriptProviderBean();
    }/*from w ww .  ja v a 2  s  .  c  om*/
    if (null == providerBean.getGlobalScript()) {
        providerBean.setGlobalScript(
                new PropertyBasedScriptProvider("/com/ikanow/aleph2/storm/samples/script/js/scripts.properties")
                        .getGlobalScript());
    }
    BeanBasedScriptProvider mapperScriptProvider = new BeanBasedScriptProvider(providerBean);
    BeanBasedScriptProvider folderScriptProvider = new BeanBasedScriptProvider(providerBean);

    final Collection<Tuple2<BaseRichSpout, String>> entry_points = context
            .getTopologyEntryPoints(BaseRichSpout.class, Optional.of(bucket));
    entry_points.forEach(spout_name -> builder.setSpout(spout_name._2(), spout_name._1()));
    entry_points.stream().reduce(
            builder.setBolt("mapperBolt", new JavaScriptMapperBolt(contextSignature, mapperScriptProvider)),
            (acc, v) -> acc.shuffleGrouping(v._2()), (acc1, acc2) -> acc1 // (not possible in practice)
    );
    builder.setBolt("folderBolt", new JavaScriptFolderBolt(contextSignature, folderScriptProvider))
            .shuffleGrouping("mapperBolt").shuffleGrouping("timer");
    builder.setBolt("out", context.getTopologyStorageEndpoint(BaseRichBolt.class, Optional.of(bucket)))
            .localOrShuffleGrouping("folderBolt");
    return new Tuple2<Object, Map<String, String>>(builder.createTopology(), new HashMap<String, String>());
}

From source file:cc.kave.commons.pointsto.evaluation.events.MRREvaluation.java

private Set<ICoReTypeName> getQueryTypes(Collection<Map<ICompletionEvent, List<Usage>>> eventUsages) {
    List<ICoReTypeName> types = new ArrayList<>(eventUsages.stream().flatMap(eu -> eu.values().stream())
            .flatMap(u -> u.stream()).map(u -> u.getType()).collect(Collectors.toSet()));
    types.sort(new TypeNameComparator());
    return Sets.newLinkedHashSet(types);
}

From source file:org.trustedanalytics.servicecatalog.service.rest.ServicesController.java

public boolean canDeleteOffering(UUID serviceGuid) {
    final FilterQuery filter = FilterQuery.from(Filter.SERVICE_PLAN_GUID, FilterOperator.EQ, serviceGuid);
    boolean isPublic = privilegedClient.getExtendedServicePlans(serviceGuid)
            .exists(plan -> plan.getEntity().getPublicStatus()).toBlocking().single();

    boolean inAnotherOrg = privilegedClient.getExtendedServicePlanVisibility(filter)
            .distinct(visibility -> visibility.getEntity().getOrgGuid()).count().toBlocking().single() > 1;

    if (!isPublic && !inAnotherOrg) {
        return true;
    }/*from w ww . j  a va2 s .c  o m*/

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    Collection<? extends GrantedAuthority> authorities = Optional.ofNullable(auth.getAuthorities())
            .orElse(new ArrayList<>());
    return authorities.stream().map(GrantedAuthority::getAuthority).anyMatch(ADMIN_ROLE::equalsIgnoreCase);
}

From source file:com.siemens.sw360.vulnerabilities.db.VulnerabilityDatabaseHandler.java

public <T extends TBase> RequestStatus update(Collection<T> elements) {
    if (elements != null && elements.size() > 0) {
        return elements.stream().map(this::update).reduce(RequestStatus.SUCCESS, (r1, r2) -> {
            if (r1 == RequestStatus.SUCCESS && r2 == RequestStatus.SUCCESS) {
                return RequestStatus.SUCCESS;
            } else {
                return RequestStatus.FAILURE;
            }/*from   w  w w  .j ava2 s  .  com*/
        });
    }
    return RequestStatus.SUCCESS;
}

From source file:ch.sdi.report.SdiReporter.java

/**
 * @param aResult//from   ww  w .ja  v a 2 s  .  c  om
 * @param aProcessed
 */
private void appendProcessedPersons(StringBuilder aSb, Collection<ReportMsg> aProcessed) {
    appendTitle(aSb, "Processed Persons", "-");

    aProcessed.stream()
            .filter(msg -> (msg.getKey().equals("ProcessedPersons")) && msg.getValue() instanceof Collection)
            .map(msg -> Collection.class.cast(msg.getValue())).forEach(list -> appendPersonList(aSb, list));

    aSb.append("\n");
    appendTitle(aSb, "Persons already in target platform (duplicate)", "-");

    aProcessed.stream()
            .filter(msg -> (msg.getKey().equals("DuplicatePersons")) && msg.getValue() instanceof Collection)
            .map(msg -> Collection.class.cast(msg.getValue())).forEach(list -> appendPersonList(aSb, list));

}

From source file:io.github.moosbusch.lumpi.gui.form.editor.io.spi.ListButtonStoreValueDelegate.java

@SuppressWarnings("unchecked")
@Override//from w w  w  . j av  a 2 s.c o  m
public void storeValue(Object context) {
    if (context != null) {
        ListButton listButton = getFormEditor().getComponent();
        String propertyName = listButton.getListDataKey();
        ListView.ListDataBindMapping bindMapping = listButton.getListDataBindMapping();
        Object newPropertyValue = bindMapping.valueOf(listButton.getListData());

        if (PropertyUtils.isWriteable(context, propertyName)) {
            listButton.store(context);
        } else {
            Object oldPropertyValue = null;

            try {
                oldPropertyValue = PropertyUtils.getProperty(context, propertyName);
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
                Logger.getLogger(AbstractDynamicForm.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if ((newPropertyValue != null) && (oldPropertyValue != null)) {
                    if ((newPropertyValue instanceof java.util.Collection)
                            && (oldPropertyValue instanceof java.util.Collection)) {
                        java.util.Collection<Object> newColl = (java.util.Collection<Object>) newPropertyValue;
                        java.util.Collection<Object> oldColl = (java.util.Collection<Object>) oldPropertyValue;

                        newColl.stream().filter((obj) -> (!oldColl.contains(obj))).forEach((obj) -> {
                            oldColl.add(obj);
                        });
                    } else if ((newPropertyValue instanceof Sequence)
                            && (oldPropertyValue instanceof Sequence)) {
                        Sequence<Object> newSeq = (Sequence<Object>) newPropertyValue;
                        Sequence<Object> oldSeq = (Sequence<Object>) oldPropertyValue;

                        for (int cnt = 0; cnt < newSeq.getLength(); cnt++) {
                            Object obj = newSeq.get(cnt);

                            if (oldSeq.indexOf(obj) == -1) {
                                oldSeq.add(obj);
                            }
                        }
                    } else if ((newPropertyValue instanceof org.apache.pivot.collections.Set)
                            && (oldPropertyValue instanceof org.apache.pivot.collections.Set)) {
                        org.apache.pivot.collections.Set<Object> newColl = (org.apache.pivot.collections.Set<Object>) newPropertyValue;
                        org.apache.pivot.collections.Set<Object> oldColl = (org.apache.pivot.collections.Set<Object>) oldPropertyValue;

                        for (Object obj : newColl) {
                            if (!oldColl.contains(obj)) {
                                oldColl.add(obj);
                            }
                        }
                    } else if ((ObjectUtils.isArray(newPropertyValue))
                            && (ObjectUtils.isArray(oldPropertyValue))) {
                        Object[] newArray = (Object[]) newPropertyValue;
                        Object[] oldArray = (Object[]) oldPropertyValue;

                        for (Object obj : newArray) {
                            if (!ArrayUtils.contains(oldArray, obj)) {
                                oldArray = ArrayUtils.add(oldArray, obj);
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.ejisto.modules.dao.local.LocalMockedFieldsDao.java

@Override
public List<MockedField> loadByContextPathAndClassName(String contextPath, String className) {
    Collection<MockedFieldContainer> fields = getMockedFieldsByClassName(contextPath, className);
    if (CollectionUtils.isEmpty(fields)) {
        return Collections.emptyList();
    }//ww w. ja v  a  2 s .  c  om
    return fields.stream().map(new MockedFieldExtractor()).collect(toList());
}

From source file:com.thinkbiganalytics.metadata.jobrepo.nifi.provenance.NifiBulletinExceptionExtractor.java

/**
 * queries for bulletins from component, in the flow file
 *
 * @param flowFileIds The collection UUID of the flow file to extract the error message from
 * @return a list of bulletin objects that were posted by the component to the flow file
 * @throws NifiConnectionException if cannot query Nifi
 *///from www  .j  a v  a2  s  . c  o m
public List<BulletinDTO> getErrorBulletinsForFlowFiles(Collection<String> flowFileIds, Long afterId)
        throws NifiConnectionException {
    List<BulletinDTO> bulletins;
    try {
        String regexPattern = flowFileIds.stream().collect(Collectors.joining("|"));
        if (afterId != null && afterId != -1L) {
            bulletins = nifiRestClient.getBulletinsMatchingMessage(regexPattern, afterId);
        } else {
            bulletins = nifiRestClient.getBulletinsMatchingMessage(regexPattern);
        }
        log.info("Query for {} bulletins returned {} results ", regexPattern, bulletins.size());
        if (bulletins != null && !bulletins.isEmpty()) {
            bulletins = bulletins.stream()
                    .filter(bulletinDTO -> bulletinErrorLevels.contains(bulletinDTO.getLevel().toUpperCase()))
                    .collect(Collectors.toList());
        }

        return bulletins;
    } catch (NifiClientRuntimeException e) {
        if (e instanceof NifiConnectionException) {
            throw e;
        } else {
            log.error("Error getProcessorBulletinsForFlowFiles {}, {}", flowFileIds, e.getMessage());
        }
    }
    return null;
}

From source file:it.publisys.ims.discovery.job.EntityTasks.java

private List<File> loadMetadataXml(File dir) {
    Collection<File> filesAndDirs = FileUtils.listFilesAndDirs(dir, FileFilterUtils.suffixFileFilter(".xml"),
            FileFilterUtils.suffixFileFilter("-guard"));

    return filesAndDirs.stream().filter(File::isFile).collect(Collectors.toList());
}

From source file:com.spankingrpgs.scarletmoon.loader.EventLoader.java

@Override
public void load(Collection<String> eventData, GameState state) {
    eventData.stream().forEach(datum -> loadEvent(datum, state));
}