summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/data/ListHolder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/bjc/data/ListHolder.java')
-rw-r--r--src/main/java/bjc/data/ListHolder.java44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/main/java/bjc/data/ListHolder.java b/src/main/java/bjc/data/ListHolder.java
index 077c0fb..ab3bfa8 100644
--- a/src/main/java/bjc/data/ListHolder.java
+++ b/src/main/java/bjc/data/ListHolder.java
@@ -13,7 +13,7 @@ import bjc.funcdata.IList;
* @author ben
*
* @param <ContainedType>
- * The type of contained value.
+ * The type of contained value.
*/
public class ListHolder<ContainedType> implements IHolder<ContainedType> {
private IList<ContainedType> heldValues;
@@ -22,14 +22,14 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
* Create a new list holder.
*
* @param values
- * The possible values for the computation.
+ * The possible values for the computation.
*/
@SafeVarargs
public ListHolder(final ContainedType... values) {
heldValues = new FunctionalList<>();
- if(values != null) {
- for(final ContainedType containedValue : values) {
+ if (values != null) {
+ for (final ContainedType containedValue : values) {
heldValues.add(containedValue);
}
}
@@ -41,35 +41,38 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
}
@Override
- public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> 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(final Function<ContainedType, NewType> func) {
- return val -> {
- return new ListHolder<>(new FunctionalList<>(func.apply(val)));
- };
+ public <NewType> Function<ContainedType, IHolder<NewType>>
+ lift(final Function<ContainedType, NewType> func) {
+ return val -> new ListHolder<>(new FunctionalList<>(func.apply(val)));
}
@Override
- public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> 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(final UnaryOperator<ContainedType> transformer) {
+ public IHolder<ContainedType>
+ transform(final UnaryOperator<ContainedType> transformer) {
heldValues = heldValues.map(transformer);
return this;
}
@Override
- public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
+ public <UnwrappedType> UnwrappedType
+ unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
return unwrapper.apply(heldValues.randItem());
}
@@ -90,15 +93,20 @@ public class ListHolder<ContainedType> implements IHolder<ContainedType> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof ListHolder<?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ListHolder<?>))
+ return false;
final ListHolder<?> other = (ListHolder<?>) obj;
- if(heldValues == null) {
- if(other.heldValues != null) return false;
- } else if(!heldValues.equals(other.heldValues)) return false;
+ if (heldValues == null) {
+ if (other.heldValues != null)
+ return false;
+ } else if (!heldValues.equals(other.heldValues))
+ return false;
return true;
}