monniasza.collects.StaticList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package monniasza.collects;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
/**
* @author oskar
* A list which can't be resized
* @param type of contents
*/
public class StaticList extends AbstractList { //NOSONAR the equals() is implemented by AbstractList
private final Object[] array;
/**
* Creates a fixed size list by copying an array
* @param array
*/
@SafeVarargs
public StaticList(E... array) {
this.array = Arrays.copyOf(array, array.length, Object[].class);
}
public StaticList(int size) {
array = new Object[size];
}
public StaticList(Collection extends E> c) {
array = c.toArray();
}
@SuppressWarnings("unchecked")
@Override
public E get(int i) {
return (E) array[i];
}
@Override
public E set(int index, @SuppressWarnings("null") E element) {
E value = get(index);
array[index] = element;
return value;
}
@Override
public int size() {
return array.length;
}
}