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

monniasza.collects.StaticList Maven / Gradle / Ivy

Go to download

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<

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy