Example usage for java.util.stream Collectors toSet

List of usage examples for java.util.stream Collectors toSet

Introduction

In this page you can find the example usage for java.util.stream Collectors toSet.

Prototype

public static <T> Collector<T, ?, Set<T>> toSet() 

Source Link

Document

Returns a Collector that accumulates the input elements into a new Set .

Usage

From source file:eu.itesla_project.merge.MergeByDateTool.java

@Override
public void run(CommandLine line) throws Exception {
    ComponentDefaultConfig defaultConfig = ComponentDefaultConfig.load();
    CaseRepository caseRepository = defaultConfig.newFactoryImpl(CaseRepositoryFactory.class)
            .create(LocalComputationManager.getDefault());
    LoadFlowFactory loadFlowFactory = defaultConfig.newFactoryImpl(LoadFlowFactory.class);
    MergeOptimizerFactory mergeOptimizerFactory = defaultConfig.newFactoryImpl(MergeOptimizerFactory.class);
    Set<Country> countries = Arrays.stream(line.getOptionValue("countries").split(",")).map(Country::valueOf)
            .collect(Collectors.toSet());
    DateTime date = DateTime.parse(line.getOptionValue("date"));
    Path outputDir = Paths.get(line.getOptionValue("output-dir"));
    String outputFormat = line.getOptionValue("output-format");
    Exporter exporter = Exporters.getExporter(outputFormat);
    if (exporter == null) {
        throw new RuntimeException("Format " + outputFormat + " not supported");
    }//w w w  .  ja  va 2  s  .  c  o  m
    boolean optimize = line.hasOption("optimize");

    System.out.println("merging...");

    Network merge = MergeUtil.merge(caseRepository, date, CaseType.SN, countries, loadFlowFactory, 0,
            mergeOptimizerFactory, LocalComputationManager.getDefault(), optimize);

    System.out.println("exporting...");

    String baseName = merge.getId().replace(" ", "_");
    exporter.export(merge, null, new FileDataSource(outputDir, baseName));
}

From source file:io.gravitee.repository.redis.management.internal.impl.ApplicationRedisRepositoryImpl.java

@Override
public Set<RedisApplication> findByGroups(List<String> groups) {
    Set<Object> keys = new HashSet<>();
    groups.forEach(group -> keys.addAll(redisTemplate.opsForSet().members(REDIS_KEY + ":group:" + group)));
    List<Object> apiObjects = redisTemplate.opsForHash().multiGet(REDIS_KEY, keys);

    return apiObjects.stream().map(event -> convert(event, RedisApplication.class)).collect(Collectors.toSet());
}

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//www.ja v a2 s. c om
            .forEach(entry -> declRefs.put(entry.getValue(), entry.getKey().replaceFirst("BANK_URL_TFI_", "")));
}

From source file:ddf.catalog.transformer.csv.common.CsvTransformerTest.java

@Test
public void getAllCsvAttributeDescriptors() {
    Set<AttributeDescriptor> allAttributes = CsvTransformer.getAllCsvAttributeDescriptors(metacardList);
    assertThat(allAttributes, hasSize(6));
    Set<String> allAttributeNames = allAttributes.stream().map(AttributeDescriptor::getName)
            .collect(Collectors.toSet());
    // Binary and Object types are filtered
    final Set<String> expectedAttributes = Sets.newHashSet("attribute1", "attribute2", "attribute3",
            "attribute4", "attribute5", "attribute6");
    assertThat(allAttributeNames, is(expectedAttributes));
}

From source file:nu.yona.server.device.service.DeviceService.java

@Transactional
public Set<DeviceBaseDto> getDevicesOfUser(UUID userId) {
    return userService.getUserEntityById(userId).getDevices().stream().map(UserDeviceDto::createInstance)
            .collect(Collectors.toSet());
}

From source file:com.vsct.dt.hesperides.resources.HesperidesModuleResource.java

@Path("/{module_name}")
@GET// w ww.j a v  a  2  s .co m
@Timed
@ApiOperation("Get all versions for a given module")
public Collection<String> getModuleVersions(@Auth final User user,
        @PathParam("module_name") final String moduleName) {
    checkQueryParameterNotEmpty("module_name", moduleName);

    return modules.getAllModules().stream().filter(e -> e.getName().equals(moduleName)).map(Module::getVersion)
            .collect(Collectors.toSet());
}

From source file:org.n52.iceland.request.operator.RequestOperatorRepository.java

public Set<RequestOperator> getActiveRequestOperators(ServiceOperatorKey sok) {
    return activeRequestOperatorStream(sok).map(Entry::getValue).map(Producer::get).collect(Collectors.toSet());
}

From source file:eu.itesla_project.online.tools.PrintOnlineWorkflowViolationsTool.java

@Override
public void run(CommandLine line) throws Exception {
    OnlineConfig config = OnlineConfig.load();
    String workflowId = line.getOptionValue("workflow");
    final LimitViolationFilter violationsFilter = (line.hasOption("type"))
            ? new LimitViolationFilter(Arrays.stream(line.getOptionValue("type").split(","))
                    .map(LimitViolationType::valueOf).collect(Collectors.toSet()), 0)
            : null;/*from w  w w.  ja v  a 2  s  .  co m*/
    TableFormatterConfig tableFormatterConfig = TableFormatterConfig.load();
    Column[] tableColumns = { new Column("State"), new Column("Step"), new Column("Equipment"),
            new Column("Type"), new Column("Value"), new Column("Limit"), new Column("Limit reduction"),
            new Column("Voltage Level") };
    Path cvsOutFile = (line.hasOption("csv")) ? Paths.get(line.getOptionValue("csv")) : null;
    try (OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create()) {
        if (line.hasOption("state") && line.hasOption("step")) {
            Integer stateId = Integer.parseInt(line.getOptionValue("state"));
            OnlineStep step = OnlineStep.valueOf(line.getOptionValue("step"));
            List<LimitViolation> violationsByStateAndStep = onlinedb.getViolations(workflowId, stateId, step);
            if (violationsByStateAndStep != null && !violationsByStateAndStep.isEmpty()) {
                try (TableFormatter formatter = PrintOnlineWorkflowUtils.createFormatter(tableFormatterConfig,
                        cvsOutFile, TABLE_TITLE, tableColumns)) {
                    printStateStepViolations(formatter, stateId, step, violationsByStateAndStep,
                            violationsFilter);
                }
            } else {
                System.out.println("\nNo violations for workflow " + workflowId + ", step " + step.name()
                        + " and state " + stateId);
            }
        } else if (line.hasOption("state")) {
            Integer stateId = Integer.parseInt(line.getOptionValue("state"));
            Map<OnlineStep, List<LimitViolation>> stateViolations = onlinedb.getViolations(workflowId, stateId);
            if (stateViolations != null && !stateViolations.keySet().isEmpty()) {
                try (TableFormatter formatter = PrintOnlineWorkflowUtils.createFormatter(tableFormatterConfig,
                        cvsOutFile, TABLE_TITLE, tableColumns)) {
                    new TreeMap<>(stateViolations)
                            .forEach((onlineStep, violations) -> printStateStepViolations(formatter, stateId,
                                    onlineStep, violations, violationsFilter));
                }
            } else {
                System.out.println("\nNo violations for workflow " + workflowId + " and state " + stateId);
            }
        } else if (line.hasOption("step")) {
            OnlineStep step = OnlineStep.valueOf(line.getOptionValue("step"));
            Map<Integer, List<LimitViolation>> stepViolations = onlinedb.getViolations(workflowId, step);
            if (stepViolations != null && !stepViolations.keySet().isEmpty()) {
                try (TableFormatter formatter = PrintOnlineWorkflowUtils.createFormatter(tableFormatterConfig,
                        cvsOutFile, TABLE_TITLE, tableColumns)) {
                    new TreeMap<>(stepViolations)
                            .forEach((stateId, violations) -> printStateStepViolations(formatter, stateId, step,
                                    violations, violationsFilter));
                }
            } else {
                System.out.println("\nNo violations for workflow " + workflowId + " and step " + step);
            }
        } else {
            Map<Integer, Map<OnlineStep, List<LimitViolation>>> workflowViolations = onlinedb
                    .getViolations(workflowId);
            if (workflowViolations != null && !workflowViolations.keySet().isEmpty()) {
                try (TableFormatter formatter = PrintOnlineWorkflowUtils.createFormatter(tableFormatterConfig,
                        cvsOutFile, TABLE_TITLE, tableColumns)) {
                    new TreeMap<>(workflowViolations).forEach((stateId, stateViolations) -> {
                        if (stateViolations != null) {
                            new TreeMap<>(stateViolations)
                                    .forEach((step, violations) -> printStateStepViolations(formatter, stateId,
                                            step, violations, violationsFilter));
                        }
                    });
                }
            } else {
                System.out.println("\nNo violations for workflow " + workflowId);
            }
        }
    }
}

From source file:fi.hsl.parkandride.back.UtilizationDao.java

@TransactionalRead
@Override/*from  ww w  . j  a v a2  s  .  c  o m*/
public Set<Utilization> findLatestUtilization(long facilityId) {
    // TODO: do with a single query
    List<Tuple> utilizationKeyCombinations = queryFactory.from(qUtilization)
            .where(qUtilization.facilityId.eq(facilityId)).select(qUtilization.capacityType, qUtilization.usage)
            .distinct().fetch();
    return utilizationKeyCombinations.stream()
            .map(utilizationKey -> queryFactory.from(qUtilization).select(utilizationMapping)
                    .where(qUtilization.facilityId.eq(facilityId),
                            qUtilization.capacityType.eq(utilizationKey.get(qUtilization.capacityType)),
                            qUtilization.usage.eq(utilizationKey.get(qUtilization.usage)))
                    .orderBy(qUtilization.ts.desc()).fetchFirst())
            .collect(Collectors.toSet());
}

From source file:it.smartcommunitylab.aac.controller.AppController.java

/**
 * Retrieve the with the user data: currently on the username is added.
 * @return/*from   w  w  w .j a  v  a2 s  .c o  m*/
 */
@RequestMapping("/dev")
public ModelAndView developer() {
    Map<String, Object> model = new HashMap<String, Object>();

    String username = userManager.getUserFullName();
    model.put("username", username);
    Set<String> userRoles = userManager.getUserRoles();
    model.put("roles", userRoles);
    model.put("contexts",
            userManager.getUser().getRoles().stream().filter(r -> r.getRole().equals(Config.R_PROVIDER))
                    .map(Role::canonicalSpace).collect(Collectors.toSet()));
    String check = ":" + Config.R_PROVIDER;
    model.put("apiProvider", userRoles.stream().anyMatch(s -> s.endsWith(check)));
    return new ModelAndView("index", model);
}