com.braintreegateway.util.EnumUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.servicemix.bundles.braintree-java
Show all versions of org.apache.servicemix.bundles.braintree-java
This OSGi bundle wraps ${pkgArtifactId} ${pkgVersion} jar file.
The newest version!
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;
}
}