15 Aralık 2019 Pazar

ImmutableSortedMultiset Sınıfı

copyOf metodu
Şöyle yaparız.
List<String> temp = Stream.of("b, c", "a", "  ", "a, c")
            .filter(StringUtils::isNotBlank)
            .map(val -> val.split(","))
            .flatMap(Arrays::stream)
            .map(String::trim)
            .collect(Collectors.toList());

    Multiset<String> multiset = ImmutableSortedMultiset.copyOf(temp);

System.out.println("As list: " + temp);
System.out.println("As multiset: " + multiset);
// Output is:
// As list: [b, c, a, a, c]
// As multiset: [a x 2, b, c x 2]
naturalOrder metodu
Şöyle yaparız.
.collect(Collector.of(
    ImmutableSortedMultiset::<String>naturalOrder,
    ImmutableSortedMultiset.Builder::add,
    (b1, b2) -> {b1.addAll(b2.build()); return b1;},
    ImmutableSortedMultiset.Builder::build)
);
toImmutableSortedMultiset metodu
Şöyle yaparız.
.collect(ImmutableSortedMultiset.toImmutableSortedMultiset(Comparator.naturalOrder()));

Hiç yorum yok:

Yorum Gönder