Browse Source

Ensure mutable lazy values executes actions on value if set.

pull/222/head
weisj 4 years ago
parent
commit
bd35c0b65b
  1. 8
      utils/src/main/java/com/github/weisj/darklaf/util/LazyValue.java
  2. 6
      utils/src/main/java/com/github/weisj/darklaf/util/MutableLazyValue.java

8
utils/src/main/java/com/github/weisj/darklaf/util/LazyValue.java

@ -39,18 +39,24 @@ public class LazyValue<T> {
}
public boolean isInitialized() {
return supplier == null;
return discardSupplierOnLoad() ? supplier == null : value != null;
}
protected T load() {
if (supplier != null) {
T obj = supplier.get();
if (discardSupplierOnLoad()) {
supplier = null;
}
return obj;
}
return value;
}
protected boolean discardSupplierOnLoad() {
return true;
}
protected void set(final T value) {
this.value = value;
}

6
utils/src/main/java/com/github/weisj/darklaf/util/MutableLazyValue.java

@ -25,7 +25,6 @@ import java.util.function.Supplier;
public class MutableLazyValue<T> extends LazyValue<T> {
public MutableLazyValue(final T value) {
super(value);
}
@ -37,4 +36,9 @@ public class MutableLazyValue<T> extends LazyValue<T> {
public void set(final T value) {
super.set(value);
}
@Override
protected boolean discardSupplierOnLoad() {
return false;
}
}

Loading…
Cancel
Save