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

com.bluecatcode.common.base.RichEnumInstance Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.bluecatcode.common.base;

import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * An implementation for {@link com.bluecatcode.common.base.RichEnum}
 * @see com.bluecatcode.common.base.RichEnum
 * @see com.bluecatcode.common.base.RichEnumConstants
 * @param  the enum type
 */
public class RichEnumInstance {

    private final T theEnum;

    public RichEnumInstance(T theEnum) {
        this.theEnum = theEnum;
    }

    public static  RichEnumInstance richEnum(T theEnum) {
        return new RichEnumInstance<>(theEnum);
    }

    public boolean nameEquals(@Nullable String that) {
        return theEnum.name().equals(that);
    }

    public boolean nameEqualsIgnoreCase(@Nullable String that) {
        return theEnum.name().equalsIgnoreCase(that);
    }

    public boolean nameEqualsIgnoreCaseAndUnderscore(@Nullable String that) {
        String selfNameWithoutUnderscore = checkNotNull(theEnum.name()).replace("_", "");
        String thatNameWithoutUnderscore = that == null ? null : that.replace("_", "");
        return selfNameWithoutUnderscore.equalsIgnoreCase(thatNameWithoutUnderscore);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy