I'm new to Java and object oriented design concepts. I have a piece of code that I know could be improved, but I'm not sure the best way to go about it.
I have a stream of data (authorization values) coming in that I am trying to convert to a map of authorization ID to validity of the value. In order to test the validity, I need to check the type of authorization value it is, and send it to a remote client to make sure it works.
I am creating the map of authorization validity here:
private Map<UUID, Boolean> getAuthorizationValidityMap(UUID accountId) {
final Map<UUID, Boolean> authValidity = findCredentialsByAccountId(accountId)
.parallelStream()
.map((auth -> Pair.of(auth.getId(), isAuthValid(auth))))
.collect(Collectors.toMap(res -> res.getLeft(), res -> res.getRight()));
return authValidity;
}
The function to find if the authorization value is valid. There are multiple authorization value types, and each one needs to check the validity differently. The way I have it implemented feels clunky because as more auth types get added, it will just result in more else if statements.
private Boolean isAuthValid(AuthorizationValue authValue) {
if (authValue.getType().equals(AUTH_TYPE_A)) {
return isAuthTypeAValid(authValue);
} else if (authValue.getType().equals(AUTH_TYPE_B)) {
return isAuthTypeBValid(authValue);
} else if (authValue.getType().equals(AUTH_TYPE_C)) {
return isAuthTypeCValid(authValue);
}
return false;
}