
mmb.data.variables.Variable Maven / Gradle / Ivy
/**
*
*/
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));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy