add IntObjConsumer and forEach implementation in Column

This commit is contained in:
dfsek
2022-06-08 18:35:49 -07:00
parent 84cb428b6c
commit 2307138fa8
2 changed files with 15 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
package com.dfsek.terra.api.util;
import com.dfsek.terra.api.util.function.IntObjConsumer;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
@@ -20,9 +22,15 @@ public interface Column<T> {
}
}
default void forEach(IntObjConsumer<T> consumer) {
for(int y = getMinY(); y < getMaxY(); y++) {
consumer.accept(y, get(y));
}
}
default List<? extends T> asList() {
List<T> list = new ArrayList<>();
forEach(list::add);
forEach((Consumer<T>) list::add);
return list;
}
}

View File

@@ -0,0 +1,6 @@
package com.dfsek.terra.api.util.function;
@FunctionalInterface
public interface IntObjConsumer<T> {
void accept(int i, T obj);
}