Skip to content

Commit

Permalink
Simplified switch statement to be inside type.cast() call that was us…
Browse files Browse the repository at this point in the history
…ed for all cases
  • Loading branch information
TheDavSmasher committed Dec 23, 2024
1 parent b1db013 commit bd439c3
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/main/java/edu/byu/cs/dataAccess/sql/ConfigurationSqlDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ private <T> T getValue(Configuration key, String value, Class<T> type) throws Re
if (value.equals(DEFAULT_VALUE)) {
LOGGER.warn("Using default configuration value for key: {} of type {}", key, type);

return switch (typedObj) {
case String ignored -> type.cast("");
case Integer ignored -> type.cast(0);
case Boolean ignored -> type.cast(false);
case Instant ignored -> type.cast(Instant.MAX);
case Float ignored -> type.cast(0f);
return type.cast(switch (typedObj) {
case String ignored -> "";
case Integer ignored -> 0;
case Boolean ignored -> false;
case Instant ignored -> Instant.MAX;
case Float ignored -> 0f;
default -> throw new IllegalArgumentException("Unsupported configuration type: " + type);
};
});
}

return switch (typedObj) {
case String ignored -> type.cast(value);
case Integer ignored -> type.cast(Integer.parseInt(value));
case Boolean ignored -> type.cast(Boolean.parseBoolean(value));
case Instant ignored -> type.cast(Instant.parse(value));
case Float ignored -> type.cast(Float.parseFloat(value));
return type.cast(switch (typedObj) {
case String ignored -> value;
case Integer ignored -> Integer.parseInt(value);
case Boolean ignored -> Boolean.parseBoolean(value);
case Instant ignored -> Instant.parse(value);
case Float ignored -> Float.parseFloat(value);
default -> throw new IllegalArgumentException("Unsupported configuration type: " + type);
};
});
}
}

0 comments on commit bd439c3

Please sign in to comment.