Код: Выделить всё
@Data
public class Car {
private Long carId;
private Long carNumber;
private Long carColorId;
private String engineNumber;
private String partsNumber;
private String modifiedBy;
}
Код: Выделить всё
List carList = List.of(
new Car(1L, 100L, 1000L, "1ACB", "ZEGV200", "John"),
new Car(2L, 100L, 1000L, "1TUV", "ZVAV200", "Doe"),
new Car(3L, 200L, 2000L, "1ZVC", "CADV200", "Jane"),
new Car(4L, 200L, 2000L, "8CEB", "V2IWD00", "Harry")
);
carList.stream()
.filter(x -> !ObjectUtils.isEmpty(x.getCarNumber()))
.collect(Collectors.toMap(
Car::getCarNumber,
Function.identity(),
(x1, x2) -> new Car(x1.getCarNumber(), x1.getEngineNumber().concat(x2.getEngineNumber()))
));
carList.stream()
.filter(x -> !ObjectUtils.isEmpty(x.getCarColorId()))
.collect(Collectors.toMap(
Car::getCarColorId,
Function.identity(),
(x1, x2) -> new Car(x1.getCarColorId(), x1.getEngineNumber().concat(x2.getEngineNumber()))
));
Например: если я передаю строку colorId, то поток с условием colorId будет вызван в динамическом потоке.
Подробнее здесь: https://stackoverflow.com/questions/759 ... va-streams