spring-cloud-stream-demo
spring-cloud-stream-demo copied to clipboard
Statuses.valueOf instead of checking against all the enum values
https://github.com/benwilcock/spring-cloud-stream-demo/blob/fbdadd1b8d30c5f3d42c18e03835474aaa052f29/loancheck/src/main/java/io/pivotal/loancheck/Loan.java#L34-L38
https://github.com/benwilcock/spring-cloud-stream-demo/blob/fbdadd1b8d30c5f3d42c18e03835474aaa052f29/loansource/src/main/java/io/pivotal/loansource/Loan.java#L37-L46
Instead of all checking against all of the Statuses
enum values, we can easily check the existence of the status with the help of Statuses.valueOf
which throws IllegalArgumentException
as well.
try {
this.status = Statuses.valueOf(status).name();
} catch (IllegalArgumentException ex){
throw new IllegalArgumentException("Cannot set the LoanApplication's status to " + status);
}