summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java47
1 files changed, 21 insertions, 26 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
index 8807312..142057c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/ListHolder.java
@@ -1,12 +1,12 @@
package bjc.utils.data;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
+
import bjc.utils.data.internals.BoundListHolder;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
/**
* A holder that represents a set of non-deterministic computations
*
@@ -25,50 +25,50 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
* The possible values for the computation
*/
@SafeVarargs
- public ListHolder(ContainedType... values) {
+ public ListHolder(final ContainedType... values) {
heldValues = new FunctionalList<>();
if (values != null) {
- for (ContainedType containedValue : values) {
+ for (final ContainedType containedValue : values) {
heldValues.add(containedValue);
}
}
}
- private ListHolder(IList<ContainedType> toHold) {
+ private ListHolder(final IList<ContainedType> toHold) {
heldValues = toHold;
}
@Override
- public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- IList<IHolder<BoundType>> boundValues = heldValues.map(binder);
+ public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) {
+ final IList<IHolder<BoundType>> boundValues = heldValues.map(binder);
return new BoundListHolder<>(boundValues);
}
@Override
- public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func) {
+ public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) {
return val -> {
return new ListHolder<>(new FunctionalList<>(func.apply(val)));
};
}
@Override
- public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper) {
- IList<MappedType> mappedValues = heldValues.map(mapper);
+ public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) {
+ final IList<MappedType> mappedValues = heldValues.map(mapper);
return new ListHolder<>(mappedValues);
}
@Override
- public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) {
heldValues = heldValues.map(transformer);
return this;
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
return unwrapper.apply(heldValues.randItem());
}
@@ -82,27 +82,22 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
final int prime = 31;
int result = 1;
- result = prime * result + ((heldValues == null) ? 0 : heldValues.hashCode());
+ result = prime * result + (heldValues == null ? 0 : heldValues.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof ListHolder<?>))
- return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof ListHolder<?>)) return false;
- ListHolder<?> other = (ListHolder<?>) obj;
+ final ListHolder<?> other = (ListHolder<?>) obj;
if (heldValues == null) {
- if (other.heldValues != null)
- return false;
- } else if (!heldValues.equals(other.heldValues))
- return false;
+ if (other.heldValues != null) return false;
+ } else if (!heldValues.equals(other.heldValues)) return false;
return true;
}