All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minestom.server.utils.collection.IntMappedArray Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy