Skip to content

Lesson 49 (optional)#108

Open
Binary-Cat-01 wants to merge 3 commits intoKFalcon2022:for-prfrom
Binary-Cat-01:lesson_49_optional
Open

Lesson 49 (optional)#108
Binary-Cat-01 wants to merge 3 commits intoKFalcon2022:for-prfrom
Binary-Cat-01:lesson_49_optional

Conversation

@Binary-Cat-01
Copy link
Copy Markdown

No description provided.

CarService carService = new CarService(initCars());

Car desiredCar = createCar();
Optional<Car> foundCar = carService.findCar(desiredCar);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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