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.hortonworks.streamline.streams.cluster.resource.ClusterCatalogResource.java

private void assertNoNamespaceRefersCluster(Long clusterId) {
    Collection<Namespace> namespaces = environmentService.listNamespaces();
    if (namespaces != null) {
        for (Namespace namespace : namespaces) {
            Collection<NamespaceServiceClusterMap> mappings = environmentService
                    .listServiceClusterMapping(namespace.getId());
            if (mappings != null) {
                boolean matched = mappings.stream().anyMatch(m -> Objects.equals(m.getClusterId(), clusterId));
                if (matched) {
                    throw BadRequestException.message(
                            "Namespace refers the cluster trying to remove - cluster id: " + clusterId);
                }/*ww  w  .  j a  va  2 s .c om*/
            }
        }
    }
}

From source file:com.hortonworks.streamline.streams.service.NamespaceCatalogResource.java

@DELETE
@Path("/namespaces/{id}/mapping/{serviceName}/cluster/{clusterId}")
@Timed//ww w .  jav a  2s. c om
public Response unmapServiceToClusterInNamespace(@PathParam("id") Long namespaceId,
        @PathParam("serviceName") String serviceName, @PathParam("clusterId") Long clusterId,
        @Context SecurityContext securityContext) {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN,
            Namespace.NAMESPACE, namespaceId, WRITE);
    Namespace namespace = environmentService.getNamespace(namespaceId);
    if (namespace == null) {
        throw EntityNotFoundException.byId(namespaceId.toString());
    }

    String streamingEngine = namespace.getStreamingEngine();
    Collection<NamespaceServiceClusterMapping> mappings = environmentService
            .listServiceClusterMapping(namespaceId);
    boolean containsStreamingEngine = mappings.stream()
            .anyMatch(m -> m.getServiceName().equals(streamingEngine));
    // check topology running only streaming engine exists
    if (serviceName.equals(streamingEngine) && containsStreamingEngine) {
        assertNoTopologyReferringNamespaceIsRunning(namespaceId,
                WSUtils.getUserFromSecurityContext(securityContext));
    }

    NamespaceServiceClusterMapping mapping = environmentService.removeServiceClusterMapping(namespaceId,
            serviceName, clusterId);
    if (mapping != null) {
        return WSUtils.respondEntity(mapping, OK);
    }

    throw EntityNotFoundException.byId(buildMessageForCompositeId(namespaceId, serviceName, clusterId));
}

From source file:ddf.catalog.history.Historian.java

private Map<String, List<ContentItem>> getContent(Collection<ReadStorageRequest> ids) {
    return ids.stream().map(this::getStorageItem).filter(Objects::nonNull)
            .map(ReadStorageResponse::getContentItem).filter(Objects::nonNull)
            .collect(Collectors.toMap(ContentItem::getId, Lists::newArrayList, (l, r) -> {
                l.addAll(r);//from ww  w  .  j  a v  a2s. c  o m
                return l;
            }));
}

From source file:uk.dsxt.voting.client.ClientManager.java

public RequestResult getVotings(String clientId) {
    final Collection<Voting> votings = assetsHolder.getVotings().stream()
            .filter(v -> assetsHolder.getClientPacketSize(v.getId(), clientId) == null
                    || assetsHolder.getClientPacketSize(v.getId(), clientId).compareTo(BigDecimal.ZERO) > 0)
            .collect(Collectors.toSet());
    return new RequestResult<>(
            votings.stream().map(v -> new VotingWeb(v, assetsHolder.getClientVote(v.getId(), clientId) == null))
                    .collect(Collectors.toList()).toArray(new VotingWeb[votings.size()]),
            null);//from  w  ww  .ja va  2  s . com
}

From source file:com.hp.autonomy.frontend.configuration.server.ServerConfig.java

private boolean testServerVersion(final AciService aciService, final ProcessorFactory processorFactory) {
    // Community's ProductName is just IDOL, so we need to check the product type
    final GetVersionResponseData versionResponseData = aciService.executeAction(toAciServerDetails(),
            new AciParameters(GeneralActions.GetVersion.name()),
            processorFactory.getResponseDataProcessor(GetVersionResponseData.class));

    final Collection<String> serverProductTypes = new HashSet<>(
            Arrays.asList(versionResponseData.getProducttypecsv().split(",")));

    return productTypeRegex == null ? productType.stream().anyMatch(p -> serverProductTypes.contains(p.name()))
            : serverProductTypes.stream()
                    .anyMatch(serverProductType -> productTypeRegex.matcher(serverProductType).matches());
}

From source file:com.example.app.profile.model.location.LocationDAO.java

/**
 * Set the status of the specified locations.
 *
 * @param locations the locations to update
 * @param status the new status// w  ww.j  av a 2  s. co  m
 */
public void setLocationStatus(final Collection<? extends Location> locations, final LocationStatus status) {
    doInTransaction(session -> {
        final String hql = "update " + Location.class.getName() + " location" + " set location."
                + Location.STATUS_PROP + " = :status" + " where location in :locations";

        final Query query = session.createQuery(hql);
        query.setParameter("status", status);
        query.setParameterList("locations", locations.stream().map(Location::getId).toArray(Integer[]::new));

        query.executeUpdate();
    });
}

From source file:com.thinkbiganalytics.feedmgr.rest.controller.NifiIntegrationRestController.java

/**
 * get all referencing components in a single hashmap
 *
 * @param references references/* ww  w .  j  av  a 2 s  .c om*/
 * @return the map of id to component entity
 */
private Map<String, ControllerServiceReferencingComponentEntity> getReferencingComponents(
        Collection<ControllerServiceReferencingComponentEntity> references) {
    Map<String, ControllerServiceReferencingComponentEntity> map = new HashMap<>();
    references.stream().forEach(c -> {
        map.put(c.getId(), c);
        if (c.getComponent().getReferencingComponents() != null
                && !c.getComponent().getReferencingComponents().isEmpty()) {
            map.putAll(getReferencingComponents(c.getComponent().getReferencingComponents()));
        }
    });
    return map;
}

From source file:fr.paris.lutece.portal.web.admin.AdminPageJspBeanTest.java

@Override
protected void tearDown() throws Exception {
    IPageService pageService = (IPageService) SpringContextService.getBean("pageService");
    if (_page != null) {
        try {/* w w w .j  a  v a  2  s .  com*/
            Collection<Page> children = PageHome.getChildPages(_page.getId());
            children.stream().forEach(page -> pageService.removePage(page.getId()));
            pageService.removePage(_page.getId());
        } finally {
        }
    }
    removeUser(_adminUser);
    super.tearDown();
}

From source file:com.github.drbookings.model.data.manager.MainManager.java

public Optional<BookingEntry> getAfter(BookingEntry e) {
    LocalDate plusOneDay = e.getDate().plusDays(1);
    Room room = e.getRoom();/*w w  w. j  a  v a  2  s  . c o m*/
    Collection<BookingEntry> bookingsThatDay = bookingEntries.get(plusOneDay);
    if (bookingsThatDay != null) {
        return bookingsThatDay.stream().filter(b -> b.getRoom().equals(room)).findFirst();
    }
    return Optional.empty();
}

From source file:com.github.drbookings.model.data.manager.MainManager.java

public Optional<BookingEntry> getBefore(BookingEntry e) {
    LocalDate plusOneDay = e.getDate().minusDays(1);
    Room room = e.getRoom();//from   ww  w . ja va 2  s  .co  m
    Collection<BookingEntry> bookingsThatDay = bookingEntries.get(plusOneDay);
    if (bookingsThatDay != null) {
        return bookingsThatDay.stream().filter(b -> b.getRoom().equals(room)).findFirst();
    }
    return Optional.empty();
}