Skip to content

Conversation

@Binary-Cat-01
Copy link

No description provided.

CarService carService = new CarService(initCars());

Car desiredCar = createCar();
Optional<Car> foundCar = carService.findCar(desiredCar);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Избыточная переменная

String found = foundCar.map("Найдена машина:\n%s"::formatted)
.orElse("Подходящая машина не обнаружена");

System.out.println(found);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно было впихнуть в ifPresentOrElse()

.getYear() <= 2021)
.map(Car::getOwner)
.filter(person -> !person.getProfession()
.equals("policeman"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Конструкции с equals и константой/литералом зачастую лучше описывать в другом порядке:

"policeman".equals(person.getProfession())

во избежание NPE на ровном месте

.getYear() <= 2021)
.map(Car::getOwner)
.filter(person -> !person.getProfession()
.equals("policeman"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Конструкции с equals и константой/литералом зачастую лучше описывать в другом порядке:

"policeman".equals(person.getProfession())

во избежание NPE на ровном месте

.map(Home::getAddress)
.filter(address -> !address.contains("Рублевское шоссе"));

String address = foundAddress.map("Найден адрес:\n%s"::formatted)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем отдельная переменная

String address = foundAddress.map("Найден адрес:\n%s"::formatted)
.orElse("Адресс не найден");

System.out.println(address);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifPresentOrElse()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants