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:org.hawkular.alerter.prometheus.PrometheusAlerter.java

private void initialRefresh() {
    try {/* ww  w.j  a v  a2 s. c  o  m*/
        Collection<Trigger> triggers = definitions.getAllTriggersByTag(ALERTER_ID, "*");
        triggers.stream().forEach(
                trigger -> activeTriggers.put(new TriggerKey(trigger.getTenantId(), trigger.getId()), trigger));
        update();
    } catch (Exception e) {
        log.error("Failed to fetch Triggers for external conditions.", e);
    }
}

From source file:simx.profiler.discovery.latency.LatencyReportTopComponent.java

@Override
public void resultChanged(LookupEvent le) {
    Collection<? extends LatencyReport> allSelectedTypes = result.allInstances();
    if (!allSelectedTypes.isEmpty()) {
        allSelectedTypes.stream().forEach((type) -> {
            this.setData(type);
        });/*from  w ww .  j a va 2  s  .  co  m*/
    } else {
        System.out.println("No selection");
    }
}

From source file:org.hawkular.alerter.elasticsearch.ElasticsearchAlerter.java

private void initialRefresh() {
    try {/* w  ww .j av  a2s  . c  o m*/
        Collection<Trigger> triggers = definitions.getAllTriggersByTag(ALERTER_NAME, "*");
        triggers.stream().forEach(
                trigger -> activeTriggers.put(new TriggerKey(trigger.getTenantId(), trigger.getId()), trigger));
        update();
    } catch (Exception e) {
        log.error("Failed to fetch Triggers for external conditions.", e);
    }
}

From source file:org.kie.appformer.ala.wildfly.executor.AppFormerProvisioningHelper.java

public DataSourceDef findDataSourceDef(String uuid) {
    Collection<DataSourceDefInfo> defInfoList = dataSourceDefQueryService.findGlobalDataSources(false);
    Optional<DataSourceDefInfo> defInfo = defInfoList.stream()
            .filter(_defInfo -> uuid.equals(_defInfo.getUuid())).findFirst();
    if (defInfo.isPresent()) {
        DataSourceDefEditorContent content = dataSourceDefEditorService.loadContent(defInfo.get().getPath());
        return content != null ? content.getDef() : null;
    } else {/*from  w  w w.  j a v  a  2  s.com*/
        return null;
    }
}

From source file:com._4dconcept.springframework.data.marklogic.core.query.QueryBuilder.java

@Nullable
private Criteria buildCriteria(MarklogicPersistentProperty property, Object value) {
    Optional<? extends TypeInformation<?>> typeInformation = StreamSupport
            .stream(property.getPersistentEntityTypes().spliterator(), false).findFirst();
    if (typeInformation.isPresent()) {
        MarklogicPersistentEntity<?> nestedEntity = mappingContext.getPersistentEntity(typeInformation.get());
        return nestedEntity != null ? buildCriteria(value, nestedEntity) : null;
    } else {//from ww  w . ja  v a  2s  . com
        Criteria criteria = new Criteria();

        if (value instanceof Collection) {
            criteria.setOperator(Criteria.Operator.or);
            Collection<?> collection = (Collection<?>) value;
            criteria.setCriteriaObject(
                    collection.stream().map(o -> buildCriteria(property, o)).collect(Collectors.toList()));
        } else {
            criteria.setQname(property.getQName());
            criteria.setCriteriaObject(value);
        }

        return criteria;
    }
}

From source file:com.yahoo.elide.parsers.state.RelationshipTerminalState.java

