勉强能用的依赖加载系统做好了
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
package com.ilummc.tlib.bean;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class BooleanProperty {
|
||||
|
||||
private boolean property;
|
||||
|
||||
public BooleanProperty(boolean property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public void addListener(BiConsumer<Boolean, Boolean> consumer) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,41 @@
|
||||
package com.ilummc.tlib.bean;
|
||||
|
||||
public class Property {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class Property<T> {
|
||||
|
||||
private Property(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private List<BiConsumer<T, T>> consumers;
|
||||
|
||||
private T value;
|
||||
|
||||
public void set(T value) {
|
||||
if (value != this.value) {
|
||||
if (consumers != null)
|
||||
for (BiConsumer<T, T> consumer : consumers) {
|
||||
consumer.accept(this.value, value);
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public T get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void addListener(BiConsumer<T, T> consumer) {
|
||||
if (consumers == null)
|
||||
consumers = new ArrayList<>();
|
||||
consumers.add(consumer);
|
||||
}
|
||||
|
||||
public static <T> Property<T> of(T value) {
|
||||
return new Property<>(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user