diff --git a/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureEnums.java b/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureEnums.java index a0a307aa3..d4897a3d2 100644 --- a/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureEnums.java +++ b/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureEnums.java @@ -18,20 +18,12 @@ import com.palantir.logsafe.UnsafeArg; import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; -import java.util.BitSet; /** * Internal utility functions for conjure enum types. */ public final class ConjureEnums { - private static final BitSet allowedCharacters = new BitSet(); - - static { - allowedCharacters.set('A', 'Z' + 1); - allowedCharacters.set('_'); - } - private ConjureEnums() { // cannot instantiate } @@ -41,12 +33,16 @@ public static void validate(String value) { throw new SafeIllegalArgumentException("Enum values must not be empty"); } - final int length = value.length(); + int length = value.length(); for (int index = 0; index < length; index++) { - if (!allowedCharacters.get(value.charAt(index))) { + if (!isAllowedCharacter(value.charAt(index))) { throw new SafeIllegalArgumentException("Enum values must use SCREAMING_SNAKE_CASE", UnsafeArg.of("value", value)); } } } + + private static boolean isAllowedCharacter(char character) { + return (character >= 'A' && character <= 'Z') || character == '_'; + } }