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.openmrs.api.cache.CachePropertiesUtil.java

private static Set<String> getAllCacheNames(Set<Object> keys) {
    Set<String> cacheNames = new HashSet<>();
    keys.forEach(cacheName -> {
        String s = cacheName.toString();
        cacheNames.add(s.substring(0, s.indexOf(".")));
    });/*  ww  w  .  j a  v  a 2  s. c  om*/
    return cacheNames;
}

From source file:se.uu.it.cs.recsys.constraint.api.SolverAPI.java

private static void printSolution(Set<List<se.uu.it.cs.recsys.api.type.Course>> solutions) {
    solutions.forEach(solution -> {
        LOGGER.info("==> Solution: ");
        solution.forEach(course -> {//from  w w w.  j  a  v  a2 s  .c  o  m
            LOGGER.info("Course {}", course);
        });
        LOGGER.info("\n");
    });
}

From source file:io.fabric8.vertx.maven.plugin.FileFilterMain.java

private static FileAlterationMonitor fileWatcher(Set<Path> inclDirs) {
    FileAlterationMonitor monitor = new FileAlterationMonitor(1000);

    inclDirs.forEach(path -> {
        System.out.println("Adding Observer to " + path.toString());
        FileAlterationObserver observer = new FileAlterationObserver(path.toFile());
        observer.addListener(new FileAlterationListenerAdaptor() {
            @Override// w  w  w  . j  ava 2 s  . c om
            public void onFileCreate(File file) {
                System.out.println("File Create:" + file.toString());
            }

            @Override
            public void onFileChange(File file) {
                System.out.println("File Change:" + file.toString());
            }

            @Override
            public void onFileDelete(File file) {
                System.out.println("File Delete:" + file.toString());
            }

        });
        monitor.addObserver(observer);
    });

    return monitor;

}

From source file:synonyms.SynonymAdapter.java

/**
 * @param word The word to find synonyms for
 * @return A set of synonyms for the given #word# in no particular order or null if you didn't pass a word, jerk.
 *//* w  ww .  ja v a 2  s  .  c om*/
public static Set getSynonyms(String word) {
    if (word == null) {
        return null;
    }

    // Initialize the dictionary db
    WordNetDatabase db = WordNetDatabase.getFileInstance();
    Set<String> synonyms = new HashSet();

    // Sanitize the input
    String cleansedWord = word.toLowerCase().trim();

    // Get the synsets, which will each contain a set of synonyms for a given definition of the word.
    Synset[] synsets = db.getSynsets(cleansedWord);
    for (Synset synset : synsets) {
        // Add all of the wordForms (Either a single word or a phrase) from the given synset
        synonyms.addAll(Arrays.asList(synset.getWordForms()));
    }

    // Filter out any versions of #word# that may be capitalized in any form, then remove them from the set.
    Set<String> wordRepeats = synonyms.stream().filter(synonym -> synonym.equalsIgnoreCase(word))
            .collect(Collectors.toSet());
    wordRepeats.forEach(synonyms::remove);

    // If we found any synonyms, return them
    return synonyms.size() > 0 ? synonyms : null;
}

From source file:com.widowcrawler.terminator.trie.RuleTrie.java

public static RuleTrie build(Set<Rule> rules) {
    TrieNode root = new TrieNode(null, 0, "", null);

    rules.forEach(rule -> insert(root, rule));

    return new RuleTrie(root);
}

From source file:org.thingsboard.server.service.install.DatabaseHelper.java

public static void upgradeTo40_assignDashboards(Path dashboardsDump, DashboardService dashboardService,
        boolean sql) throws Exception {
    JavaType assignedCustomersType = objectMapper.getTypeFactory().constructCollectionType(HashSet.class,
            ShortCustomerInfo.class);
    try (CSVParser csvParser = new CSVParser(Files.newBufferedReader(dashboardsDump),
            CSV_DUMP_FORMAT.withFirstRecordAsHeader())) {
        csvParser.forEach(record -> {
            String customerIdString = record.get(CUSTOMER_ID);
            String assignedCustomersString = record.get(ASSIGNED_CUSTOMERS);
            DashboardId dashboardId = new DashboardId(toUUID(record.get(ID), sql));
            List<CustomerId> customerIds = new ArrayList<>();
            if (!StringUtils.isEmpty(assignedCustomersString)) {
                try {
                    Set<ShortCustomerInfo> assignedCustomers = objectMapper.readValue(assignedCustomersString,
                            assignedCustomersType);
                    assignedCustomers.forEach((customerInfo) -> {
                        CustomerId customerId = customerInfo.getCustomerId();
                        if (!customerId.isNullUid()) {
                            customerIds.add(customerId);
                        }/*from  ww w. j a  v a  2 s.  c  om*/
                    });
                } catch (IOException e) {
                    log.error("Unable to parse assigned customers field", e);
                }
            }
            if (!StringUtils.isEmpty(customerIdString)) {
                CustomerId customerId = new CustomerId(toUUID(customerIdString, sql));
                if (!customerId.isNullUid()) {
                    customerIds.add(customerId);
                }
            }
            for (CustomerId customerId : customerIds) {
                dashboardService.assignDashboardToCustomer(new TenantId(EntityId.NULL_UUID), dashboardId,
                        customerId);
            }
        });
    }
}

From source file:org.apdplat.superword.extract.PartOfSpeechExtractor.java

private static Map<String, Set<String>> group(Set<Word> words) {
    Map<String, Set<String>> data = new HashMap<>();
    words.forEach(w -> {
        w.getPartOfSpeeches().forEach(pos -> {
            data.putIfAbsent(pos, new HashSet<>());
            data.get(pos).add(w.getWord());
        });//from   w w w . jav a2 s .c o m
    });
    return data;
}

From source file:org.apdplat.superword.extract.DefinitionExtractor.java

public static void compensate(Set<Word> words) {
    Set<Word> minus = WordSources.minus(WordSources.getSyllabusVocabulary(), words);
    LOGGER.debug("?" + minus.size());
    minus.forEach(w -> {
        LOGGER.debug(w.getWord());/*from  www .  ja va2  s  .c  o  m*/
        Word word = parseWord(w.getWord());
        if (word != null && !word.getDefinitions().isEmpty()) {
            words.add(word);
        }
    });
}

From source file:org.apdplat.superword.extract.PartOfSpeechExtractor.java

private static String formatPartOfSpeechType(Set<Word> words) {
    StringBuilder text = new StringBuilder();
    Set<String> ps = new HashSet<>();
    words.forEach(w -> {
        ps.addAll(w.getPartOfSpeeches());
    });//from   w w w. j a  v a 2 s  .  c om
    text.append("#??(").append(ps.size()).append(")").append("\n");
    ps.forEach(p -> text.append("#").append(p).append("=").append(PartOfSpeech.getMeaning(p)).append("\n"));
    return text.toString();
}

From source file:org.apdplat.superword.extract.PartOfSpeechExtractor.java

private static String formatPartOfSpeech(Set<Word> words) {
    StringBuilder text = new StringBuilder();
    AtomicInteger i = new AtomicInteger();
    words.forEach(w -> text.append(i.incrementAndGet()).append("\t").append(w.getWord()).append("\t")
            .append(w.getFormatPartOfSpeeches()).append("\n"));
    text.append(formatPartOfSpeechType(words));
    return text.toString();
}