Skip to content

Commit

Permalink
a binding is really cool
Browse files Browse the repository at this point in the history
  • Loading branch information
Progames723 committed Feb 12, 2025
1 parent 8df5ffc commit 9f9582c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions common/src/main/java/dev/progames723/hmmm/utils/Binding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dev.progames723.hmmm.utils;

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

public class Binding<T> {
private final Supplier<T> getter;
private final Consumer<T> setter;
private final T defaultValue;

/**
* add a comment
* @param getter getter
* @param setter setter
* @param defaultValue default value
*/
public Binding(Supplier<T> getter, Consumer<T> setter, T defaultValue) {
this.getter = getter;
this.setter = setter;
this.defaultValue = defaultValue;
}

/**
* gets value
* @return {@link T} aka the class that this instance uses
*/
public T getValue() {
return getter.get();
}

/**
* sets value
* @param value value
*/
public void setValue(T value) {
setter.accept(value);
}

/**
* gets default value
* @return {@link T} aka the class that this instance uses
*/
public T getDefaultValue() {
return defaultValue;
}
}

0 comments on commit 9f9582c

Please sign in to comment.