-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8df5ffc
commit 9f9582c
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
common/src/main/java/dev/progames723/hmmm/utils/Binding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |