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<
The newest version!
/**
*
*/
package monniasza.collects;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
/**
* A list which can't be resized
* @author oskar
* @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 source array
*/
@SafeVarargs
public StaticList(E... array) {
this.array = Arrays.copyOf(array, array.length, Object[].class);
}
/**
* Creates a fixed size list of a given size
* @param size size of the listt
*/
public StaticList(int size) {
array = new Object[size];
}
/**
* Creates a fixed size list from a collection
* @param c source collection
*/
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, E element) {
E value = get(index);
array[index] = element;
return value;
}
@Override
public int size() {
return array.length;
}
}