志向和热爱是伟大行为的双翼。——歌德

之前分享了vavr,今天在分享一个同类框架eclipse-collections

官方文档:http://www.eclipse.org/collections/

1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-api</artifactId>
<version>11.0.0</version>
</dependency>

<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
<version>11.0.0</version>
</dependency>

体验下,这是java8 Stream的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
boolean anyPeopleHaveCats =
this.people
.stream()
.anyMatch(person -> person.hasPet(PetType.CAT));

long countPeopleWithCats =
this.people
.stream()
.filter(person -> person.hasPet(PetType.CAT))
.count();

List<Person> peopleWithCats =
this.people
.stream()
.filter(person -> person.hasPet(PetType.CAT))
.collect(Collectors.toList());

eclipse-collections

1
2
3
4
5
6
7
8
9
10
11
boolean anyPeopleHaveCats =
this.people
.anySatisfy(person -> person.hasPet(PetType.CAT));

int countPeopleWithCats =
this.people
.count(person -> person.hasPet(PetType.CAT));

MutableList<Person> peopleWithCats =
this.people
.select(person -> person.hasPet(PetType.CAT));

简短了原本的代码