com.braintreegateway.util.EnumUtils Maven / Gradle / Ivy
package com.braintreegateway.util;
public class EnumUtils {
public static > T findByName(Class enumType, String name, T defaultValue) {
if (name == null) {
return null;
}
try {
return Enum.valueOf(enumType, name.toUpperCase().replace(' ', '_'));
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
public static > T findByToString(T[] values, String name, T defaultValue) {
if (name == null || values == null) {
return defaultValue;
}
for (T value : values) {
if (name.equals(value.toString())) {
return value;
}
}
return defaultValue;
}
}