summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/data/Lazy.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-11 13:41:07 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-11 13:41:07 -0300
commit946cab444bc301d8a7c756a1bab039558288de89 (patch)
tree419f27c39a509bcd83cae0e6630be8eb7ff95a30 /base/src/main/java/bjc/utils/data/Lazy.java
parentc82e3b3b2de0633317ec8fc85925e91422820597 (diff)
Cleanup work
Diffstat (limited to 'base/src/main/java/bjc/utils/data/Lazy.java')
-rw-r--r--base/src/main/java/bjc/utils/data/Lazy.java34
1 files changed, 20 insertions, 14 deletions
diff --git a/base/src/main/java/bjc/utils/data/Lazy.java b/base/src/main/java/bjc/utils/data/Lazy.java
index ca41b62..fcebb70 100644
--- a/base/src/main/java/bjc/utils/data/Lazy.java
+++ b/base/src/main/java/bjc/utils/data/Lazy.java
@@ -10,26 +10,29 @@ import bjc.utils.funcdata.IList;
/**
* A holder that holds a means to create a value, but doesn't actually compute
- * the value until it's needed
+ * the value until it's needed.
*
* @author ben
*
* @param <ContainedType>
+ * The type of the value being held.
*/
public class Lazy<ContainedType> implements IHolder<ContainedType> {
+ /* The supplier of the type. */
private Supplier<ContainedType> valueSupplier;
-
- private IList<UnaryOperator<ContainedType>> actions = new FunctionalList<>();
-
+ /* The actual type value. */
+ private ContainedType heldValue;
+ /* Whether the value has been created. */
private boolean valueMaterialized;
- private ContainedType heldValue;
+ /* The list of pending actions on the value. */
+ private IList<UnaryOperator<ContainedType>> actions = new FunctionalList<>();
/**
- * Create a new lazy value from the specified seed value
+ * Create a new lazy value from the specified seed value.
*
* @param value
- * The seed value to use
+ * The seed value to use.
*/
public Lazy(final ContainedType value) {
heldValue = value;
@@ -38,10 +41,10 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
}
/**
- * Create a new lazy value from the specified value source
+ * Create a new lazy value from the specified value source.
*
* @param supp
- * The source of a value to use
+ * The source of a value to use.
*/
public Lazy(final Supplier<ContainedType> supp) {
valueSupplier = new SingleSupplier<>(supp);
@@ -49,6 +52,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
valueMaterialized = false;
}
+ /* Create a new value from a supplier and a list of actions. */
private Lazy(final Supplier<ContainedType> supp, final IList<UnaryOperator<ContainedType>> pendingActions) {
valueSupplier = supp;
@@ -171,9 +175,10 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
* Create a new lazy container with an already present value.
*
* @param val
- * The value for the lazy container.
+ * The value for the lazy container.
*
- * @return A new lazy container holding that value.
+ * @return
+ * A new lazy container holding that value.
*/
public static <ContainedType> Lazy<ContainedType> lazy(final ContainedType val) {
return new Lazy<>(val);
@@ -183,10 +188,11 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
* Create a new lazy container with a suspended value.
*
* @param supp
- * The suspended value for the lazy container.
+ * The suspended value for the lazy container.
*
- * @return A new lazy container that will un-suspend the value when
- * necessary.
+ * @return
+ * A new lazy container that will un-suspend the value when
+ * necessary.
*/
public static <ContainedType> Lazy<ContainedType> lazy(final Supplier<ContainedType> supp) {
return new Lazy<>(supp);