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

mmb.data.variables.Variable 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 mmb.data.variables;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

import mmb.NN;

/**
 * @author oskar
 * @param  type of variable
 *
 */
public interface Variable extends Property{
	/**
	 * 
	 * @param value
	 */
	public void set(T value);
	
	public static @NN  Variable delegate(Supplier getter, Consumer setter){
		return new Variable() {

			@Override
			public U get() {
				return getter.get();
			}

			@Override
			public void set(U value) {
				setter.accept(value);
			}
		};
	}
	
	public static @NN  Variable ofArraySlot(int slot, U[] array){
		return delegate(() -> array[slot], val -> array[slot] = val);
	}
	
	public static @NN  Variable ofListSlot(int slot, List array){
		return delegate(() -> array.get(slot), val -> array.set(slot, val));
	}
}