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

org.rx.bean.NEnum Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.rx.bean;

import lombok.NonNull;
import lombok.SneakyThrows;
import org.rx.core.Extends;

import java.io.Serializable;

import static org.rx.core.Constants.NON_UNCHECKED;

public interface NEnum & NEnum> extends Serializable {
    static  & NEnum> T valueOf(@NonNull Class type, int value) {
        for (T nEnum : type.getEnumConstants()) {
            if (nEnum.getValue() == value) {
                return nEnum;
            }
        }
        return null;
    }

    int getValue();

    default FlagsEnum flags() {
        return new FlagsEnum<>(this);
    }

    @SuppressWarnings(NON_UNCHECKED)
    default FlagsEnum flags(T... nEnum) {
        FlagsEnum flagsEnum = flags();
        flagsEnum.add(nEnum);
        return flagsEnum;
    }

    @SuppressWarnings(NON_UNCHECKED)
    @SneakyThrows
    default String description() {
        Class type = this.getClass();
        return Extends.metadata(type.getField(((T) this).name()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy