mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-08-30 05:40:34 +00:00
add Column#forRanges
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.api.util;
|
package com.dfsek.terra.api.util;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.util.function.IntIntObjConsumer;
|
||||||
import com.dfsek.terra.api.util.function.IntObjConsumer;
|
import com.dfsek.terra.api.util.function.IntObjConsumer;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -28,6 +29,22 @@ public interface Column<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void forRanges(IntIntObjConsumer<T> consumer) {
|
||||||
|
int y = getMinY();
|
||||||
|
int runningMin = y;
|
||||||
|
T runningObj = get(runningMin);
|
||||||
|
do {
|
||||||
|
y++;
|
||||||
|
T current = get(y);
|
||||||
|
|
||||||
|
if(!current.equals(runningObj)) {
|
||||||
|
consumer.accept(runningMin, y, runningObj);
|
||||||
|
runningMin = y;
|
||||||
|
runningObj = current;
|
||||||
|
}
|
||||||
|
} while(y < getMaxY());
|
||||||
|
}
|
||||||
|
|
||||||
default List<? extends T> asList() {
|
default List<? extends T> asList() {
|
||||||
List<T> list = new ArrayList<>();
|
List<T> list = new ArrayList<>();
|
||||||
forEach((Consumer<T>) list::add);
|
forEach((Consumer<T>) list::add);
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.dfsek.terra.api.util.function;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IntIntObjConsumer<T> {
|
||||||
|
void accept(int i, int j, T obj);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user