/** * Check whether the given array of enum constants contains a constant with the given name, * ignoring case when determining a match. * @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()} * @param constant the constant name to find (must not be null or empty string) * @return whether the constant has been found in the given array */ public static boolean containsConstant(Enum<?>[] enumValues, String constant) { return containsConstant(enumValues, constant, false); }
/** * Check whether the given array of enum constants contains a constant with the given name, * ignoring case when determining a match. * @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()} * @param constant the constant name to find (must not be null or empty string) * @return whether the constant has been found in the given array */ public static boolean containsConstant(Enum<?>[] enumValues, String constant) { return containsConstant(enumValues, constant, false); }
@Test public void containsConstant() { assertThat(ObjectUtils.containsConstant(Tropes.values(), "FOO"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "foo"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "BaR"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "bar"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "BAZ"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "baz"), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "BOGUS"), is(false)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "FOO", true), is(true)); assertThat(ObjectUtils.containsConstant(Tropes.values(), "foo", true), is(false)); }
/** * Check whether the given array of enum constants contains a constant with the given name, * ignoring case when determining a match. * @param enumValues the enum values to check, typically the product of a call to MyEnum.values() * @param constant the constant name to find (must not be null or empty string) * @return whether the constant has been found in the given array */ public static boolean containsConstant(Enum<?>[] enumValues, String constant) { return containsConstant(enumValues, constant, false); }
/** * Check whether the given array of enum constants contains a constant with the given name, * ignoring case when determining a match. * @param enumValues the enum values to check, typically the product of a call to MyEnum.values() * @param constant the constant name to find (must not be null or empty string) * @return whether the constant has been found in the given array */ public static boolean containsConstant(Enum<?>[] enumValues, String constant) { return containsConstant(enumValues, constant, false); }
/** * Check whether the given array of enum constants contains a constant with the given name, * ignoring case when determining a match. * @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()} * @param constant the constant name to find (must not be null or empty string) * @return whether the constant has been found in the given array */ public static boolean containsConstant(Enum<?>[] enumValues, String constant) { return containsConstant(enumValues, constant, false); }
return containsConstant(enumValues, constant, false);