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

com.hframework.common.util.EnumUtils Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.hframework.common.util;

import com.google.common.base.Enums;
import com.google.common.base.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by zhangquanhong on 2016/5/26.
 */
public class EnumUtils {

    private static final Logger logger = LoggerFactory.getLogger(EnumUtils.class);

    public static > boolean compare(T enum1, String value) {
        return compare(enum1,value,false);
    }

    public static > boolean compareIfNullTrue(T enum1, String value) {
        return compare(enum1,value,true);
    }


    public static > boolean compare(T enum1, String value, boolean ifNullTrue) {
//        logger.debug("request : {}",enum1,value,ifNullTrue);
        if(StringUtils.isBlank(value) && ifNullTrue) {
            return true;
        }
        if(StringUtils.isBlank(value) && !ifNullTrue) {
            return false;
        }
        Optional ifPresent = Enums.getIfPresent(enum1.getClass(), value);
        if(ifPresent != null && ifPresent.orNull() == enum1) {
            return true;
        }
        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy