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:com.edduarte.argus.stopper.FileStopper.java

private boolean load(String language) {
    File stopwordsFile = new File(Constants.STOPWORDS_DIR, language + ".txt");
    if (stopwordsFile.exists()) {
        try (InputStream is = new FileInputStream(stopwordsFile); Parser parser = new SimpleParser()) {

            Set<MutableString> stopwordsAux = new HashSet<>();
            List<String> lines = IOUtils.readLines(is);
            lines.forEach(line -> {/*  w  w  w .  ja v a 2 s.  c  o m*/
                line = line.trim().toLowerCase();
                if (!line.isEmpty()) {
                    int indexOfPipe = line.indexOf('|');

                    MutableString stopwordLine;
                    if (indexOfPipe == -1) {
                        // there are no pipes in this line
                        // -> add the whole line as a stopword
                        stopwordLine = new MutableString(line);

                    } else if (indexOfPipe > 0) {
                        // there is a pipe in this line and it's not the first char
                        // -> add everything from index 0 to the pipe's index
                        String word = line.substring(0, indexOfPipe).trim();
                        stopwordLine = new MutableString(word);
                    } else {
                        return;
                    }

                    Set<MutableString> stopwordsAtLine = parser.parse(stopwordLine).parallelStream()
                            .map(sw -> sw.text).collect(Collectors.toSet());
                    stopwordsAux.addAll(stopwordsAtLine);
                }
            });

            stopwords = ImmutableSet.copyOf(stopwordsAux);
            return true;

        } catch (IOException e) {
            logger.error("There was a problem loading the stopword file.", e);
            stopwords = Collections.emptySet();
        }
    }

    return false;
}

From source file:com.pscnlab.member.services.impl.MemberSeviceImpl.java

@Override
public Map<Integer, MemberPageDTO> findMemberWithRoleByIds(Set<Integer> memberIdsSet) {

    List<Member> members = memberDao.findListByMemberIdsSet(memberIdsSet);
    if (CollectionUtils.isEmpty(members)) {
        return Collections.emptyMap();
    }/*  w  w  w  .  j a v a  2 s.c o  m*/

    Set<Integer> roleIds = members.stream().map(Member::getUuidRole).collect(Collectors.toSet());
    Map<Integer, Role> roleMap = roleService.findMapByRoleIds(roleIds);

    Map<Integer, MemberPageDTO> memberPageDTOMap = Maps.newHashMap();
    for (Member result : members) {
        MemberPageDTO memberPageDTO = new MemberPageDTO();
        memberPageDTO.setRole(roleMap.get(result.getUuidRole()));
        memberPageDTO.setMember(result);
        memberPageDTOMap.put(result.getUuidMember(), memberPageDTO);
    }

    return memberPageDTOMap;
}

From source file:com.collective.celos.GetSchedulerTest.java

