summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2020-11-11 12:23:57 -0400
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2020-11-11 12:23:57 -0400
commit0805c271505340c1da60a1b8920560bae73f21a9 (patch)
tree2703917145a8e8aee7bd4ad55634c65ed688dda6 /src/main/java
parentd3239ea7b6945d449c0361416ab54fec6f9643e6 (diff)
parentc56a10f7c943dd9e9f04854395638babfaba6529 (diff)
Merge branch 'master' of https://github.com/bculkin2442/esodata
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/bjc/data/ArrayIterator.java3
-rw-r--r--src/main/java/bjc/data/BooleanToggle.java17
-rw-r--r--src/main/java/bjc/data/Either.java80
-rw-r--r--src/main/java/bjc/data/IPair.java3
-rw-r--r--src/main/java/bjc/data/ITree.java3
-rw-r--r--src/main/java/bjc/data/Identity.java15
-rw-r--r--src/main/java/bjc/data/IntHolder.java72
-rw-r--r--src/main/java/bjc/data/Lazy.java62
-rw-r--r--src/main/java/bjc/data/LazyPair.java66
-rw-r--r--src/main/java/bjc/data/ListHolder.java15
-rw-r--r--src/main/java/bjc/data/OneWayToggle.java10
-rw-r--r--src/main/java/bjc/data/Option.java28
-rw-r--r--src/main/java/bjc/data/Pair.java41
-rw-r--r--src/main/java/bjc/data/QueuedIterator.java15
-rw-r--r--src/main/java/bjc/data/ResettableIterator.java7
-rw-r--r--src/main/java/bjc/data/TopDownTransformIterator.java18
-rw-r--r--src/main/java/bjc/data/Tree.java49
-rw-r--r--src/main/java/bjc/data/ValueToggle.java14
-rw-r--r--src/main/java/bjc/esodata/AbbrevMap2.java15
-rw-r--r--src/main/java/bjc/esodata/DefaultList.java6
-rw-r--r--src/main/java/bjc/esodata/Directory.java3
-rw-r--r--src/main/java/bjc/esodata/DoubleTape.java29
-rw-r--r--src/main/java/bjc/esodata/MapSet.java9
-rw-r--r--src/main/java/bjc/esodata/Multimap.java14
-rw-r--r--src/main/java/bjc/esodata/PushdownMap.java19
-rw-r--r--src/main/java/bjc/esodata/QueueStack.java21
-rw-r--r--src/main/java/bjc/esodata/SimpleDirectory.java21
-rw-r--r--src/main/java/bjc/esodata/SimpleStack.java21
-rw-r--r--src/main/java/bjc/esodata/SingleTape.java63
-rw-r--r--src/main/java/bjc/esodata/SpaghettiStack.java27
-rw-r--r--src/main/java/bjc/esodata/Stack.java36
-rw-r--r--src/main/java/bjc/esodata/ThresholdSet.java30
-rw-r--r--src/main/java/bjc/esodata/UnifiedDirectory.java21
-rw-r--r--src/main/java/bjc/funcdata/bst/BinarySearchTree.java11
34 files changed, 381 insertions, 483 deletions
diff --git a/src/main/java/bjc/data/ArrayIterator.java b/src/main/java/bjc/data/ArrayIterator.java
index 6d11a1d..c5f68cc 100644
--- a/src/main/java/bjc/data/ArrayIterator.java
+++ b/src/main/java/bjc/data/ArrayIterator.java
@@ -34,8 +34,7 @@ public class ArrayIterator<T> implements Iterator<T> {
@SuppressWarnings("unchecked")
@Override
public T next() {
- if (idx >= arr.length)
- return null;
+ if (idx >= arr.length) return null;
return (T) (arr[idx++]);
}
diff --git a/src/main/java/bjc/data/BooleanToggle.java b/src/main/java/bjc/data/BooleanToggle.java
index af083f5..e0286d4 100644
--- a/src/main/java/bjc/data/BooleanToggle.java
+++ b/src/main/java/bjc/data/BooleanToggle.java
@@ -59,23 +59,18 @@ public class BooleanToggle implements Toggle<Boolean> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof BooleanToggle))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof BooleanToggle)) return false;
final BooleanToggle other = (BooleanToggle) obj;
- if (val != other.val)
- return false;
-
- return true;
+ if (val != other.val) return false;
+ else return true;
}
@Override
public String toString() {
- return String.format("BooleanToggle [val=%s]", val);
+ return String.format("%s", val);
}
}
diff --git a/src/main/java/bjc/data/Either.java b/src/main/java/bjc/data/Either.java
index 55518d8..0ac3181 100644
--- a/src/main/java/bjc/data/Either.java
+++ b/src/main/java/bjc/data/Either.java
@@ -75,8 +75,7 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
final BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
- if (binder == null)
- throw new NullPointerException("Binder must not be null");
+ if (binder == null) throw new NullPointerException("Binder must not be null");
return binder.apply(leftVal, rightVal);
}
@@ -84,25 +83,19 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <BoundLeft> IPair<BoundLeft, RightType>
bindLeft(final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- if (leftBinder == null)
- throw new NullPointerException("Left binder must not be null");
+ if (leftBinder == null) throw new NullPointerException("Left binder must not be null");
- if (isLeft)
- return leftBinder.apply(leftVal);
-
- return new Either<>(null, rightVal);
+ if (isLeft) return leftBinder.apply(leftVal);
+ else return new Either<>(null, rightVal);
}
@Override
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- if (rightBinder == null)
- throw new NullPointerException("Right binder must not be null");
-
- if (isLeft)
- return new Either<>(leftVal, null);
+ if (rightBinder == null) throw new NullPointerException("Right binder must not be null");
- return rightBinder.apply(rightVal);
+ if (isLeft) return new Either<>(leftVal, null);
+ else return rightBinder.apply(rightVal);
}
@Override
@@ -126,44 +119,37 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
return new Either<>(cLeft, null);
});
+ } else {
+ return otherPair.bind((otherLeft, otherRight) -> {
+ CombinedRight cRight = rightCombiner.apply(rightVal, otherRight);
+
+ return new Either<>(null, cRight);
+ });
}
-
- return otherPair.bind((otherLeft, otherRight) -> {
- CombinedRight cRight = rightCombiner.apply(rightVal, otherRight);
-
- return new Either<>(null, cRight);
- });
}
@Override
public <NewLeft> IPair<NewLeft, RightType>
mapLeft(final Function<LeftType, NewLeft> mapper) {
- if (mapper == null)
- throw new NullPointerException("Mapper must not be null");
-
- if (isLeft)
- return new Either<>(mapper.apply(leftVal), null);
+ if (mapper == null) throw new NullPointerException("Mapper must not be null");
- return new Either<>(null, rightVal);
+ if (isLeft) return new Either<>(mapper.apply(leftVal), null);
+ else return new Either<>(null, rightVal);
}
@Override
public <NewRight> IPair<LeftType, NewRight>
mapRight(final Function<RightType, NewRight> mapper) {
- if (mapper == null)
- throw new NullPointerException("Mapper must not be null");
+ if (mapper == null) throw new NullPointerException("Mapper must not be null");
- if (isLeft)
- return new Either<>(leftVal, null);
-
- return new Either<>(null, mapper.apply(rightVal));
+ if (isLeft) return new Either<>(leftVal, null);
+ else return new Either<>(null, mapper.apply(rightVal));
}
@Override
public <MergedType> MergedType
merge(final BiFunction<LeftType, RightType, MergedType> merger) {
- if (merger == null)
- throw new NullPointerException("Merger must not be null");
+ if (merger == null) throw new NullPointerException("Merger must not be null");
return merger.apply(leftVal, rightVal);
}
@@ -182,30 +168,26 @@ public class Either<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Either<?, ?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Either<?, ?>)) return false;
final Either<?, ?> other = (Either<?, ?>) obj;
- if (isLeft != other.isLeft)
- return false;
+ if (isLeft != other.isLeft) return false;
if (leftVal == null) {
- if (other.leftVal != null)
- return false;
- } else if (!leftVal.equals(other.leftVal))
+ if (other.leftVal != null) return false;
+ } else if (!leftVal.equals(other.leftVal)) {
return false;
+ }
if (rightVal == null) {
- if (other.rightVal != null)
- return false;
- } else if (!rightVal.equals(other.rightVal))
+ if (other.rightVal != null) return false;
+ } else if (!rightVal.equals(other.rightVal)) {
return false;
-
+ }
+
return true;
}
diff --git a/src/main/java/bjc/data/IPair.java b/src/main/java/bjc/data/IPair.java
index 5b1298e..f7d7956 100644
--- a/src/main/java/bjc/data/IPair.java
+++ b/src/main/java/bjc/data/IPair.java
@@ -81,7 +81,8 @@ public interface IPair<LeftType, RightType> extends Bifunctor<LeftType, RightTyp
public default <OtherLeft, OtherRight>
IPair<IPair<LeftType, OtherLeft>, IPair<RightType, OtherRight>>
combine(final IPair<OtherLeft, OtherRight> otherPair) {
- return combine(otherPair, Pair<LeftType, OtherLeft>::new,
+ return combine(otherPair,
+ Pair<LeftType, OtherLeft>::new,
Pair<RightType, OtherRight>::new);
}
diff --git a/src/main/java/bjc/data/ITree.java b/src/main/java/bjc/data/ITree.java
index e9c829e..7f9c67e 100644
--- a/src/main/java/bjc/data/ITree.java
+++ b/src/main/java/bjc/data/ITree.java
@@ -270,8 +270,7 @@ public interface ITree<ContainedType> {
Toggle<Boolean> tog = new OneWayToggle<>(false, true);
traverse(TreeLinearizationMethod.POSTORDER, val -> {
- if (pred.test(val))
- tog.get();
+ if (pred.test(val)) tog.get();
});
return tog.get();
diff --git a/src/main/java/bjc/data/Identity.java b/src/main/java/bjc/data/Identity.java
index c80c7e1..75b4ecd 100644
--- a/src/main/java/bjc/data/Identity.java
+++ b/src/main/java/bjc/data/Identity.java
@@ -48,20 +48,17 @@ public class Identity<ContainedType> implements IHolder<ContainedType> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Identity))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Identity)) return false;
final Identity<?> other = (Identity<?>) obj;
if (heldValue == null) {
- if (other.heldValue != null)
- return false;
- } else if (!heldValue.equals(other.heldValue))
+ if (other.heldValue != null) return false;
+ } else if (!heldValue.equals(other.heldValue)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/data/IntHolder.java b/src/main/java/bjc/data/IntHolder.java
new file mode 100644
index 0000000..2783669
--- /dev/null
+++ b/src/main/java/bjc/data/IntHolder.java
@@ -0,0 +1,72 @@
+package bjc.data;
+
+/**
+ * Utility class for ints by ref.
+ *
+ * @author Ben Culkin
+ */
+public class IntHolder {
+ /**
+ * The int value.
+ */
+ public int val;
+
+ /**
+ * Create a new int-holder set to 0.
+ */
+ public IntHolder() {
+ val = 0;
+ }
+
+ /**
+ * Create a new int-holder set to a value.
+ *
+ * @param i
+ * The value to set the int to.
+ */
+ public IntHolder(int i) {
+ val = i;
+ }
+
+ /**
+ * Increment the value by one, and return it.
+ *
+ * @return The value of the holder.
+ */
+ public int incr() {
+ return incr(1);
+ }
+
+ /**
+ * Increment the value by an amount and return it.
+ *
+ * @param i
+ * The amount to increment by.
+ *
+ * @return The value of the holder.
+ */
+ public int incr(int i) {
+ val += 1;
+
+ return val;
+ }
+
+ /**
+ * Get the value.
+ *
+ * @return The value.
+ */
+ public int get() {
+ return val;
+ }
+
+ /**
+ * Set the value.
+ *
+ * @param i
+ * The value to set it to.
+ */
+ public void set(int i) {
+ val = i;
+ }
+}
diff --git a/src/main/java/bjc/data/Lazy.java b/src/main/java/bjc/data/Lazy.java
index a425232..8573325 100644
--- a/src/main/java/bjc/data/Lazy.java
+++ b/src/main/java/bjc/data/Lazy.java
@@ -65,13 +65,14 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
bind(final Function<ContainedType, IHolder<BoundType>> binder) {
final IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
- actions.forEach(pendingActions::add);
+ for (UnaryOperator<ContainedType> action : actions) {
+ pendingActions.add(action);
+ }
+
final Supplier<ContainedType> supplier = () -> {
- if (valueMaterialized)
- return heldValue;
-
- return valueSupplier.get();
+ if (valueMaterialized) return heldValue;
+ else return valueSupplier.get();
};
return new BoundLazy<>(() -> new Lazy<>(supplier, pendingActions), binder);
@@ -87,8 +88,10 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
public <MappedType> IHolder<MappedType>
map(final Function<ContainedType, MappedType> mapper) {
final IList<UnaryOperator<ContainedType>> pendingActions = new FunctionalList<>();
-
- actions.forEach(pendingActions::add);
+
+ for (UnaryOperator<ContainedType> action : actions) {
+ pendingActions.add(action);
+ }
return new Lazy<>(() -> {
ContainedType currVal = heldValue;
@@ -97,7 +100,8 @@ 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));
});
}
@@ -107,12 +111,18 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
if (valueMaterialized) {
if (actions.isEmpty()) {
return String.format("value[v='%s']", heldValue);
+ } else {
+ return String.format("value[v='%s'] (has %d pending transforms)",
+ heldValue, actions.getSize());
}
-
- return String.format("value[v='%s'] (has pending transforms)", heldValue);
}
- return "(unmaterialized)";
+ if (actions.isEmpty()) {
+ return"(unmaterialized)";
+ } else {
+ return String.format("(unmaterialized; has %d pending transforms",
+ actions.getSize());
+ }
}
@Override
@@ -132,9 +142,9 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
valueMaterialized = true;
}
- actions.forEach(action -> {
- heldValue = action.apply(heldValue);
- });
+ for (UnaryOperator<ContainedType> action : actions) {
+ heldValue = action.apply(heldValue);
+ }
actions = new FunctionalList<>();
@@ -155,12 +165,9 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Lazy<?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Lazy<?>)) return false;
final Lazy<?> other = (Lazy<?>) obj;
@@ -169,18 +176,19 @@ public class Lazy<ContainedType> implements IHolder<ContainedType> {
if (valueMaterialized) {
if (heldValue == null) {
- if (other.heldValue != null)
- return false;
- } else if (!heldValue.equals(other.heldValue))
+ if (other.heldValue != null) return false;
+ } else if (!heldValue.equals(other.heldValue)) {
return false;
- } else
+ }
+ } else {
return false;
+ }
if (actions == null) {
- if (other.actions != null)
- return false;
- } else if (actions.getSize() > 0 || other.actions.getSize() > 0)
+ if (other.actions != null) return false;
+ } else if (actions.getSize() > 0 || other.actions.getSize() > 0) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/data/LazyPair.java b/src/main/java/bjc/data/LazyPair.java
index e668cd4..2481cd7 100644
--- a/src/main/java/bjc/data/LazyPair.java
+++ b/src/main/java/bjc/data/LazyPair.java
@@ -79,8 +79,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
public <BoundLeft> IPair<BoundLeft, RightType>
bindLeft(final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
final Supplier<LeftType> leftSupp = () -> {
- if (leftMaterialized)
- return leftValue;
+ if (leftMaterialized) return leftValue;
return leftSupplier.get();
};
@@ -92,8 +91,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
final Supplier<RightType> rightSupp = () -> {
- if (rightMaterialized)
- return rightValue;
+ if (rightMaterialized) return rightValue;
return rightSupplier.get();
};
@@ -108,12 +106,14 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
final BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner,
final BiFunction<RightType, OtherRight,
CombinedRight> rightCombiner) {
- return otherPair.bind((otherLeft, otherRight) -> bind((leftVal, rightVal) -> {
- final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft);
- final CombinedRight right = rightCombiner.apply(rightVal, otherRight);
-
- return new LazyPair<>(left, right);
- }));
+ return otherPair.bind((otherLeft, otherRight) -> {
+ return bind((leftVal, rightVal) -> {
+ final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft);
+ final CombinedRight right = rightCombiner.apply(rightVal, otherRight);
+
+ return new LazyPair<>(left, right);
+ });
+ });
}
@Override
@@ -142,15 +142,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
public <NewLeft> IPair<NewLeft, RightType>
mapLeft(final Function<LeftType, NewLeft> mapper) {
final Supplier<NewLeft> leftSupp = () -> {
- if (leftMaterialized)
- return mapper.apply(leftValue);
+ if (leftMaterialized) return mapper.apply(leftValue);
return mapper.apply(leftSupplier.get());
};
final Supplier<RightType> rightSupp = () -> {
- if (rightMaterialized)
- return rightValue;
+ if (rightMaterialized) return rightValue;
return rightSupplier.get();
};
@@ -162,15 +160,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
public <NewRight> IPair<LeftType, NewRight>
mapRight(final Function<RightType, NewRight> mapper) {
final Supplier<LeftType> leftSupp = () -> {
- if (leftMaterialized)
- return leftValue;
+ if (leftMaterialized) return leftValue;
return leftSupplier.get();
};
final Supplier<NewRight> rightSupp = () -> {
- if (rightMaterialized)
- return mapper.apply(rightValue);
+ if (rightMaterialized) return mapper.apply(rightValue);
return mapper.apply(rightSupplier.get());
};
@@ -231,37 +227,35 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType>
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof LazyPair<?, ?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof LazyPair<?, ?>)) return false;
final LazyPair<?, ?> other = (LazyPair<?, ?>) obj;
- if (leftMaterialized != other.leftMaterialized)
- return false;
+ if (leftMaterialized != other.leftMaterialized) return false;
if (leftMaterialized) {
if (leftValue == null) {
- if (other.leftValue != null)
- return false;
- } else if (!leftValue.equals(other.leftValue))
+ if (other.leftValue != null) return false;
+ } else if (!leftValue.equals(other.leftValue)) {
return false;
- } else
+ }
+ } else {
return false;
+ }
- if (rightMaterialized != other.rightMaterialized)
- return false;
+ if (rightMaterialized != other.rightMaterialized) return false;
+
if (rightMaterialized) {
if (rightValue == null) {
- if (other.rightValue != null)
- return false;
- } else if (!rightValue.equals(other.rightValue))
+ if (other.rightValue != null) return false;
+ } else if (!rightValue.equals(other.rightValue)) {
return false;
- } else
+ }
+ } else {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/data/ListHolder.java b/src/main/java/bjc/data/ListHolder.java
index ab3bfa8..79c900d 100644
--- a/src/main/java/bjc/data/ListHolder.java
+++ b/src/main/java/bjc/data/ListHolder.java
@@ -93,20 +93,17 @@ 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))
+ if (other.heldValues != null) return false;
+ } else if (!heldValues.equals(other.heldValues)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/data/OneWayToggle.java b/src/main/java/bjc/data/OneWayToggle.java
index c2e9e4b..b6074b0 100644
--- a/src/main/java/bjc/data/OneWayToggle.java
+++ b/src/main/java/bjc/data/OneWayToggle.java
@@ -31,23 +31,21 @@ public class OneWayToggle<E> implements Toggle<E> {
@Override
public E get() {
- if (gotFirst)
- return second;
+ if (gotFirst) return second;
gotFirst = true;
+
return first;
}
@Override
public E peek() {
- if (gotFirst)
- return second;
- return first;
+ if (gotFirst) return second;
+ else return first;
}
@Override
public void set(boolean gotFirst) {
this.gotFirst = gotFirst;
}
-
}
diff --git a/src/main/java/bjc/data/Option.java b/src/main/java/bjc/data/Option.java
index b5d6d5e..84e71a2 100644
--- a/src/main/java/bjc/data/Option.java
+++ b/src/main/java/bjc/data/Option.java
@@ -27,8 +27,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public <BoundType> IHolder<BoundType>
bind(final Function<ContainedType, IHolder<BoundType>> binder) {
- if (held == null)
- return new Option<>(null);
+ if (held == null) return new Option<>(null);
return binder.apply(held);
}
@@ -42,8 +41,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public <MappedType> IHolder<MappedType>
map(final Function<ContainedType, MappedType> mapper) {
- if (held == null)
- return new Option<>(null);
+ if (held == null) return new Option<>(null);
return new Option<>(mapper.apply(held));
}
@@ -51,9 +49,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public IHolder<ContainedType>
transform(final UnaryOperator<ContainedType> transformer) {
- if (held != null) {
- held = transformer.apply(held);
- }
+ if (held != null) held = transformer.apply(held);
return this;
}
@@ -61,8 +57,7 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public <UnwrappedType> UnwrappedType
unwrap(final Function<ContainedType, UnwrappedType> unwrapper) {
- if (held == null)
- return null;
+ if (held == null) return null;
return unwrapper.apply(held);
}
@@ -84,20 +79,17 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Option<?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Option<?>)) return false;
final Option<?> other = (Option<?>) obj;
if (held == null) {
- if (other.held != null)
- return false;
- } else if (!held.equals(other.held))
+ if (other.held != null) return false;
+ } else if (!held.equals(other.held)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/data/Pair.java b/src/main/java/bjc/data/Pair.java
index 610e89c..ea2f82f 100644
--- a/src/main/java/bjc/data/Pair.java
+++ b/src/main/java/bjc/data/Pair.java
@@ -22,7 +22,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
/** Create a new pair with both sides set to null. */
public Pair() {
-
+ // Do nothing :)
}
/**
@@ -42,8 +42,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <BoundLeft, BoundRight> IPair<BoundLeft, BoundRight> bind(
final BiFunction<LeftType, RightType, IPair<BoundLeft, BoundRight>> binder) {
- if (binder == null)
- throw new NullPointerException("Binder must not be null.");
+ if (binder == null) throw new NullPointerException("Binder must not be null.");
return binder.apply(leftValue, rightValue);
}
@@ -51,8 +50,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <BoundLeft> IPair<BoundLeft, RightType>
bindLeft(final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) {
- if (leftBinder == null)
- throw new NullPointerException("Binder must not be null");
+ if (leftBinder == null) throw new NullPointerException("Binder must not be null");
return leftBinder.apply(leftValue);
}
@@ -60,8 +58,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <BoundRight> IPair<LeftType, BoundRight> bindRight(
final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) {
- if (rightBinder == null)
- throw new NullPointerException("Binder must not be null");
+ if (rightBinder == null) throw new NullPointerException("Binder must not be null");
return rightBinder.apply(rightValue);
}
@@ -84,8 +81,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <NewLeft> IPair<NewLeft, RightType>
mapLeft(final Function<LeftType, NewLeft> mapper) {
- if (mapper == null)
- throw new NullPointerException("Mapper must not be null");
+ if (mapper == null) throw new NullPointerException("Mapper must not be null");
return new Pair<>(mapper.apply(leftValue), rightValue);
}
@@ -93,8 +89,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <NewRight> IPair<LeftType, NewRight>
mapRight(final Function<RightType, NewRight> mapper) {
- if (mapper == null)
- throw new NullPointerException("Mapper must not be null");
+ if (mapper == null) throw new NullPointerException("Mapper must not be null");
return new Pair<>(leftValue, mapper.apply(rightValue));
}
@@ -102,8 +97,7 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public <MergedType> MergedType
merge(final BiFunction<LeftType, RightType, MergedType> merger) {
- if (merger == null)
- throw new NullPointerException("Merger must not be null");
+ if (merger == null) throw new NullPointerException("Merger must not be null");
return merger.apply(leftValue, rightValue);
}
@@ -137,26 +131,23 @@ public class Pair<LeftType, RightType> implements IPair<LeftType, RightType> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Pair<?, ?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Pair<?, ?>)) return false;
final Pair<?, ?> other = (Pair<?, ?>) obj;
if (leftValue == null) {
- if (other.leftValue != null)
- return false;
- } else if (!leftValue.equals(other.leftValue))
+ if (other.leftValue != null) return false;
+ } else if (!leftValue.equals(other.leftValue)) {
return false;
+ }
if (rightValue == null) {
- if (other.rightValue != null)
- return false;
- } else if (!rightValue.equals(other.rightValue))
+ if (other.rightValue != null) return false;
+ } else if (!rightValue.equals(other.rightValue)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/data/QueuedIterator.java b/src/main/java/bjc/data/QueuedIterator.java
index f10014e..78f180d 100644
--- a/src/main/java/bjc/data/QueuedIterator.java
+++ b/src/main/java/bjc/data/QueuedIterator.java
@@ -82,9 +82,7 @@ public class QueuedIterator<E> implements Iterator<E> {
public QueuedIterator(Iterator<E>... inits) {
this();
- for (Iterator<E> init : inits) {
- pending.add(init);
- }
+ for (Iterator<E> init : inits) pending.add(init);
}
/**
@@ -97,9 +95,7 @@ public class QueuedIterator<E> implements Iterator<E> {
public QueuedIterator(Iterable<E>... inits) {
this();
- for (Iterable<E> init : inits) {
- pending.add(init.iterator());
- }
+ for (Iterable<E> init : inits) pending.add(init.iterator());
}
/**
@@ -208,8 +204,7 @@ public class QueuedIterator<E> implements Iterator<E> {
@Override
public boolean hasNext() {
while (cur == null || !cur.hasNext()) {
- if (pending.isEmpty())
- return false;
+ if (pending.isEmpty()) return false;
cur = pending.pop();
}
@@ -220,13 +215,11 @@ public class QueuedIterator<E> implements Iterator<E> {
@Override
public E next() {
while (cur == null || !cur.hasNext()) {
- if (pending.isEmpty())
- return null;
+ if (pending.isEmpty()) return null;
cur = pending.pop();
}
return cur.next();
}
-
}
diff --git a/src/main/java/bjc/data/ResettableIterator.java b/src/main/java/bjc/data/ResettableIterator.java
index 2208fb2..8b7f07a 100644
--- a/src/main/java/bjc/data/ResettableIterator.java
+++ b/src/main/java/bjc/data/ResettableIterator.java
@@ -56,11 +56,8 @@ public class ResettableIterator<T> implements Iterator<T> {
@Override
public boolean hasNext() {
- if (isRepeating) {
- return cacheIterator.hasNext() ? true : backing.hasNext();
- } else {
- return backing.hasNext();
- }
+ if (isRepeating) return cacheIterator.hasNext() ? true : backing.hasNext();
+ else return backing.hasNext();
}
@Override
diff --git a/src/main/java/bjc/data/TopDownTransformIterator.java b/src/main/java/bjc/data/TopDownTransformIterator.java
index 3b4b997..cf211d3 100644
--- a/src/main/java/bjc/data/TopDownTransformIterator.java
+++ b/src/main/java/bjc/data/TopDownTransformIterator.java
@@ -97,9 +97,7 @@ public class TopDownTransformIterator<ContainedType>
* The nodes to yield.
*/
public void addYield(final Iterator<ITree<ContainedType>> src) {
- if (currYield != null) {
- toYield.push(currYield);
- }
+ if (currYield != null) toYield.push(currYield);
currYield = src;
}
@@ -128,9 +126,7 @@ public class TopDownTransformIterator<ContainedType>
*/
toYield.add(new SingleIterator<>(val));
- if (currYield.hasNext()) {
- return currYield.next();
- }
+ if (currYield.hasNext()) return currYield.next();
while (toYield.size() != 0 && !currYield.hasNext()) {
currYield = toYield.pop();
@@ -149,8 +145,7 @@ public class TopDownTransformIterator<ContainedType>
@Override
public ITree<ContainedType> next() {
- if (done)
- throw new NoSuchElementException();
+ if (done) throw new NoSuchElementException();
/*
* Flush any values that need to be yielded.
@@ -158,8 +153,7 @@ public class TopDownTransformIterator<ContainedType>
if (currYield != null) {
ITree<ContainedType> yeld = flushYields(null);
- if (yeld != null)
- return yeld;
+ if (yeld != null) return yeld;
}
if (initial) {
@@ -226,9 +220,7 @@ public class TopDownTransformIterator<ContainedType>
throw new IllegalArgumentException("Unknown result type " + res);
}
- if (res != RTRANSFORM) {
- initial = false;
- }
+ if (res != RTRANSFORM) initial = false;
}
if (curChild == null || !curChild.hasNext()) {
diff --git a/src/main/java/bjc/data/Tree.java b/src/main/java/bjc/data/Tree.java
index 5337af5..d0cfe3d 100644
--- a/src/main/java/bjc/data/Tree.java
+++ b/src/main/java/bjc/data/Tree.java
@@ -28,8 +28,10 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
/* Whether this node has children. */
/*
* @NOTE Why have both this boolean and childCount? Why not just do a childCount
- * == 0 whenever you'd check hasChildren? - Because hasChildren is set once and
- * not reset, and really what it indicates is that children has been allocated.
+ * == 0 whenever you'd check hasChildren?
+ *
+ * - Because hasChildren is set once and not reset, and really what it
+ * indicates is that children has been allocated.
*/
private boolean hasChildren;
/* The number of children this node has. */
@@ -139,9 +141,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public void doForChildren(final Consumer<ITree<ContainedType>> action) {
- if (childCount > 0) {
- children.forEach(action);
- }
+ if (childCount > 0) children.forEach(action);
}
@Override
@@ -151,13 +151,10 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public int revFind(final Predicate<ITree<ContainedType>> childPred) {
- if (childCount == 0) {
- return -1;
- }
+ if (childCount == 0) return -1;
for (int i = childCount - 1; i >= 0; i--) {
- if (childPred.test(getChild(i)))
- return i;
+ if (childPred.test(getChild(i))) return i;
}
return -1;
@@ -249,9 +246,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
private void internalToString(final StringBuilder builder, final int indentLevel,
final boolean initial) {
if (!initial) {
- for (int i = 0; i < indentLevel; i++) {
- builder.append(">\t");
- }
+ for (int i = 0; i < indentLevel; i++) builder.append(">\t");
}
builder.append("Node #");
@@ -284,7 +279,9 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
final Function<ContainedType, MappedType> leafTransformer,
final Function<ContainedType, MappedType> operatorTransformer) {
if (hasChildren) {
- final IList<ITree<MappedType>> mappedChildren = children.map(child -> child.rebuildTree(leafTransformer, operatorTransformer));
+ final IList<ITree<MappedType>> mappedChildren =
+ children.map(child ->
+ child.rebuildTree(leafTransformer, operatorTransformer));
final MappedType mapData = operatorTransformer.apply(data);
return new Tree<>(mapData, mappedChildren);
@@ -424,29 +421,25 @@ public class Tree<ContainedType> implements ITree<ContainedType> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof Tree<?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof Tree<?>)) return false;
final Tree<?> other = (Tree<?>) obj;
if (data == null) {
- if (other.data != null)
- return false;
- } else if (!data.equals(other.data))
+ if (other.data != null) return false;
+ } else if (!data.equals(other.data)) {
return false;
+ }
- if (childCount != other.childCount)
- return false;
+ if (childCount != other.childCount) return false;
if (children == null) {
- if (other.children != null)
- return false;
- } else if (!children.equals(other.children))
+ if (other.children != null) return false;
+ } else if (!children.equals(other.children)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/data/ValueToggle.java b/src/main/java/bjc/data/ValueToggle.java
index 041a2d5..9e4b83b 100644
--- a/src/main/java/bjc/data/ValueToggle.java
+++ b/src/main/java/bjc/data/ValueToggle.java
@@ -37,20 +37,14 @@ public class ValueToggle<E> implements Toggle<E> {
@Override
public E get() {
- if (alignment.get()) {
- return lft;
- }
-
- return rght;
+ if (alignment.get()) return lft;
+ else return rght;
}
@Override
public E peek() {
- if (alignment.peek()) {
- return lft;
- }
-
- return rght;
+ if (alignment.peek()) return lft;
+ else return rght;
}
@Override
diff --git a/src/main/java/bjc/esodata/AbbrevMap2.java b/src/main/java/bjc/esodata/AbbrevMap2.java
index f131aec..259c963 100644
--- a/src/main/java/bjc/esodata/AbbrevMap2.java
+++ b/src/main/java/bjc/esodata/AbbrevMap2.java
@@ -36,9 +36,7 @@ public class AbbrevMap2 {
*/
public void add(String... words) {
for (String word : words) {
- for (String substr : genAbbrevs(word)) {
- backing.add(substr, word);
- }
+ for (String substr : genAbbrevs(word)) backing.add(substr, word);
}
}
@@ -65,9 +63,7 @@ public class AbbrevMap2 {
*/
public void removeWords(String... words) {
for (String word : words) {
- for (String substr : genAbbrevs(word)) {
- backing.remove(substr, word);
- }
+ for (String substr : genAbbrevs(word)) backing.remove(substr, word);
}
}
@@ -95,10 +91,7 @@ public class AbbrevMap2 {
public String deabbrev(String word) {
Set<String> st = backing.get(word);
- if (st.size() == 1) {
- return st.iterator().next();
- } else {
- return null;
- }
+ if (st.size() == 1) return st.iterator().next();
+ else return null;
}
}
diff --git a/src/main/java/bjc/esodata/DefaultList.java b/src/main/java/bjc/esodata/DefaultList.java
index c4535bd..e622301 100644
--- a/src/main/java/bjc/esodata/DefaultList.java
+++ b/src/main/java/bjc/esodata/DefaultList.java
@@ -90,10 +90,8 @@ public class DefaultList<ValueType> extends AbstractList<ValueType> {
@Override
public ValueType get(int idx) {
- if (idx < 0 || idx >= backing.size())
- return defVal;
-
- return backing.get(idx);
+ if (idx < 0 || idx >= backing.size()) return defVal;
+ else return backing.get(idx);
}
@Override
diff --git a/src/main/java/bjc/esodata/Directory.java b/src/main/java/bjc/esodata/Directory.java
index e083cd8..fa47b6f 100644
--- a/src/main/java/bjc/esodata/Directory.java
+++ b/src/main/java/bjc/esodata/Directory.java
@@ -59,8 +59,7 @@ public interface Directory<K, V> {
* @return The new sub-directory, or null if one by that name already exists.
*/
default Directory<K, V> newSubdirectory(final K key) {
- if (hasSubdirectory(key))
- return null;
+ if (hasSubdirectory(key)) return null;
final Directory<K, V> dir = new SimpleDirectory<>();
diff --git a/src/main/java/bjc/esodata/DoubleTape.java b/src/main/java/bjc/esodata/DoubleTape.java
index cc7cdb9..30d94a1 100644
--- a/src/main/java/bjc/esodata/DoubleTape.java
+++ b/src/main/java/bjc/esodata/DoubleTape.java
@@ -112,9 +112,7 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided {
public boolean left(final int amt) {
final boolean succ = front.left(amt);
- if (succ) {
- back.right(amt);
- }
+ if (succ) back.right(amt);
return succ;
}
@@ -128,9 +126,7 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided {
public boolean right(final int amt) {
final boolean succ = front.right(amt);
- if (succ) {
- back.left(amt);
- }
+ if (succ) back.left(amt);
return succ;
}
@@ -167,26 +163,23 @@ public class DoubleTape<T> implements Tape<T>, DoubleSided {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof DoubleTape<?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof DoubleTape<?>)) return false;
final DoubleTape<?> other = (DoubleTape<?>) obj;
if (back == null) {
- if (other.back != null)
- return false;
- } else if (!back.equals(other.back))
+ if (other.back != null) return false;
+ } else if (!back.equals(other.back)) {
return false;
+ }
if (front == null) {
- if (other.front != null)
- return false;
- } else if (!front.equals(other.front))
+ if (other.front != null) return false;
+ } else if (!front.equals(other.front)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/esodata/MapSet.java b/src/main/java/bjc/esodata/MapSet.java
index a80c482..7d77ad6 100644
--- a/src/main/java/bjc/esodata/MapSet.java
+++ b/src/main/java/bjc/esodata/MapSet.java
@@ -116,8 +116,7 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
* @return False if there is no map attached to the key, true otherwise.
*/
public boolean setMap(String key) {
- if (!backing.containsKey(key))
- return false;
+ if (!backing.containsKey(key)) return false;
currentMap = backing.get(key);
@@ -165,16 +164,14 @@ public class MapSet<KeyType, ValueType> extends AbstractMap<KeyType, ValueType>
@Override
public Set<Map.Entry<KeyType, ValueType>> entrySet() {
- if (currentMap == null)
- throw new NullPointerException("Current map is not set");
+ if (currentMap == null) throw new NullPointerException("Current map is not set");
return currentMap.entrySet();
}
@Override
public ValueType put(KeyType key, ValueType value) {
- if (currentMap == null)
- throw new NullPointerException("Current map is not set");
+ if (currentMap == null) throw new NullPointerException("Current map is not set");
return currentMap.put(key, value);
}
diff --git a/src/main/java/bjc/esodata/Multimap.java b/src/main/java/bjc/esodata/Multimap.java
index a79f1b0..fae872e 100644
--- a/src/main/java/bjc/esodata/Multimap.java
+++ b/src/main/java/bjc/esodata/Multimap.java
@@ -51,9 +51,8 @@ public class Multimap<KeyType, ValueType> {
*/
public void remove(KeyType key, ValueType value) {
// We have no values for that key; bail.
- if (!backing.containsKey(key))
- return;
-
+ if (!backing.containsKey(key)) return;
+
backing.get(key).remove(value);
}
@@ -76,10 +75,8 @@ public class Multimap<KeyType, ValueType> {
* @return A set containing all of the values that have been mapped to that key.
*/
public Set<ValueType> get(KeyType key) {
- if (!backing.containsKey(key))
- return new HashSet<>();
-
- return backing.get(key).values();
+ if (!backing.containsKey(key)) return new HashSet<>();
+ else return backing.get(key).values();
}
/**
@@ -107,8 +104,7 @@ public class Multimap<KeyType, ValueType> {
* mapping.
*/
public boolean contains(KeyType key, ValueType value) {
- if (!backing.containsKey(key))
- return false;
+ if (!backing.containsKey(key)) return false;
return backing.get(key).contains(value) > 0;
}
diff --git a/src/main/java/bjc/esodata/PushdownMap.java b/src/main/java/bjc/esodata/PushdownMap.java
index 54ae939..a10c149 100644
--- a/src/main/java/bjc/esodata/PushdownMap.java
+++ b/src/main/java/bjc/esodata/PushdownMap.java
@@ -113,9 +113,7 @@ public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType>
public ValueType remove(final KeyType key) {
final Stack<ValueType> stk = backing.get(key);
- if (stk.size() > 1) {
- return stk.pop();
- }
+ if (stk.size() > 1) return stk.pop();
return backing.remove(key).top();
}
@@ -137,20 +135,17 @@ public class PushdownMap<KeyType, ValueType> implements IMap<KeyType, ValueType>
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof PushdownMap<?, ?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof PushdownMap<?, ?>)) return false;
final PushdownMap<?, ?> other = (PushdownMap<?, ?>) obj;
if (backing == null) {
- if (other.backing != null)
- return false;
- } else if (!backing.equals(other.backing))
+ if (other.backing != null) return false;
+ } else if (!backing.equals(other.backing)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/esodata/QueueStack.java b/src/main/java/bjc/esodata/QueueStack.java
index c40721a..e310f16 100644
--- a/src/main/java/bjc/esodata/QueueStack.java
+++ b/src/main/java/bjc/esodata/QueueStack.java
@@ -29,16 +29,14 @@ public class QueueStack<T> extends Stack<T> {
@Override
public T pop() {
- if (backing.isEmpty())
- throw new StackUnderflow();
+ if (backing.isEmpty()) throw new StackUnderflow();
return backing.remove();
}
@Override
public T top() {
- if (backing.isEmpty())
- throw new StackUnderflow();
+ if (backing.isEmpty()) throw new StackUnderflow();
return backing.peek();
}
@@ -76,20 +74,17 @@ public class QueueStack<T> extends Stack<T> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof QueueStack<?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof QueueStack<?>)) return false;
final QueueStack<?> other = (QueueStack<?>) obj;
if (backing == null) {
- if (other.backing != null)
- return false;
- } else if (!backing.equals(other.backing))
+ if (other.backing != null) return false;
+ } else if (!backing.equals(other.backing)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/esodata/SimpleDirectory.java b/src/main/java/bjc/esodata/SimpleDirectory.java
index 672d92f..36f5f5a 100644
--- a/src/main/java/bjc/esodata/SimpleDirectory.java
+++ b/src/main/java/bjc/esodata/SimpleDirectory.java
@@ -71,26 +71,23 @@ public class SimpleDirectory<K, V> implements Directory<K, V> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof SimpleDirectory<?, ?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof SimpleDirectory<?, ?>)) return false;
final SimpleDirectory<?, ?> other = (SimpleDirectory<?, ?>) obj;
if (children == null) {
- if (other.children != null)
- return false;
- } else if (!children.equals(other.children))
+ if (other.children != null) return false;
+ } else if (!children.equals(other.children)) {
return false;
+ }
if (data == null) {
- if (other.data != null)
- return false;
- } else if (!data.equals(other.data))
+ if (other.data != null) return false;
+ } else if (!data.equals(other.data)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/esodata/SimpleStack.java b/src/main/java/bjc/esodata/SimpleStack.java
index b50521e..9c016c3 100644
--- a/src/main/java/bjc/esodata/SimpleStack.java
+++ b/src/main/java/bjc/esodata/SimpleStack.java
@@ -27,16 +27,14 @@ public class SimpleStack<T> extends Stack<T> {
@Override
public T pop() {
- if (backing.isEmpty())
- throw new StackUnderflow();
+ if (backing.isEmpty()) throw new StackUnderflow();
return backing.pop();
}
@Override
public T top() {
- if (backing.isEmpty())
- throw new StackUnderflow();
+ if (backing.isEmpty()) throw new StackUnderflow();
return backing.peek();
}
@@ -69,20 +67,17 @@ public class SimpleStack<T> extends Stack<T> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof SimpleStack<?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof SimpleStack<?>)) return false;
final SimpleStack<?> other = (SimpleStack<?>) obj;
if (backing == null) {
- if (other.backing != null)
- return false;
- } else if (!backing.equals(other.backing))
+ if (other.backing != null) return false;
+ } else if (!backing.equals(other.backing)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/esodata/SingleTape.java b/src/main/java/bjc/esodata/SingleTape.java
index ec56e2b..7c3a34f 100644
--- a/src/main/java/bjc/esodata/SingleTape.java
+++ b/src/main/java/bjc/esodata/SingleTape.java
@@ -45,9 +45,7 @@ public class SingleTape<T> implements Tape<T> {
backing = new ArrayList<>(vals.length);
- for (T val : vals) {
- backing.add(val);
- }
+ for (T val : vals) backing.add(val);
}
/**
@@ -66,9 +64,7 @@ public class SingleTape<T> implements Tape<T> {
public SingleTape(Iterable<T> itr) {
this(false);
- for (T itm : itr) {
- backing.add(itm);
- }
+ for (T itm : itr) backing.add(itm);
}
/**
@@ -86,8 +82,7 @@ public class SingleTape<T> implements Tape<T> {
@Override
public T item() {
- if (pos < 0 || pos >= backing.size())
- return null;
+ if (pos < 0 || pos >= backing.size()) return null;
return backing.get(pos);
}
@@ -114,19 +109,16 @@ public class SingleTape<T> implements Tape<T> {
@Override
public void insertAfter(final T itm) {
- if (pos == backing.size() - 1) {
- backing.add(itm);
- } else {
- backing.add(pos + 1, itm);
- }
+ if (pos == backing.size() - 1) backing.add(itm);
+ else backing.add(pos + 1, itm);
}
@Override
public T remove() {
final T res = backing.remove(pos);
- if (pos != 0) {
- pos -= 1;
- }
+
+ if (pos != 0) pos -= 1;
+
return res;
}
@@ -147,8 +139,7 @@ public class SingleTape<T> implements Tape<T> {
@Override
public boolean left(final int amt) {
- if (pos - amt < 0)
- return false;
+ if (pos - amt < 0) return false;
pos -= amt;
return true;
@@ -163,11 +154,10 @@ public class SingleTape<T> implements Tape<T> {
public boolean right(final int amt) {
if (pos + amt > backing.size()) {
if (autoExtend) {
- while (pos + amt >= backing.size() - 1) {
- backing.add(null);
- }
- } else
+ while (pos + amt >= backing.size() - 1) backing.add(null);
+ } else {
return false;
+ }
}
pos += amt;
@@ -176,15 +166,15 @@ public class SingleTape<T> implements Tape<T> {
@Override
public boolean seekTo(int tgtPos) {
- if (tgtPos < 0)
- return false;
+ if (tgtPos < 0) return false;
- if (tgtPos >= backing.size() - 1)
- if (autoExtend)
- while (tgtPos >= backing.size() - 1)
- backing.add(null);
- else
+ if (tgtPos >= backing.size() - 1) {
+ if (autoExtend) {
+ while (tgtPos >= backing.size() - 1) backing.add(null);
+ } else {
return false;
+ }
+ }
pos = tgtPos;
@@ -208,20 +198,17 @@ public class SingleTape<T> implements Tape<T> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof SingleTape<?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof SingleTape<?>)) return false;
final SingleTape<?> other = (SingleTape<?>) obj;
if (backing == null) {
- if (other.backing != null)
- return false;
- } else if (!backing.equals(other.backing))
+ if (other.backing != null) return false;
+ } else if (!backing.equals(other.backing)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/esodata/SpaghettiStack.java b/src/main/java/bjc/esodata/SpaghettiStack.java
index fc3e154..4bd77d3 100644
--- a/src/main/java/bjc/esodata/SpaghettiStack.java
+++ b/src/main/java/bjc/esodata/SpaghettiStack.java
@@ -37,16 +37,14 @@ class SpaghettiStack<T> extends Stack<T> {
@Override
public T pop() {
- if (backing.isEmpty())
- return parent.pop();
+ if (backing.isEmpty()) return parent.pop();
return backing.pop();
}
@Override
public T top() {
- if (backing.isEmpty())
- return parent.top();
+ if (backing.isEmpty()) return parent.top();
return backing.top();
}
@@ -82,26 +80,23 @@ class SpaghettiStack<T> extends Stack<T> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof SpaghettiStack<?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof SpaghettiStack<?>)) return false;
final SpaghettiStack<?> other = (SpaghettiStack<?>) obj;
if (backing == null) {
- if (other.backing != null)
- return false;
- } else if (!backing.equals(other.backing))
+ if (other.backing != null) return false;
+ } else if (!backing.equals(other.backing)) {
return false;
+ }
if (parent == null) {
- if (other.parent != null)
- return false;
- } else if (!parent.equals(other.parent))
+ if (other.parent != null) return false;
+ } else if (!parent.equals(other.parent)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/esodata/Stack.java b/src/main/java/bjc/esodata/Stack.java
index 5ee5ef2..360e57d 100644
--- a/src/main/java/bjc/esodata/Stack.java
+++ b/src/main/java/bjc/esodata/Stack.java
@@ -96,9 +96,7 @@ public abstract class Stack<T> {
* The elements to insert.
*/
public void pushAll(@SuppressWarnings("unchecked") T... elms) {
- for (T elm : elms) {
- push(elm);
- }
+ for (T elm : elms) push(elm);
}
/**
@@ -108,9 +106,7 @@ public abstract class Stack<T> {
* The elements to insert.
*/
public void pushAll(List<T> elms) {
- for (T elm : elms) {
- push(elm);
- }
+ for (T elm : elms) push(elm);
}
/**
@@ -124,9 +120,7 @@ public abstract class Stack<T> {
public List<T> multipop(int n) {
List<T> lst = new LinkedList<>();
- for (int i = 0; i < n; i++) {
- lst.add(pop());
- }
+ for (int i = 0; i < n; i++) lst.add(pop());
return lst;
}
@@ -142,9 +136,7 @@ public abstract class Stack<T> {
public List<T> multipoprev(int n) {
LinkedList<T> lst = new LinkedList<>();
- for (int i = 0; i < n; i++) {
- lst.addFirst(pop());
- }
+ for (int i = 0; i < n; i++) lst.addFirst(pop());
return lst;
}
@@ -160,9 +152,7 @@ public abstract class Stack<T> {
* The number of items to drop.
*/
public void drop(final int n) {
- for (int i = 0; i < n; i++) {
- pop();
- }
+ for (int i = 0; i < n; i++) pop();
}
/** Drop one item from the stack. */
@@ -201,9 +191,7 @@ public abstract class Stack<T> {
public void multidup(final int n, final int m) {
List<T> lst = multipoprev(n);
- for (int i = 0; i <= m; i++) {
- pushAll(lst);
- }
+ for (int i = 0; i <= m; i++) pushAll(lst);
}
/**
@@ -235,15 +223,11 @@ public abstract class Stack<T> {
List<T> lst = multipoprev(n);
- for (final T nelm : lst) {
- push(nelm);
- }
+ for (final T nelm : lst) push(nelm);
push(elm);
- for (int i = 0; i < m; i++) {
- pushAll(lst);
- }
+ for (int i = 0; i < m; i++) pushAll(lst);
}
/**
@@ -555,9 +539,7 @@ public abstract class Stack<T> {
public void multiapply(final int n, final int m, final Consumer<Stack<T>> action) {
final List<Consumer<Stack<T>>> actions = new ArrayList<>(m);
- for (int i = 0; i < m; i++) {
- actions.add(action);
- }
+ for (int i = 0; i < m; i++) actions.add(action);
multispread(n, actions);
}
diff --git a/src/main/java/bjc/esodata/ThresholdSet.java b/src/main/java/bjc/esodata/ThresholdSet.java
index ae277e1..9b8560b 100644
--- a/src/main/java/bjc/esodata/ThresholdSet.java
+++ b/src/main/java/bjc/esodata/ThresholdSet.java
@@ -37,8 +37,7 @@ public class ThresholdSet<KeyType> {
int ret = ThresholdSet.this.add(key);
// No change to set contents
- if (ret > 2)
- return false;
+ if (ret > 2) return false;
return true;
}
@@ -52,8 +51,7 @@ public class ThresholdSet<KeyType> {
int ret = ThresholdSet.this.remove(k);
// We removed the element.
- if (ret == 0)
- return true;
+ if (ret == 0) return true;
return false;
}
@@ -67,8 +65,7 @@ public class ThresholdSet<KeyType> {
int ret = ThresholdSet.this.contains(k);
// The object is set-visible
- if (ret == 1)
- return true;
+ if (ret == 1) return true;
return false;
}
@@ -112,9 +109,7 @@ public class ThresholdSet<KeyType> {
public int[] addKeys(@SuppressWarnings("unchecked") KeyType... keys) {
int[] ret = new int[keys.length];
- for (int i = 0; i < keys.length; i++) {
- ret[i] = add(keys[i]);
- }
+ for (int i = 0; i < keys.length; i++) ret[i] = add(keys[i]);
return ret;
}
@@ -162,9 +157,7 @@ public class ThresholdSet<KeyType> {
public int[] removeKeys(@SuppressWarnings("unchecked") KeyType... keys) {
int[] ret = new int[keys.length];
- for (int i = 0; i < keys.length; i++) {
- ret[i] = remove(keys[i]);
- }
+ for (int i = 0; i < keys.length; i++) ret[i] = remove(keys[i]);
return ret;
}
@@ -217,9 +210,7 @@ public class ThresholdSet<KeyType> {
public int[] containsKeys(@SuppressWarnings("unchecked") KeyType... keys) {
int[] ret = new int[keys.length];
- for (int i = 0; i < keys.length; i++) {
- ret[i] = contains(keys[i]);
- }
+ for (int i = 0; i < keys.length; i++) ret[i] = contains(keys[i]);
return ret;
}
@@ -233,12 +224,9 @@ public class ThresholdSet<KeyType> {
* @return The number of times the key occurs; -1 if it doesn't occur.
*/
public int contains(KeyType key) {
- if (keySet.contains(key))
- return 1;
- if (!keyMap.containsKey(key))
- return -1;
-
- return keyMap.get(key);
+ if (keySet.contains(key)) return 1;
+ if (!keyMap.containsKey(key)) return -1;
+ else return keyMap.get(key);
}
/**
diff --git a/src/main/java/bjc/esodata/UnifiedDirectory.java b/src/main/java/bjc/esodata/UnifiedDirectory.java
index 2221615..dcbac89 100644
--- a/src/main/java/bjc/esodata/UnifiedDirectory.java
+++ b/src/main/java/bjc/esodata/UnifiedDirectory.java
@@ -82,26 +82,23 @@ public class UnifiedDirectory<K, V> implements Directory<K, V> {
@Override
public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof UnifiedDirectory<?, ?>))
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof UnifiedDirectory<?, ?>)) return false;
final UnifiedDirectory<?, ?> other = (UnifiedDirectory<?, ?>) obj;
if (children == null) {
- if (other.children != null)
- return false;
- } else if (!children.equals(other.children))
+ if (other.children != null) return false;
+ } else if (!children.equals(other.children)) {
return false;
+ }
if (data == null) {
- if (other.data != null)
- return false;
- } else if (!data.equals(other.data))
+ if (other.data != null) return false;
+ } else if (!data.equals(other.data)) {
return false;
+ }
return true;
}
diff --git a/src/main/java/bjc/funcdata/bst/BinarySearchTree.java b/src/main/java/bjc/funcdata/bst/BinarySearchTree.java
index e22a8da..2c5b4d8 100644
--- a/src/main/java/bjc/funcdata/bst/BinarySearchTree.java
+++ b/src/main/java/bjc/funcdata/bst/BinarySearchTree.java
@@ -33,8 +33,7 @@ public class BinarySearchTree<T> {
* The thing to use for comparing elements
*/
public BinarySearchTree(final Comparator<T> cmp) {
- if (cmp == null)
- throw new NullPointerException("Comparator must not be null");
+ if (cmp == null) throw new NullPointerException("Comparator must not be null");
elementCount = 0;
comparator = cmp;
@@ -49,11 +48,8 @@ public class BinarySearchTree<T> {
public void addNode(final T element) {
elementCount++;
- if (root == null) {
- root = new BinarySearchTreeNode<>(element, null, null);
- } else {
- root.add(element, comparator);
- }
+ if (root == null) root = new BinarySearchTreeNode<>(element, null, null);
+ else root.add(element, comparator);
}
/**
@@ -184,6 +180,7 @@ public class BinarySearchTree<T> {
*/
traverse(TreeLinearizationMethod.PREORDER, node -> {
nodes.add(node);
+
return true;
});