org.rx.bean.NEnum Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxlib Show documentation
Show all versions of rxlib Show documentation
A set of utilities for Java
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()));
}
}