Skip to content

Commit

Permalink
Use pattern matching instead of casting
Browse files Browse the repository at this point in the history
  • Loading branch information
mkutz committed Aug 6, 2024
1 parent 4085f2a commit 9349e4a
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ default boolean isIgnoredException(Exception exception) {
* @return {@code true} if the given answer is acceptable
*/
default boolean acceptable(A answer) {
if (answer instanceof Optional<?>) {
return ((Optional<?>) answer).isPresent();
} else if (answer instanceof Collection<?>) {
return !((Collection<?>) answer).isEmpty();
} else if (answer instanceof Map<?, ?>) {
return !((Map<?, ?>) answer).isEmpty();
} else if (answer instanceof Object[]) {
return ((Object[]) answer).length > 0;
} else if (answer instanceof Boolean) {
return (Boolean) answer;
if (answer instanceof Optional<?> optionalAnswer) {
return optionalAnswer.isPresent();
} else if (answer instanceof Collection<?> collectionAnswer) {
return !collectionAnswer.isEmpty();
} else if (answer instanceof Map<?, ?> mapAnswer) {
return !mapAnswer.isEmpty();
} else if (answer instanceof Object[] arrayAnswer) {
return arrayAnswer.length > 0;
} else if (answer instanceof Boolean booleanAnswer) {
return booleanAnswer;
}
return answer != null;
}
Expand Down

0 comments on commit 9349e4a

Please sign in to comment.