private boolean delete(Data<Resource> data, RequestScope requestScope) {
    if (data == null) {
        throw new InvalidEntityBodyException("Expected data but received null");
    }/* w ww  . j av a2  s. c  o m*/

    Collection<Resource> resources = data.get();
    if (resources == null || resources.isEmpty()) {
        // As per: http://jsonapi.org/format/#crud-updating-relationship-responses-403
        throw new ForbiddenAccessException("Unknown update");
    }
    resources.stream().forEachOrdered(
            resource -> record.removeRelation(relationshipName, resource.toPersistentResource(requestScope)));
    return true;
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesV2OnDemandCachingAgent.java

@Override
public Collection<Map> pendingOnDemandRequests(ProviderCache providerCache) {
    Collection<String> keys = providerCache.getIdentifiers(ON_DEMAND_TYPE);
    List<Keys.InfrastructureCacheKey> infraKeys = keys.stream().map(Keys::parseKey)
            .flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
            .filter(k -> k instanceof Keys.InfrastructureCacheKey).map(i -> (Keys.InfrastructureCacheKey) i)
            .collect(Collectors.toList());

    List<String> matchingKeys = infraKeys.stream()
            .filter(i -> i.getAccount().equals(getAccountName()) && (StringUtils.isEmpty(i.getNamespace()))
                    || namespaces.contains(i.getNamespace()) && primaryKinds().contains(i.getKubernetesKind()))
            .map(Keys.InfrastructureCacheKey::toString).collect(Collectors.toList());

    return providerCache.getAll(ON_DEMAND_TYPE, matchingKeys).stream().map(cd -> {
        Keys.InfrastructureCacheKey parsedKey = (Keys.InfrastructureCacheKey) Keys.parseKey(cd.getId()).get();
        Map<String, String> details = mapKeyToOnDemandResult(parsedKey);
        Map<String, Object> attributes = cd.getAttributes();
        return new ImmutableMap.Builder<String, Object>().put(DETAILS_KEY, details)
                .put(MONIKER_KEY, attributes.get(MONIKER_KEY))
                .put(CACHE_TIME_KEY, attributes.get(CACHE_TIME_KEY))
                .put(PROCESSED_COUNT_KEY, attributes.get(PROCESSED_COUNT_KEY))
                .put(PROCESSED_TIME_KEY, attributes.get(PROCESSED_TIME_KEY)).build();
    }).collect(Collectors.toList());
}

From source file:io.gravitee.management.service.impl.PageServiceImpl.java

private void reorderAndSavePages(final Page pageToReorder) throws TechnicalException {
    final Collection<Page> pages = pageRepository.findByApi(pageToReorder.getApi());
    final List<Boolean> increment = asList(true);
    pages.stream().sorted((o1, o2) -> Integer.compare(o1.getOrder(), o2.getOrder())).forEachOrdered(page -> {
        try {//from ww  w .j a va 2s  . c  o m
            if (page.equals(pageToReorder)) {
                increment.set(0, false);
                page.setOrder(pageToReorder.getOrder());
            } else {
                final int newOrder;
                final Boolean isIncrement = increment.get(0);
                if (page.getOrder() < pageToReorder.getOrder()) {
                    newOrder = page.getOrder() - (isIncrement ? 0 : 1);
                } else if (page.getOrder() > pageToReorder.getOrder()) {
                    newOrder = page.getOrder() + (isIncrement ? 1 : 0);
                } else {
                    newOrder = page.getOrder() + (isIncrement ? 1 : -1);
                }
                page.setOrder(newOrder);
            }
            pageRepository.update(page);
        } catch (final TechnicalException ex) {
            throw onUpdateFail(page.getId(), ex);
        }
    });
}

From source file:com.openshift.internal.restclient.model.v1.ReplicationControllerTest.java

@Test
public void testEnvironmentVariable() {
    //add/*from   w  w  w .jav  a2  s.c om*/
    rc.setEnvironmentVariable("foo", "bar");
    Collection<IEnvironmentVariable> envVars = rc.getEnvironmentVariables();
    Optional<IEnvironmentVariable> envVar = envVars.stream().filter(e -> "foo".equals(e.getName())).findFirst();
    assertTrue("Exp. to find env var", envVar.isPresent());
    assertEquals("bar", envVar.get().getValue());

    //update
    int size = rc.getEnvironmentVariables().size();
    rc.setEnvironmentVariable("foo", "baz");
    assertEquals(size, rc.getEnvironmentVariables().size());
    envVars = rc.getEnvironmentVariables();
    envVar = envVars.stream().filter(e -> "foo".equals(e.getName())).findFirst();
    assertEquals("baz", envVar.get().getValue());

    rc.removeEnvironmentVariable("foo");
    assertEquals(size - 1, rc.getEnvironmentVariables().size());
}

From source file:ch.wisv.areafiftylan.teams.service.TeamServiceImpl.java

private List<TeamInviteResponse> teamInviteTokensToReponses(Collection<TeamInviteToken> inviteTokens) {
    // From all Tokens that exist in the database linked to the user, only display the valid ones. Change
    // them to TeamInviteResponses for display in the authentication.
    return inviteTokens
            .stream().filter(Token::isValid).map(t -> new TeamInviteResponse(t.getTeam().getId(),
                    t.getTeam().getTeamName(), t.getToken(), t.getUser().getUsername()))
            .collect(Collectors.toList());
}