Skip to content

Commit 03f04a2

Browse files
authored
refactor: use more concise APIs to collect streams (#5031)
1 parent 53486b7 commit 03f04a2

8 files changed

Lines changed: 11 additions & 24 deletions

File tree

articles/flow/component-internals/visibility.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ container.add(label);
5252
5353
// prints 1 - the server-side structure is preserved
5454
// regardless of whether the component is visible or not
55-
System.out.println("Number of children: "
56-
+ container.getChildren().collect(
57-
Collectors.counting()));
55+
System.out.println("Number of children: " + container.getChildCount());
5856
----
5957
====
6058

articles/flow/routing/registered-routes.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To retrieve all the routes defined by parent layout, use:
2727
List<RouteData> routes = RouteConfiguration.forSessionScope().getAvailableRoutes();
2828
List<RouteData> myRoutes = routes.stream()
2929
.filter(routeData -> MyParentLayout.class.equals((routeData.getParentLayout())))
30-
.collect(Collectors.toList());
30+
.toList();
3131
----
3232

3333

src/main/java/com/vaadin/demo/component/datepicker/DatePickerIndividualInputFields.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import java.time.LocalDate;
1616
import java.time.Month;
17-
import java.util.stream.Collectors;
1817
import java.util.stream.IntStream;
1918

2019
@Route("date-picker-individual-input-fields")
@@ -29,8 +28,7 @@ public DatePickerIndividualInputFields() {
2928
LocalDate now = LocalDate.now(ZoneId.systemDefault());
3029

3130
List<Integer> selectableYears = IntStream
32-
.range(now.getYear() - 99, now.getYear() + 1).boxed()
33-
.collect(Collectors.toList());
31+
.range(now.getYear() - 99, now.getYear() + 1).boxed().toList();
3432

3533
yearPicker = new ComboBox<>("Year", selectableYears);
3634
yearPicker.setWidth(6, Unit.EM);
@@ -80,8 +78,8 @@ private void updateDayPicker() {
8078
monthPicker.getValue(), 1);
8179
int lengthOfMonth = startOfMonth.lengthOfMonth();
8280

83-
dayPicker.setItems(IntStream.range(1, lengthOfMonth + 1).boxed()
84-
.collect(Collectors.toList()));
81+
dayPicker.setItems(
82+
IntStream.range(1, lengthOfMonth + 1).boxed().toList());
8583
}
8684
// end::snippet[]
8785

src/main/java/com/vaadin/demo/component/grid/GridDragDropFilters.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ public class GridDragDropFilters extends Div {
2626
public GridDragDropFilters() {
2727

2828
List<Person> people = DataService.getPeople();
29-
managers = people.stream().filter(Person::isManager)
30-
.collect(Collectors.toList());
29+
managers = people.stream().filter(Person::isManager).toList();
3130
staffGroupedByMangers = people.stream()
3231
.filter(person -> person.getManagerId() != null)
33-
.collect(Collectors.groupingBy(Person::getManagerId,
34-
Collectors.toList()));
32+
.collect(Collectors.groupingBy(Person::getManagerId));
3533

3634
// tag::snippet[]
3735
TreeGrid<Person> treeGrid = setupTreeGrid();

src/main/java/com/vaadin/demo/component/grid/GridHeaderFooterStyling.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.vaadin.flow.router.Route;
88

99
import java.util.List;
10-
import java.util.stream.Collectors;
1110

1211
@Route("grid-header-footer-styling")
1312
public class GridHeaderFooterStyling extends Div {
@@ -35,8 +34,7 @@ public GridHeaderFooterStyling() {
3534

3635
private static List<PersonWithRating> createDataSet() {
3736
return DataService.getPeople().stream()
38-
.map(PersonWithRating::generateFromPerson)
39-
.collect(Collectors.toList());
37+
.map(PersonWithRating::generateFromPerson).toList();
4038
}
4139

4240
public static class Exporter // hidden-source-line

src/main/java/com/vaadin/demo/component/grid/GridStyling.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.vaadin.flow.router.Route;
88

99
import java.util.List;
10-
import java.util.stream.Collectors;
1110

1211
@Route("grid-styling")
1312
public class GridStyling extends Div {
@@ -39,8 +38,7 @@ public GridStyling() {
3938

4039
private static List<PersonWithRating> createDataSet() {
4140
return DataService.getPeople().stream()
42-
.map(PersonWithRating::generateFromPerson)
43-
.collect(Collectors.toList());
41+
.map(PersonWithRating::generateFromPerson).toList();
4442
}
4543

4644
public static class Exporter // hidden-source-line

src/main/java/com/vaadin/demo/component/treegrid/TreeGridDragDrop.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public TreeGridDragDrop() {
2929
managers = people.stream().filter(Person::isManager).toList();
3030
staffGroupedByMangers = people.stream()
3131
.filter(person -> person.getManagerId() != null)
32-
.collect(Collectors.groupingBy(Person::getManagerId,
33-
Collectors.toList()));
32+
.collect(Collectors.groupingBy(Person::getManagerId));
3433

3534
// tag::snippet[]
3635
TreeGrid<Person> treeGrid = setupTreeGrid();

src/main/java/com/vaadin/demo/fusion/security/authentication/UserInfoService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.springframework.security.core.context.SecurityContextHolder;
99

1010
import java.util.List;
11-
import java.util.stream.Collectors;
1211

1312
/**
1413
* Provides information about the current user.
@@ -24,8 +23,7 @@ public UserInfo getUserInfo() {
2423
.getAuthentication();
2524

2625
final List<String> authorities = auth.getAuthorities().stream()
27-
.map(GrantedAuthority::getAuthority)
28-
.collect(Collectors.toList());
26+
.map(GrantedAuthority::getAuthority).toList();
2927

3028
return new UserInfo(auth.getName(), authorities);
3129
}

0 commit comments

Comments
 (0)