diff options
author | gjoranv <gjoranv@gmail.com> | 2023-11-02 13:32:56 +0100 |
---|---|---|
committer | gjoranv <gjoranv@gmail.com> | 2023-11-02 13:32:56 +0100 |
commit | ea41233fdafa0a577e08dd8ebece5e7db233592f (patch) | |
tree | b5790a73db188986c6f982b12c9e29061f48f877 /controller-api | |
parent | e64583fa0b618da67189152c10310293221dd8bc (diff) |
Use 'value' when getting an enum object from a String.
- Ensures that the correct value is returned even if the name
and value does not match.
Diffstat (limited to 'controller-api')
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java index 00aa43cce5d..17698aff6f4 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillStatus.java @@ -1,5 +1,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.billing; +import java.util.Arrays; + /** * @author gjoranv */ @@ -34,7 +36,11 @@ public enum BillStatus { public static BillStatus from(String status) { if (LEGACY_ISSUED.equals(status) || LEGACY_EXPORTED.equals(status)) return OPEN; if (LEGACY_CANCELED.equals(status)) return VOID; - return Enum.valueOf(BillStatus.class, status.toUpperCase()); + + return Arrays.stream(values()) + .filter(s -> s.value.equals(status)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("Unknown bill status: " + status)); } } |