gdxapp4d/demo4d-bassboonyd/src/main/love/distributedrebirth/bassboonyd/BãßBȍőnEnumSetʸᴰ.java

84 lines
1.7 KiB
Java
Raw Normal View History

2022-02-02 15:29:29 +00:00
package love.distributedrebirth.bassboonyd;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;
/**
2022-02-02 15:29:29 +00:00
* Inject EnumSet methods.
*
* @author willemtsade ©Δ 仙上主天
*/
2022-02-02 16:34:46 +00:00
public interface BãßBȍőnEnumSetʸᴰ<T> extends BãßBȍőnEnumʸᴰ<T> {
2022-02-02 16:34:46 +00:00
int ordinal();
default int dingRangTelNul() {
return ordinal();
}
default int dingRangTelEen() {
return ordinal() + 1;
}
@SuppressWarnings("unchecked")
default T[] staticInstances() {
try {
2022-02-02 16:34:46 +00:00
Object result = getClass().getMethod(BãßBȍőnConstants.STR_VALUES).invoke(null);
return (T[]) result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
default List<T> staticInstancesList() {
return Arrays.asList(staticInstances());
}
default Iterator<T> staticInstancesIterator() {
return staticInstancesList().iterator();
}
default Stream<T> staticInstancesStream() {
return staticInstancesList().stream();
}
default T volgende() {
T[] values = staticInstances();
int resultIndex = 0;
for (int i=0;i<values.length;i++) {
if (this == values[i]) {
resultIndex = i + 1;
break;
}
}
if (resultIndex == values.length) {
resultIndex = 0;
}
return values[resultIndex];
}
default T vorige() {
T[] values = staticInstances();
int resultIndex = 0;
for (int i=0;i<values.length;i++) {
if (this == values[i]) {
resultIndex = i - 1;
break;
}
}
if (resultIndex < 0) {
resultIndex = values.length - 1;
}
return values[resultIndex];
}
default void staticVoorElk(Consumer<T> consumer) {
for (T value:staticInstances()) {
consumer.accept(value);
}
}
}