Cannot understand how to compose Map<InternalErrorCode, ExternalErrorCode> variable from the following enum structure using Stream API:
@Getter
@RequiredArgsConstructor
public enum ExternalErrorCode {
// Internal error codes won't be duplicated across any ExternalErrorCode enums
ERROR1(Set.of(InternalErrorCode.FOO, InternalErrorCode.BAR)),
ERROR2(Set.of(InternalErrorCode.ZOO)),
...;
// Expected output should be: [{"FOO","ERROR1"}, {"BAR","ERROR1"}, {"ZOO","ERROR2"}]
private static final Map<InternalErrorCode, ExternalErrorCode> LOOKUP_BY_ERROR_CODE = Stream.of(ExternalErrorCode.values())
.filter(not(externalErrorCode -> externalErrorCode.getErrorCode().isEmpty()))
.collect(groupingBy(...)); // Here is unclarity
private final Set<InternalErrorCode> errorCode;
}
Can someone assist with it?