"I was reviewing the private method getStatusCode in the MyHealthMetricsExportConfiguration class from Spring Docs written in Java. Switch statements would enhance readability, in my opinion."

Before Code

    private int getStatusCode(HealthEndpoint health) {
        Status status = health.health().getStatus();
        if (Status.UP.equals(status)) {
            return 3;
        }
        if (Status.OUT_OF_SERVICE.equals(status)) {
            return 2;
        }
        if (Status.DOWN.equals(status)) {
            return 1;
        }
        return 0;
    }

After Code

    private int getStatusCode(HealthEndpoint health) {
        return switch (health.health().getStatus().toString()) {
            case "UP" -> 3;
            case "OUT_OF_SERVICE" -> 2;
            case "DOWN" -> 1;
            default -> 0;
        };
    }

If there is a problem with my opinion, I would appreciate it if you could point it out.

Comment From: pivotal-cla

@BLoHny Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@BLoHny Thank you for signing the Contributor License Agreement!

Comment From: wilkinsona

Thanks for the suggestion but I don't like the String-based matching that this change has introduced. It could lead to subtle bugs in the future if the toString() implementation is changed such that it no longer matches in the same way as equals does currently.