summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/data/internals/BoundLazy.java
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-04-13 18:43:13 -0400
committerBen Culkin <scorpress@gmail.com>2020-04-13 18:43:13 -0400
commitf51f6da7319787348c38b875652b5c0e9f88c8aa (patch)
tree943888fc724da2d2dedd89abec99dcbfcc089fd0 /src/main/java/bjc/data/internals/BoundLazy.java
parent9052ed6da37af23ea82588d248f409e60a33c6cb (diff)
Cleanup pass
Pass to do some cleanups
Diffstat (limited to 'src/main/java/bjc/data/internals/BoundLazy.java')
-rw-r--r--src/main/java/bjc/data/internals/BoundLazy.java66
1 files changed, 38 insertions, 28 deletions
diff --git a/src/main/java/bjc/data/internals/BoundLazy.java b/src/main/java/bjc/data/internals/BoundLazy.java
index 728af8e..9c984eb 100644
--- a/src/main/java/bjc/data/internals/BoundLazy.java
+++ b/src/main/java/bjc/data/internals/BoundLazy.java
@@ -15,7 +15,8 @@ import bjc.funcdata.IList;
* @author Ben Culkin
*/
@SuppressWarnings("javadoc")
-public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundContainedType> {
+public class BoundLazy<OldType, BoundContainedType>
+ implements IHolder<BoundContainedType> {
/* The old value. */
private final Supplier<IHolder<OldType>> oldSupplier;
@@ -29,16 +30,17 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
private boolean holderBound;
/* Transformations currently pending on the bound value. */
- private final IList<UnaryOperator<BoundContainedType>> actions = new FunctionalList<>();
+ private final IList<UnaryOperator<BoundContainedType>> actions
+ = new FunctionalList<>();
/**
* Create a new bound lazy value.
*
* @param supp
- * The supplier of the old value.
+ * The supplier of the old value.
*
* @param binder
- * The function to use to bind the old value to the new one.
+ * The function to use to bind the old value to the new one.
*/
public BoundLazy(final Supplier<IHolder<OldType>> supp,
final Function<OldType, IHolder<BoundContainedType>> binder) {
@@ -47,11 +49,14 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
}
@Override
- public <BoundType> IHolder<BoundType> bind(final Function<BoundContainedType, IHolder<BoundType>> bindr) {
- if(bindr == null) throw new NullPointerException("Binder must not be null");
+ public <BoundType> IHolder<BoundType>
+ bind(final Function<BoundContainedType, IHolder<BoundType>> bindr) {
+ if (bindr == null)
+ throw new NullPointerException("Binder must not be null");
/* Prepare a list of pending actions. */
- final IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
+ final IList<UnaryOperator<BoundContainedType>> pendingActions
+ = new FunctionalList<>();
actions.forEach(pendingActions::add);
/* Create the new supplier of a value. */
@@ -59,35 +64,37 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
IHolder<BoundContainedType> oldHolder = boundHolder;
/* Bind the value if it hasn't been bound before. */
- if(!holderBound) {
+ if (!holderBound) {
oldHolder = oldSupplier.get().unwrap(binder);
}
/* Apply all the pending actions. */
- return pendingActions.reduceAux(oldHolder, (action, state) -> {
- return state.transform(action);
- }, (value) -> value);
+ return pendingActions.reduceAux(oldHolder, (action, state) -> state.transform(action), value -> value);
};
return new BoundLazy<>(typeSupplier, bindr);
}
@Override
- public <NewType> Function<BoundContainedType, IHolder<NewType>> lift(
- final Function<BoundContainedType, NewType> func) {
- if(func == null) throw new NullPointerException("Function to lift must not be null");
+ public <NewType> Function<BoundContainedType, IHolder<NewType>>
+ lift(final Function<BoundContainedType, NewType> func) {
+ if (func == null)
+ throw new NullPointerException("Function to lift must not be null");
- return (val) -> {
+ return val -> {
return new Lazy<>(func.apply(val));
};
}
@Override
- public <MappedType> IHolder<MappedType> map(final Function<BoundContainedType, MappedType> mapper) {
- if(mapper == null) throw new NullPointerException("Mapper must not be null");
+ public <MappedType> IHolder<MappedType>
+ map(final Function<BoundContainedType, MappedType> mapper) {
+ if (mapper == null)
+ throw new NullPointerException("Mapper must not be null");
/* Prepare a list of pending actions. */
- final IList<UnaryOperator<BoundContainedType>> pendingActions = new FunctionalList<>();
+ final IList<UnaryOperator<BoundContainedType>> pendingActions
+ = new FunctionalList<>();
actions.forEach(pendingActions::add);
/* Prepare the new supplier. */
@@ -95,14 +102,12 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
IHolder<BoundContainedType> oldHolder = boundHolder;
/* Bound the value if it hasn't been bound. */
- if(!holderBound) {
+ if (!holderBound) {
oldHolder = oldSupplier.get().unwrap(binder);
}
/* Apply pending actions. */
- return pendingActions.reduceAux(oldHolder.getValue(), (action, state) -> {
- return action.apply(state);
- }, (value) -> mapper.apply(value));
+ return pendingActions.reduceAux(oldHolder.getValue(), (action, state) -> action.apply(state), value -> mapper.apply(value));
};
return new Lazy<>(typeSupplier);
@@ -110,14 +115,17 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
@Override
public String toString() {
- if(holderBound) return boundHolder.toString();
+ if (holderBound)
+ return boundHolder.toString();
return "(unmaterialized)";
}
@Override
- public IHolder<BoundContainedType> transform(final UnaryOperator<BoundContainedType> transformer) {
- if(transformer == null) throw new NullPointerException("Transformer must not be null");
+ public IHolder<BoundContainedType>
+ transform(final UnaryOperator<BoundContainedType> transformer) {
+ if (transformer == null)
+ throw new NullPointerException("Transformer must not be null");
actions.add(transformer);
@@ -125,10 +133,12 @@ public class BoundLazy<OldType, BoundContainedType> implements IHolder<BoundCont
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<BoundContainedType, UnwrappedType> unwrapper) {
- if(unwrapper == null) throw new NullPointerException("Unwrapper must not be null");
+ public <UnwrappedType> UnwrappedType
+ unwrap(final Function<BoundContainedType, UnwrappedType> unwrapper) {
+ if (unwrapper == null)
+ throw new NullPointerException("Unwrapper must not be null");
- if(!holderBound) {
+ if (!holderBound) {
boundHolder = oldSupplier.get().unwrap(binder::apply);
}