shz.core.enums.IEnum Maven / Gradle / Ivy
package shz.core.enums;
import shz.core.*;
import java.io.Serializable;
import java.util.*;
import java.util.function.Predicate;
public interface IEnum extends Serializable {
String name();
int ordinal();
C getCode();
V getValue();
static > T get(Class cls, Predicate predicate) {
List ts = EnumHelp.enumSet(cls);
if (ts.isEmpty()) return null;
return ts.stream().filter(predicate).findFirst().orElse(null);
}
static > List gets(Class cls, Predicate predicate) {
List ts = EnumHelp.enumSet(cls);
if (ts.isEmpty()) return Collections.emptyList();
return ToList.explicitCollect(ts.stream().filter(predicate), ts.size());
}
static > T getByName(Class cls, String name) {
return get(cls, e -> Objects.equals(name, e.name()));
}
static > List getByNames(Class cls, String... names) {
if (NullHelp.isEmpty(names)) return Collections.emptyList();
Set set = ToSet.explicitCollect(Arrays.stream(names).filter(Objects::nonNull), names.length);
if (set.isEmpty()) return Collections.emptyList();
return gets(cls, e -> set.contains(e.name()));
}
static > T getByCode(Class cls, Object code) {
return get(cls, e -> Objects.equals(code, e.getCode()));
}
static > List getByCodes(Class cls, Object... codes) {
if (NullHelp.isEmpty(codes)) return Collections.emptyList();
Set