Example usage for java.util Set forEach

List of usage examples for java.util Set forEach

Introduction

In this page you can find the example usage for java.util Set forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:org.artifactory.api.license.ModuleLicenseModel.java

/**
 * return scope in view table format//from w ww  . j av a 2 s.  c  o m
 * @param scopes
 */
private void ScopeForView(Set<String> scopes) {
    if (scopes != null && !scopes.isEmpty()) {
        StringBuilder scopesBuilder = new StringBuilder();
        scopes.forEach(scope -> scopesBuilder.append(scope + " , "));
        String scopeString = scopesBuilder.toString();
        if (scopeString.length() > 0) {
            scopeNames = scopeString.substring(0, scopesBuilder.toString().length() - 3);
        }
    }
}

From source file:com.github.mrstampy.gameboot.web.WebProcessor.java

@Override
public void onDisconnection(HttpSession httpSession) throws Exception {
    String id = httpSession.getId();

    SystemIdKey systemId = systemIds.remove(id);
    cleaner.cleanup(systemId);//from ww w .j  ava 2  s.c o m

    Set<Entry<AbstractRegistryKey<?>, HttpSession>> set = registry.getKeysForValue(httpSession);

    set.forEach(e -> registry.remove(e.getKey()));
}

From source file:fi.vm.kapa.identification.adapter.service.SessionParserService.java

@PostConstruct
public void initSessionParser() {
    tupasProperties = propertyMapper.getTupasProperties();
    tupasFormTemplate = propertyMapper.getTupasFormTemplate();
    Set<Map.Entry<String, String>> tupasEntries = tupasProperties.entrySet().stream()
            .filter(entry -> entry.getKey().startsWith("BANK_URL_TFI_")).collect(Collectors.toSet());
    tupasEntries
            .forEach(entry -> declRefs.put(entry.getValue(), entry.getKey().replaceFirst("BANK_URL_TFI_", "")));
}

From source file:org.onosproject.cpman.rest.ControlMetricsWebResource.java

/**
 * Returns a collection of control loads of the given control metric types.
 *
 * @param service control plane monitoring service
 * @param nodeId  node identification//from  www. ja va 2  s  . com
 * @param typeSet a group of control metric types
 * @param name    resource name
 * @param did     device identification
 * @return a collection of control loads
 */
private ArrayNode metricsStats(ControlPlaneMonitorService service, NodeId nodeId,
        Set<ControlMetricType> typeSet, String name, DeviceId did, ObjectNode node) {
    ArrayNode metricsNode = node.putArray("metrics");

    if (name == null && did == null) {
        typeSet.forEach(type -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, type, Optional.empty());
            processRest(cls, type, metricsNode);
        });
    } else if (name == null) {
        typeSet.forEach(type -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, type, Optional.of(did));
            processRest(cls, type, metricsNode);
        });
    } else if (did == null) {
        typeSet.forEach(type -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, type, name);
            processRest(cls, type, metricsNode);
        });
    }

    return metricsNode;
}

From source file:org.apache.bookkeeper.stream.storage.impl.sc.DefaultStorageContainerControllerTest.java

@Test
public void testComputeIdealStateWhenHostsRemovedAdded() throws Exception {
    ClusterAssignmentData emptyAssignment = ClusterAssignmentData.newBuilder().build();

    int numServers = 4;
    Set<BookieSocketAddress> currentCluster = newCluster(numServers);

    ClusterAssignmentData assignmentData = controller.computeIdealState(clusterMetadata, emptyAssignment,
            currentCluster);/*from   ww w  .j  a v  a  2 s  . c o m*/
    verifyAssignmentData(assignmentData, currentCluster, true);

    Set<BookieSocketAddress> serversToAdd = newCluster(6, numServers);
    Set<BookieSocketAddress> serversToRemove = newCluster(2);

    Set<BookieSocketAddress> newCluster = Sets.newHashSet(currentCluster);
    newCluster.addAll(serversToAdd);
    serversToRemove.forEach(newCluster::remove);

    ClusterAssignmentData newAssignmentData = controller.computeIdealState(clusterMetadata, assignmentData,
            newCluster);
    verifyAssignmentData(newAssignmentData, newCluster, false);
}

From source file:io.gravitee.gateway.services.sync.SyncManager.java

public void refresh() {
    logger.debug("Refreshing gateway state...");

    try {/*from  w  w w .  j  ava 2s . c o m*/
        Set<io.gravitee.repository.management.model.Api> apis = apiRepository.findAll();

        // Determine deployed APIs store into events payload
        Set<Api> deployedApis = getDeployedApis(apis);

        Map<String, Api> apisMap = deployedApis.stream().filter(api -> api != null && hasMatchingTags(api))
                .collect(Collectors.toMap(Api::getId, api -> api));

        // Determine APIs to undeploy
        Set<String> apiToRemove = apiManager.apis().stream()
                .filter(api -> !apisMap.containsKey(api.getId()) || !hasMatchingTags(api)).map(Api::getId)
                .collect(Collectors.toSet());

        apiToRemove.forEach(apiManager::undeploy);

        // Determine APIs to update
        apisMap.keySet().stream().filter(apiId -> apiManager.get(apiId) != null).forEach(apiId -> {
            // Get local cached API
            Api deployedApi = apiManager.get(apiId);

            // Get API from store
            Api remoteApi = apisMap.get(apiId);

            if (deployedApi.getDeployedAt().before(remoteApi.getDeployedAt())) {
                apiManager.update(remoteApi);
            }
        });

        // Determine APIs to deploy
        apisMap.keySet().stream().filter(api -> apiManager.get(api) == null).forEach(api -> {
            Api newApi = apisMap.get(api);
            apiManager.deploy(newApi);
        });
    } catch (TechnicalException te) {
        logger.error("Unable to sync instance", te);
    }
}

