Skip to content

Commit

Permalink
chore: #99 Remove the archaic Collectors.toList() usage. Use `Strea…
Browse files Browse the repository at this point in the history
…m.toList()` instead.
  • Loading branch information
dmitry-weirdo committed Nov 20, 2024
1 parent 5b1e1ae commit fa22cdf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions kgparserSrv/src/main/java/ru/klavogonki/kgparser/Car.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static Car getById(int carId) {
List<Car> carsWithId = Arrays
.stream(Car.values())
.filter(car -> car.id == carId)
.collect(Collectors.toList());
.toList();

if (carsWithId.size() == 1) {
return carsWithId.get(0);
Expand All @@ -151,7 +151,7 @@ public static Car getById(int carId) {
List<Car> carsWithPersonalId = Arrays
.stream(Car.values())
.filter(car -> (car.personalId != null) && (car.personalId == carId))
.collect(Collectors.toList());
.toList();

if (carsWithPersonalId.size() == 1) {
return carsWithPersonalId.get(0);
Expand Down
21 changes: 12 additions & 9 deletions kgparserSrv/src/test/java/ru/klavogonki/kgparser/CarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -18,11 +17,12 @@ class CarTest {
void testCarIdsAreUnique() {
Car[] cars = Car.values();

List<Integer> uniqueCarIds = Arrays.stream(cars)
List<Integer> uniqueCarIds = Arrays
.stream(cars)
.map(car -> car.id)
.distinct()
.sorted()
.collect(Collectors.toList());
.toList();

logger.info("unique car ids: \n{}", uniqueCarIds);

Expand All @@ -33,11 +33,12 @@ void testCarIdsAreUnique() {
void testCarNamesAreUnique() {
Car[] cars = Car.values();

List<String> uniqueCarNames = Arrays.stream(cars)
List<String> uniqueCarNames = Arrays
.stream(cars)
.map(car -> car.name)
.distinct()
.sorted()
.collect(Collectors.toList());
.toList();

logger.info("unique car names: \n{}", uniqueCarNames);

Expand All @@ -48,12 +49,13 @@ void testCarNamesAreUnique() {
void testAllPersonalCarIdsArePersonalIds() {
Car[] cars = Car.values();

List<Integer> carPersonalIds = Arrays.stream(cars)
List<Integer> carPersonalIds = Arrays
.stream(cars)
.filter(car -> (car.personalId != null))
.map(car -> car.personalId)
.distinct()
.sorted()
.collect(Collectors.toList());
.toList();

logger.info("personal car ids for cars that have been made public: \n{}", carPersonalIds);

Expand All @@ -66,11 +68,12 @@ void testAllPersonalCarIdsArePersonalIds() {
void testAllPersonalCarsThatWereMadePublicHaveOriginalOwnerFilled() {
Car[] cars = Car.values();

List<Car> personalCarsThatWereMadePublic = Arrays.stream(cars)
List<Car> personalCarsThatWereMadePublic = Arrays
.stream(cars)
.filter(Car::wasPersonalButMadePublic)
.distinct()
.sorted()
.collect(Collectors.toList());
.toList();

logger.info("cars that were personal but have been made public: \n{}", personalCarsThatWereMadePublic);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void savePlayerToDatabase(PlayerEntity player) {
.stream()
.map(PlayerEntity::getDbId)
.sorted()
.collect(Collectors.toList());
.toList();
if (existingPlayersWithId.isEmpty()) {
logger.debug("No players with playerId = {} found in the database. Nothing to delete.", playerId);
Expand Down

0 comments on commit fa22cdf

Please sign in to comment.