summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
diff options
context:
space:
mode:
authorEVE <EVE@EVE-PC>2017-03-13 16:42:21 -0400
committerEVE <EVE@EVE-PC>2017-03-13 16:42:21 -0400
commit27bf571d6413c3cc6a5d664b5bddd38d21d7b1cd (patch)
tree847fb52acb091c1c613d37b8477094d5762c6988 /BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
parentaa807a96cae2c47259fb38f710640883060339e9 (diff)
Formatting
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java44
1 files changed, 17 insertions, 27 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
index 6339795..3a037d7 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Lazy.java
@@ -9,28 +9,27 @@ import bjc.utils.funcdata.FunctionalList;
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
+ * A holder that holds a means to create a value, but doesn't actually compute
+ * the value until it's needed
*
* @author ben
*
* @param <ContainedType>
*/
public class Lazy<ContainedType> implements IHolder<ContainedType> {
- private Supplier<ContainedType> valueSupplier;
+ private Supplier<ContainedType> valueSupplier;
- private IList<UnaryOperator<
- ContainedType>> actions = new FunctionalList<>();
+ private IList<UnaryOperator<ContainedType>> actions = new FunctionalList<>();
- private boolean valueMaterialized;
+ private boolean valueMaterialized;
- private ContainedType heldValue;
+ private ContainedType heldValue;
/**
* Create a new lazy value from the specified seed value
*
* @param value
- * The seed value to use
+ * The seed value to use
*/
public Lazy(ContainedType value) {
heldValue = value;
@@ -42,7 +41,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
* 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(Supplier<ContainedType> supp) {
valueSupplier = new SingleSupplier<>(supp);
@@ -50,18 +49,15 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
valueMaterialized = false;
}
- private Lazy(Supplier<ContainedType> supp,
- IList<UnaryOperator<ContainedType>> pendingActions) {
+ private Lazy(Supplier<ContainedType> supp, IList<UnaryOperator<ContainedType>> pendingActions) {
valueSupplier = supp;
actions = pendingActions;
}
@Override
- public <BoundType> IHolder<BoundType> bind(
- Function<ContainedType, IHolder<BoundType>> binder) {
- IList<UnaryOperator<
- ContainedType>> pendingActions = new FunctionalList<>();
+ public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
+ IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
@@ -79,18 +75,15 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(
- Function<ContainedType, NewType> func) {
+ public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func) {
return (val) -> {
return new Lazy<>(func.apply(val));
};
}
@Override
- public <MappedType> IHolder<MappedType> map(
- Function<ContainedType, MappedType> mapper) {
- IList<UnaryOperator<
- ContainedType>> pendingActions = new FunctionalList<>();
+ public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper) {
+ IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
actions.forEach(pendingActions::add);
@@ -101,8 +94,7 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
currVal = valueSupplier.get();
}
- return pendingActions.reduceAux(currVal,
- UnaryOperator<ContainedType>::apply,
+ return pendingActions.reduceAux(currVal, UnaryOperator<ContainedType>::apply,
(value) -> mapper.apply(value));
});
}
@@ -121,16 +113,14 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public IHolder<ContainedType> transform(
- UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
actions.add(transformer);
return this;
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(
- Function<ContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
if (!valueMaterialized) {
heldValue = valueSupplier.get();