All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.braintreegateway.util.EnumUtils Maven / Gradle / Ivy

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy