net.minestom.server.utils.collection.IntMappedArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of minestom-snapshots Show documentation
Show all versions of minestom-snapshots Show documentation
1.20.4 Lightweight Minecraft server
package net.minestom.server.utils.collection;
import org.jetbrains.annotations.ApiStatus;
import java.util.AbstractList;
import java.util.Objects;
import java.util.function.IntFunction;
@ApiStatus.Internal
public final class IntMappedArray extends AbstractList {
private final int[] elements;
private final IntFunction function;
public IntMappedArray(int[] elements, IntFunction function) {
this.elements = elements;
this.function = function;
}
@Override
public R get(int index) {
final int[] elements = this.elements;
Objects.checkIndex(index, elements.length);
return function.apply(elements[index]);
}
@Override
public int size() {
return elements.length;
}
}