/** * Get the {@link HttpStatus} which corresponds to given status code, if any * @param code Status code * @return HttpStatus which corresponds to given code, or an empty Optional if the given code does not corresponds * to any of the {@link HttpStatus} values. */ public static Optional<HttpStatus> of(int code) { for (HttpStatus status : values()) { if (code == status.code) { return Optional.of(status); } } return Optional.empty(); }