From source file:com.epam.dlab.backendapi.service.impl.LibraryServiceImpl.java

@SuppressWarnings("unchecked")
private Document getLibsOfActiveComputationalResources(Document document) {
    Document computationalLibs = (Document) document.get(ExploratoryLibDAO.COMPUTATIONAL_LIBS);

    if (document.get(ExploratoryDAO.COMPUTATIONAL_RESOURCES) != null) {
        List<Document> computationalResources = (List<Document>) document
                .get(ExploratoryDAO.COMPUTATIONAL_RESOURCES);

        Set<String> terminated = computationalResources.stream().filter(
                doc -> doc.getString(BaseDAO.STATUS).equalsIgnoreCase(UserInstanceStatus.TERMINATED.toString()))
                .map(doc -> doc.getString("computational_name")).collect(Collectors.toSet());

        terminated.forEach(computationalLibs::remove);
    }//from   w  w  w .  java 2  s. c  om

    return computationalLibs;
}

From source file:nl.knaw.huygens.alexandria.dropwizard.cli.commands.AlexandriaCommand.java

void showChanges(Multimap<FileStatus, String> fileStatusMap) {
    AnsiConsole.systemInstall();/*from   w  w  w  .  ja v  a  2s  .  c  o m*/

    Set<String> changedFiles = new HashSet<>(fileStatusMap.get(FileStatus.changed));
    Set<String> deletedFiles = new HashSet<>(fileStatusMap.get(FileStatus.deleted));
    if (!(changedFiles.isEmpty() && deletedFiles.isEmpty())) {
        System.out.printf("Uncommitted changes:%n"
                + "  (use \"alexandria commit <file>...\" to commit the selected changes)%n"
                + "  (use \"alexandria commit -a\" to commit all changes)%n"
                + "  (use \"alexandria revert <file>...\" to discard changes)%n%n");
        Set<String> changedOrDeletedFiles = new TreeSet<>();
        changedOrDeletedFiles.addAll(changedFiles);
        changedOrDeletedFiles.addAll(deletedFiles);
        changedOrDeletedFiles.forEach(file -> {
            String status = changedFiles.contains(file) ? "        modified: " : "        deleted:  ";
            System.out.println(ansi().fg(RED).a(status).a(file).reset());
        });
    }

    Collection<String> createdFiles = fileStatusMap.get(FileStatus.created);
    if (!createdFiles.isEmpty()) {
        System.out.printf(
                "Untracked files:%n" + "  (use \"alexandria add <file>...\" to start tracking this file.)%n%n");
        createdFiles.stream().sorted()
                .forEach(f -> System.out.println(ansi().fg(RED).a("        ").a(f).reset()));
    }

    AnsiConsole.systemUninstall();
}

From source file:nu.yona.server.batch.quartz.JobManagementService.java

@Transactional
public Set<JobDto> updateJobGroup(String group, Set<JobDto> jobs) {
    try {// w w  w  . ja  va  2s .c om
        Set<String> jobNamesToBe = jobs.stream().map(JobDto::getName).collect(toSet());
        Set<JobKey> existingJobs = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group));
        Set<JobKey> keysOfJobsToDelete = existingJobs.stream().filter(jk -> !contains(jobNamesToBe, jk))
                .collect(toSet());
        Set<JobDto> jobsToUpdate = jobs.stream().filter(j -> contains(existingJobs, group, j)).collect(toSet());
        Set<JobDto> jobsToAdd = jobs.stream().filter(j -> !contains(existingJobs, group, j)).collect(toSet());

        keysOfJobsToDelete.forEach(jk -> deleteJob(jk.getGroup(), jk.getName()));
        jobsToUpdate.forEach(j -> updateJob(group, j));
        jobsToAdd.forEach(j -> addJob(group, j));

        return getJobsInGroup(group);
    } catch (SchedulerException e) {
        throw YonaException.unexpected(e);
    }
}

From source file:com.github.mrstampy.gameboot.websocket.AbstractWebSocketProcessor.java

@Override
public void onDisconnection(WebSocketSession session) throws Exception {
    String id = session.getId();/*from ww w  .  jav a 2  s .  co  m*/

    SystemIdKey systemId = systemIds.remove(id);
    cleaner.cleanup(systemId);

    Set<Entry<AbstractRegistryKey<?>, WebSocketSession>> set = registry.getKeysForValue(session);

    set.forEach(e -> registry.remove(e.getKey()));
}