So i have a list of objects:
List<GpbCodesAndVersions> lst = Arrays.asList(new GpbCodesAndVersions("code1", 1, Arrays.asList(new General(1), new General(2))),
new GpbCodesAndVersions("code2", 2, Arrays.asList(new General(1), new General(5))),
new GpbCodesAndVersions("code3", 3, Arrays.asList(new General(2), new General(3))),
new GpbCodesAndVersions("code4", 4, Arrays.asList(new General(2), new General(4))));
And i want to filter this list and get list which includes only General(1) fields:
GpbCodesAndVersions(code=code1, version=1, content=[General(status=1)]), GpbCodesAndVersions(code=code2, version=2, content=[General(status=1)])
My code is working, but maybe it possible to do it more beautiful ? My code:
List<GpbCodesAndVersions> versionOneGeneral = lst.stream().peek(x -> {
List<General> generals = x.getContent().stream().filter(y -> y.getStatus().equals(1)).toList();
x.setContent(generals);
}).filter(z -> !z.getContent().isEmpty()).toList();