@Test
public void testGetScheduler() throws Exception {
    Set<WorkflowID> workflowIDs = celosClient.getWorkflowList();
    Assert.assertTrue(workflowIDs.isEmpty());

    File src = new File(Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/client/wf-list").toURI());
    FileUtils.copyDirectory(src, workflowsDir);

    workflowIDs = celosClient.getWorkflowList();
    Assert.assertTrue(workflowIDs.isEmpty());

    celosClient.clearCache();//from ww  w .jav  a2  s  . c  o m

    HashSet<WorkflowID> expectedResult = Sets.newHashSet(new WorkflowID("workflow-1"),
            new WorkflowID("workflow-2"), new WorkflowID("workflow-Itrntinliztin"),
            new WorkflowID("workflow-4"));
    workflowIDs = celosClient.getWorkflowList();
    Assert.assertEquals(Sets.newHashSet(workflowIDs), expectedResult);

    Scheduler scheduler = Util.requireNonNull(celosServer.getScheduler());
    Set<WorkflowID> schedWfIds = scheduler.getWorkflowConfiguration().getWorkflows().stream()
            .map(x -> x.getID()).collect(Collectors.toSet());

    Assert.assertEquals(schedWfIds, expectedResult);
}

From source file:delfos.rs.contentbased.vsm.booleanvsm.SparseVector.java

public double multiply(SparseVector<Key> iuf) {

    Set<Key> intersectionDomain = map.keySet().stream().filter(key -> iuf.containsKey(key))
            .collect(Collectors.toSet());

    double sum = intersectionDomain.stream().mapToDouble(key -> map.get(key) * iuf.map.get(key)).sum();
    return sum;//w w  w.  j a  v a 2  s.  co m
}

From source file:dk.dbc.rawrepo.oai.OAIIdentifierCollectionIT.java

@Test
public void testNoneDuplicates() throws Exception {
    loadRecordsFrom("recordset_1.json");
    Connection connection = pg.getConnection();

    ObjectNode json = json("'m':'marcx'");

    OAIIdentifierCollection recordCollection = new OAIIdentifierCollection(connection,
            Arrays.asList("nat", "bkm"));
    recordCollection.fetch(json, 100);/*  w ww .  j a  v a 2s.c  o m*/
    System.out.println("recordCollection = " + recordCollection);
    Set<String> uniq = recordCollection.stream().map(id -> id.getIdentifier()).collect(Collectors.toSet());
    assertEquals(uniq.size(), recordCollection.size());
}

From source file:com.romeikat.datamessie.core.base.dao.impl.SourceDao.java

public Map<Document, Source> getForDocuments(final SharedSessionContract ssc,
        final Collection<Document> documents) {
    final Set<Long> sourceIds = documents.stream().map(d -> d.getSourceId()).collect(Collectors.toSet());
    final Map<Long, Source> sourcesById = getIdsWithEntities(ssc, sourceIds);

    final Map<Document, Source> result = Maps.newHashMapWithExpectedSize(documents.size());
    for (final Document document : documents) {
        final Source source = sourcesById.get(document.getSourceId());
        result.put(document, source);//from w  w  w . j a v  a 2  s.  c om
    }
    return result;
}

From source file:com.vsct.dt.hesperides.indexation.search.TemplateSearch.java

public Set<TemplateSearchResponse> getTemplatesByNamespaceLike(final String[] wildcards,
        final boolean isCaseSensitive) {
    String url = String.format("/templates/_search?size=%1$s", 50);

    List<String> actualSearchCaseWildcards = Arrays.asList(wildcards).stream()
            .map(wildcard -> isCaseSensitive ? wildcard : wildcard.toLowerCase()).collect(Collectors.toList());

    String body = TemplateContentGenerator.from(mustacheSearchByNamespaceLike)
            .put("wildcards", new DecoratedCollection<>(actualSearchCaseWildcards)).generate();

    ElasticSearchResponse<TemplateSearchResponse> esResponse = elasticSearchClient
            .withResponseReader(elasticSearchTemplateReader).post(url, body);

    return esResponse.streamOfData().collect(Collectors.toSet());
}

From source file:org.ow2.proactive.connector.iaas.cloud.provider.vmware.VMWareProviderVirtualMachineUtil.java

public Set<VirtualMachine> getAllVirtualMachines(Folder rootFolder) {
    try {//  w ww .ja va2s  .c o m
        ManagedEntity[] managedEntities = new InventoryNavigator(rootFolder)
                .searchManagedEntities(EntityType.VM.getValue());

        return IntStream.range(0, managedEntities.length).mapToObj(i -> (VirtualMachine) managedEntities[i])
                .collect(Collectors.toSet());

    } catch (RemoteException e) {
        throw new RuntimeException("ERROR when retrieving VMWare virtual machines", e);
    }
}

From source file:com.bitvantage.bitvantagetypes.collections.TreeBidirectionalMap.java

@Override
public Set<K> keySet() {
    return map.keySet().stream().map((ComparableWrapper<K> k) -> k.getWrapped()).collect(Collectors.toSet());
}