/
Danchi
/
Java_Cars
Обзор
Документация
Войти
/
Danchi
/
Java_Cars
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/example/car/thread/DealerServiceImpl.java
34 строки
988 B
artem
4 - 8
18 дек 2024, 11:24
18 дек 2024, 11:24
783cfa1
Код
Авторство
О чём код?
package com.example.car.thread; import com.example.car.dto.CarDto; import com.example.car.utility.CarGenerator; import java.util.ArrayList; import java.util.List; public class DealerServiceImpl implements DealerService { @Override public void processDealer(DealerCenter dealer, List<CarDto> cars) { dealer.setCarsInShowRoom(new ArrayList<>()); cars.forEach(car -> { if (isNeedAddToShowroom(car)) { synchronized (this) { dealer.getCarsInShowRoom().add(car); dealer.setCountShowroomCars(dealer.getCountShowroomCars() + 1); } } try { Thread.sleep(1); } catch (InterruptedException e) { throw new RuntimeException(e); } }); } private boolean isNeedAddToShowroom(CarDto car) { return car.getColor().equals("Чёрный") && car.getEquipment().equals("Спорт"); } }