Skip to content

Instantly share code, notes, and snippets.

View UnifiedSetWithHashingStrategy.java
HashingStrategy<Person> strategy =
HashingStrategies.fromFunction(Person::getSystemId);
MutableSet<Person> people =
new UnifiedSetWithHashingStrategy<>(strategy);
View Distinct.java
MutableList<Person> people = ...;
MutableList<Person> res1 = people.distinct();
MutableList<Person> res2 = people.distinct(HashingStrategies.fromFunction(Person::getSystemId));
MutableList<Person> res3 = people.distinctBy(Person::getSystemId);
View HashingStrategy.java
public interface HashingStrategy<E>
{
int computeHashCode(E object);
boolean equals(E object1, E object2);
}
View Bags.java
MutableBag<Color> bag = people.countBy(Person::getFavoriteColor);
View Counting.java
Map<Color, Long> map =
people.stream().collect(Collectors.groupingBy(
Person::getFavoriteColor,
Collectors.counting()));
View GroupingByList.java
Map<Color, List<Person>> map = people
.stream()
.collect(Collectors.groupingBy(Person::getFavoriteColor));
View GroupingBy.java
Map<Color, Set<Person>> map =
people.stream().collect(Collectors.groupingBy(
Person::getFavoriteColor,
Collectors.toSet()));
View GroupBy.java
MutableSetMultimap<Color, Person> multimap =
people.groupBy(Person::getFavoriteColor);
View EagerEclipseCollections.java
MutableSet<Address> addresses = people.collect(Person::getAddress);
View LazyEclipseCollections.java
MutableSet<Person> people = ...;
MutableSet<Address> addresses = people
.asLazy()
.collect(Person::getAddress)
.toSet();
You can’t perform that action at this time.