List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:com.hengyi.japp.tools.PYUtil.java
public static List<String> getFirstSpell(String cs) { if (isBlank(cs)) { return null; }//from w w w . jav a 2s . c o m List<String> result = null; List<Set<Character>> cs_fpys = cs.chars().mapToObj(i -> toHanyuPinyinStringArray((char) i)) .map(a -> Arrays.stream(a).map(s -> s.charAt(0)).collect(Collectors.toSet())) .collect(Collectors.toList()); for (Set<Character> fpys : cs_fpys) { if (result == null) { result = fpys.stream().map(String::valueOf).collect(Collectors.toList()); } else { Stream<String> tmps = result.stream().flatMap(s -> fpys.stream().map(fpy -> s + fpy)); result = tmps.collect(Collectors.toList()); } } return result; }
From source file:Main.java
public static <T> Set<T> conjunctCollectionsToSet(Collection<T> list1, Collection<T> list2) { Set<T> set = new HashSet<>(list2); return list1.stream().filter(set::contains).collect(Collectors.toSet()); }
From source file:Main.java
public static <T> boolean hasCycle(Collection<T> vertices, Function<T, Collection<T>> neighborExtractor) { Map<T, Collection<T>> parents = vertices.stream().collect(toMap(identity(), v -> new ArrayList<T>())); vertices.forEach(// ww w . ja v a 2 s . c om v -> nullSafeCollection(neighborExtractor.apply(v)).forEach(child -> parents.get(child).add(v))); Set<T> roots = vertices.stream().filter(v -> parents.get(v).isEmpty()).collect(Collectors.toSet()); while (!roots.isEmpty()) { T root = roots.iterator().next(); roots.remove(root); parents.remove(root); nullSafeCollection(neighborExtractor.apply(root)).forEach(child -> { parents.get(child).remove(root); if (parents.get(child).isEmpty()) { roots.add(child); } }); } return !parents.isEmpty(); }
From source file:Main.java
/** * @param collectionOfCollection// w w w . ja va 2 s . c o m * a {@code Collection<Collection<T>>} * @param <T> the element type * * @return a Set<T> containing all values of all Collections<T> * without any duplicates */ public static <T> Set<T> unionOfListOfLists( Collection<? extends Collection<? extends T>> collectionOfCollection) { return Optional.ofNullable(collectionOfCollection).map(Collection::stream).orElseGet(Stream::empty) .filter(Objects::nonNull).flatMap(c -> c.stream()).filter(Objects::nonNull) .collect(Collectors.toSet()); }
From source file:com.tesobe.obp.transport.json.FieldDecoder.java
@Override public Set<Entry<String, Object>> entrySet() { return json.keySet().stream().map(key -> new SimpleImmutableEntry<>(key, json.get(key))) .collect(Collectors.toSet()); }
From source file:org.vaadin.peholmst.samples.dddwebinar.domain.doctors.LicenseService.java
public Optional<License> selectBestLicense(Collection<Procedure> procedures, Collection<License> licenses) { Set<License> availableLicenses = licenses.stream().filter( l -> procedures.stream().allMatch(p -> p.getCategory().getLicenseTypes().containsKey(l.getType()))) .collect(Collectors.toSet()); if (availableLicenses.isEmpty()) { return Optional.empty(); } else {// www .j av a2 s . c om License best = null; int bestRank = Integer.MAX_VALUE; for (License l : availableLicenses) { for (Procedure p : procedures) { int rank = p.getCategory().getLicenseTypes().get(l.getType()); if (rank < bestRank) { bestRank = rank; best = l; } } } return Optional.ofNullable(best); } }
From source file:it.unibo.alchemist.SupportedIncarnations.java
/** * @return The set of incarnations currently available. *///from w ww. j a v a 2 s. c o m public static Set<String> getAvailableIncarnations() { return INCARNATIONS.stream().map(Class::getSimpleName).map(SupportedIncarnations::preprocess) .collect(Collectors.toSet()); }
From source file:index.IndexManager.java
public static Triple<SolrInputDocument, Collection<String>, Collection<String>> index(Document document) { final SolrInputDocument index = new SolrInputDocument(); index.setField("id", document.location()); index.setField("time", String.valueOf(System.currentTimeMillis())); index.setField("title", document.title()); final Set<String> links = document.select("a[href]").stream().map(e -> e.attr("abs:href")) .collect(Collectors.toSet()); final Set<String> media = document.select("[src]").stream().map(e -> e.attr("abs:src")) .collect(Collectors.toSet()); links.forEach(link -> index.addField("link", link)); media.forEach(link -> index.addField("media", link)); formatText(document.getElementsByTag("h1").stream()).forEach(e -> index.addField("h1", e)); formatText(document.getElementsByTag("h2").stream()).forEach(e -> index.addField("h2", e)); formatText(document.getElementsByTag("h3").stream()).forEach(e -> index.addField("h3", e)); formatText(document.getElementsByTag("strong").stream()).forEach(e -> index.addField("strong", e)); formatText(document.getElementsByTag("em").stream()).forEach(e -> index.addField("em", e)); formatText(document.getElementsByTag("b").stream()).forEach(e -> index.addField("b", e)); formatText(document.getElementsByTag("u").stream()).forEach(e -> index.addField("u", e)); formatText(document.getElementsByTag("i").stream()).forEach(e -> index.addField("i", e)); int i = 0;/*from w w w . j a v a 2 s .c om*/ Collection<String> text = chunkToLength(document.text()); for (String chunk : text) index.addField(++i + "_text", chunk); return Triple.of(index, links, media); }
From source file:com.vsct.dt.strowgr.admin.gui.mapping.json.EntryPointBackendMappingJson.java
public EntryPointBackendMappingJson(@JsonProperty("id") String id, @JsonProperty("servers") Set<EntryPointBackendServerMappingJson> servers, @JsonProperty("context") Map<String, String> context) { super(id, servers.stream().map(Function.identity()).collect(Collectors.toSet()), context); }
From source file:net.fabricmc.loader.launch.MixinLoader.java
public Set<String> getClientMixinConfigs() { return mods.stream().map(ModContainer::getInfo).map(ModInfo::getMixins).map(ModInfo.Mixins::getClient) .filter(s -> s != null && !s.isEmpty()).collect(Collectors.toSet()); }