I have a list of objects of structure
public class SimpleObject {
private TypeEnum type;
private String propA;
private Integer propB;
private String propC;
}
which I would like to "pack" into the following objects
public class ComplexObject {
private TypeEnum type;
private List<SimpleObject> simpleObjects;
}
based on TypeEnum.
In other words I'd like to create a sort of aggregations which will hold every SimpleObject
that contains a certain type
. I thought of doing it with Java 8 streams but I don't know how.
So let's say I'm getting the list of SimpleObject
s like
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DataService {
private final DataRepository dataRepo;
public void getPackedData() {
dataRepo.getSimpleObjects().stream()...
}
}
How the next steps should look like? Thank you in advance for any help
I'm using Java 14 with Spring Boot