summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcdata
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java131
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java31
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java56
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java77
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java40
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/SentryList.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java44
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java20
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java106
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/ITreePart.java18
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/TreeLinearizationMethod.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/package-info.java2
17 files changed, 238 insertions, 339 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java
index 7e6c23b..7db6cea 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java
@@ -1,11 +1,11 @@
package bjc.utils.funcdata;
+import bjc.utils.funcutils.ListUtils;
+
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
-import bjc.utils.funcutils.ListUtils;
-
class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> {
private IMap<KeyType, ValueType> delegate;
@@ -23,9 +23,7 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> {
@Override
public boolean containsKey(KeyType key) {
- if (store.containsKey(key)) {
- return true;
- }
+ if(store.containsKey(key)) return true;
return delegate.containsKey(key);
}
@@ -58,9 +56,7 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> {
@Override
public ValueType get(KeyType key) {
- if (store.containsKey(key)) {
- return store.get(key);
- }
+ if(store.containsKey(key)) return store.get(key);
return delegate.get(key);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java
index f98f32c..1e52d05 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java
@@ -1,5 +1,10 @@
package bjc.utils.funcdata;
+import bjc.utils.data.IHolder;
+import bjc.utils.data.IPair;
+import bjc.utils.data.Identity;
+import bjc.utils.data.Pair;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -12,18 +17,13 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-import bjc.utils.data.Identity;
-import bjc.utils.data.Pair;
-
/**
* A wrapper over another list that provides eager functional operations over
* it.
*
* Differs from a stream in every way except for the fact that they both provide
* functional operations.
- *
+ *
* @author ben
*
* @param <E>
@@ -44,9 +44,9 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
/**
* Create a new functional list containing the specified items.
- *
+ *
* Takes O(n) time, where n is the number of items specified
- *
+ *
* @param items
* The items to put into this functional list.
*/
@@ -54,14 +54,14 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
public FunctionalList(E... items) {
wrapped = new ArrayList<>(items.length);
- for (E item : items) {
+ for(E item : items) {
wrapped.add(item);
}
}
/**
* Create a new functional list with the specified size.
- *
+ *
* @param size
* The size of the backing list .
*/
@@ -71,16 +71,14 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
/**
* Create a new functional list as a wrapper of a existing list.
- *
+ *
* Takes O(1) time, since it doesn't copy the list.
- *
+ *
* @param backing
* The list to use as a backing list.
*/
public FunctionalList(List<E> backing) {
- if (backing == null) {
- throw new NullPointerException("Backing list must be non-null");
- }
+ if(backing == null) throw new NullPointerException("Backing list must be non-null");
wrapped = backing;
}
@@ -92,15 +90,12 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public boolean allMatch(Predicate<E> predicate) {
- if (predicate == null) {
- throw new NullPointerException("Predicate must be non-null");
- }
+ if(predicate == null) throw new NullPointerException("Predicate must be non-null");
- for (E item : wrapped) {
- if (!predicate.test(item)) {
- // We've found a non-matching item
+ for(E item : wrapped) {
+ if(!predicate.test(item)) // We've found a non-matching
+ // item
return false;
- }
}
// All of the items matched
@@ -109,15 +104,11 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public boolean anyMatch(Predicate<E> predicate) {
- if (predicate == null) {
- throw new NullPointerException("Predicate must be not null");
- }
+ if(predicate == null) throw new NullPointerException("Predicate must be not null");
- for (E item : wrapped) {
- if (predicate.test(item)) {
- // We've found a matching item
+ for(E item : wrapped) {
+ if(predicate.test(item)) // We've found a matching item
return true;
- }
}
// We didn't find a matching item
@@ -126,16 +117,16 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
/**
* Clone this list into a new one, and clone the backing list as well
- *
+ *
* Takes O(n) time, where n is the number of elements in the list
- *
+ *
* @return A list
*/
@Override
public IList<E> clone() {
IList<E> cloned = new FunctionalList<>();
- for (E element : wrapped) {
+ for(E element : wrapped) {
cloned.add(element);
}
@@ -144,19 +135,16 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public <T, F> IList<F> combineWith(IList<T> rightList, BiFunction<E, T, F> itemCombiner) {
- if (rightList == null) {
+ if(rightList == null)
throw new NullPointerException("Target combine list must not be null");
- } else if (itemCombiner == null) {
- throw new NullPointerException("Combiner must not be null");
- }
+ else if(itemCombiner == null) throw new NullPointerException("Combiner must not be null");
IList<F> returned = new FunctionalList<>();
// Get the iterator for the other list
Iterator<T> rightIterator = rightList.toIterable().iterator();
- for (Iterator<E> leftIterator = wrapped.iterator(); leftIterator.hasNext()
- && rightIterator.hasNext();) {
+ for(Iterator<E> leftIterator = wrapped.iterator(); leftIterator.hasNext() && rightIterator.hasNext();) {
// Add the transformed items to the result list
E leftVal = leftIterator.next();
T rightVal = rightIterator.next();
@@ -175,27 +163,21 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public E first() {
- if (wrapped.size() < 1) {
- throw new NoSuchElementException("Attempted to get first element of empty list");
- }
+ if(wrapped.size() < 1) throw new NoSuchElementException("Attempted to get first element of empty list");
return wrapped.get(0);
}
@Override
public <T> IList<T> flatMap(Function<E, IList<T>> expander) {
- if (expander == null) {
- throw new NullPointerException("Expander must not be null");
- }
+ if(expander == null) throw new NullPointerException("Expander must not be null");
IList<T> returned = new FunctionalList<>(this.wrapped.size());
forEach(element -> {
IList<T> expandedElement = expander.apply(element);
- if (expandedElement == null) {
- throw new NullPointerException("Expander returned null list");
- }
+ if(expandedElement == null) throw new NullPointerException("Expander returned null list");
// Add each element to the returned list
expandedElement.forEach(returned::add);
@@ -204,19 +186,16 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
return returned;
}
+ @Override
public void forEach(Consumer<? super E> action) {
- if (action == null) {
- throw new NullPointerException("Action is null");
- }
+ if(action == null) throw new NullPointerException("Action is null");
wrapped.forEach(action);
}
@Override
public void forEachIndexed(BiConsumer<Integer, E> indexedAction) {
- if (indexedAction == null) {
- throw new NullPointerException("Action must not be null");
- }
+ if(indexedAction == null) throw new NullPointerException("Action must not be null");
// This is held b/c ref'd variables must be final/effectively
// final
@@ -238,7 +217,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
/**
* Get the internal backing list.
- *
+ *
* @return The backing list this list is based off of.
*/
public List<E> getInternal() {
@@ -247,14 +226,12 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public IList<E> getMatching(Predicate<E> predicate) {
- if (predicate == null) {
- throw new NullPointerException("Predicate must not be null");
- }
+ if(predicate == null) throw new NullPointerException("Predicate must not be null");
IList<E> returned = new FunctionalList<>();
wrapped.forEach((element) -> {
- if (predicate.test(element)) {
+ if(predicate.test(element)) {
// The item matches, so add it to the returned
// list
returned.add(element);
@@ -283,9 +260,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public <T> IList<T> map(Function<E, T> elementTransformer) {
- if (elementTransformer == null) {
- throw new NullPointerException("Transformer must be not null");
- }
+ if(elementTransformer == null) throw new NullPointerException("Transformer must be not null");
IList<T> returned = new FunctionalList<>(this.wrapped.size());
@@ -304,10 +279,9 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public IList<IList<E>> partition(int numberPerPartition) {
- if (numberPerPartition < 1 || numberPerPartition > wrapped.size()) {
+ if(numberPerPartition < 1 || numberPerPartition > wrapped.size())
throw new IllegalArgumentException("" + numberPerPartition
+ " is an invalid partition size. Must be between 1 and " + wrapped.size());
- }
IList<IList<E>> returned = new FunctionalList<>();
@@ -315,7 +289,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
IHolder<IList<E>> currentPartition = new Identity<>(new FunctionalList<>());
this.forEach((element) -> {
- if (isPartitionFull(numberPerPartition, currentPartition)) {
+ if(isPartitionFull(numberPerPartition, currentPartition)) {
// Add the partition to the list
returned.add(currentPartition.unwrap((partition) -> partition));
@@ -337,9 +311,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public E randItem(Function<Integer, Integer> rnd) {
- if (rnd == null) {
- throw new NullPointerException("Random source must not be null");
- }
+ if(rnd == null) throw new NullPointerException("Random source must not be null");
int randomIndex = rnd.apply(wrapped.size());
@@ -349,11 +321,9 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public <T, F> F reduceAux(T initialValue, BiFunction<E, T, T> stateAccumulator,
Function<T, F> resultTransformer) {
- if (stateAccumulator == null) {
+ if(stateAccumulator == null)
throw new NullPointerException("Accumulator must not be null");
- } else if (resultTransformer == null) {
- throw new NullPointerException("Transformer must not be null");
- }
+ else if(resultTransformer == null) throw new NullPointerException("Transformer must not be null");
// The current collapsed list
IHolder<T> currentState = new Identity<>(initialValue);
@@ -369,9 +339,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
@Override
public boolean removeIf(Predicate<E> removePredicate) {
- if (removePredicate == null) {
- throw new NullPointerException("Predicate must be non-null");
- }
+ if(removePredicate == null) throw new NullPointerException("Predicate must be non-null");
return wrapped.removeIf(removePredicate);
}
@@ -391,10 +359,8 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
// Search our internal list
int foundIndex = Collections.binarySearch(wrapped, searchKey, comparator);
- if (foundIndex >= 0) {
- // We found a matching element
+ if(foundIndex >= 0) // We found a matching element
return wrapped.get(foundIndex);
- }
// We didn't find an element
return null;
@@ -425,22 +391,19 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
public String toString() {
int lSize = getSize();
- if (lSize == 0)
- return "()";
+ if(lSize == 0) return "()";
StringBuilder sb = new StringBuilder("(");
Iterator<E> itr = toIterable().iterator();
E itm = itr.next();
int i = 0;
- if (lSize == 1) {
- return "(" + itm + ")";
- }
+ if(lSize == 1) return "(" + itm + ")";
- for (E item : toIterable()) {
+ for(E item : toIterable()) {
sb.append(item.toString());
- if (i < lSize - 1) {
+ if(i < lSize - 1) {
sb.append(", ");
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java
index 3d3fed1..10a727c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java
@@ -1,16 +1,16 @@
package bjc.utils.funcdata;
+import bjc.utils.data.IPair;
+
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
-import bjc.utils.data.IPair;
-
/**
* Basic implementation of {@link IMap}
- *
+ *
* @author ben
*
* @param <KeyType>
@@ -30,7 +30,7 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp
/**
* Create a new functional map with the specified entries
- *
+ *
* @param entries
* The entries to put into the map
*/
@@ -38,7 +38,7 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp
public FunctionalMap(IPair<KeyType, ValueType>... entries) {
this();
- for (IPair<KeyType, ValueType> entry : entries) {
+ for(IPair<KeyType, ValueType> entry : entries) {
entry.doWith((key, val) -> {
wrappedMap.put(key, val);
});
@@ -47,14 +47,12 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp
/**
* Create a new functional map wrapping the specified map
- *
+ *
* @param wrap
* The map to wrap
*/
public FunctionalMap(Map<KeyType, ValueType> wrap) {
- if (wrap == null) {
- throw new NullPointerException("Map to wrap must not be null");
- }
+ if(wrap == null) throw new NullPointerException("Map to wrap must not be null");
wrappedMap = wrap;
}
@@ -91,13 +89,10 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp
@Override
public ValueType get(KeyType key) {
- if (key == null) {
- throw new NullPointerException("Key must not be null");
- }
+ if(key == null) throw new NullPointerException("Key must not be null");
- if (!wrappedMap.containsKey(key)) {
+ if(!wrappedMap.containsKey(key))
throw new IllegalArgumentException("Key " + key + " is not present in the map");
- }
return wrappedMap.get(key);
}
@@ -120,18 +115,14 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp
@Override
public <MappedValue> IMap<KeyType, MappedValue> mapValues(Function<ValueType, MappedValue> transformer) {
- if (transformer == null) {
- throw new NullPointerException("Transformer must not be null");
- }
+ if(transformer == null) throw new NullPointerException("Transformer must not be null");
return new TransformedValueMap<>(this, transformer);
}
@Override
public ValueType put(KeyType key, ValueType val) {
- if (key == null) {
- throw new NullPointerException("Key must not be null");
- }
+ if(key == null) throw new NullPointerException("Key must not be null");
return wrappedMap.put(key, val);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
index 93f2dca..b7e3f30 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
@@ -6,22 +6,20 @@ import java.util.function.Function;
/**
* A string tokenizer that exposes a functional interface
- *
+ *
* @author ben
*
*/
public class FunctionalStringTokenizer {
/**
* Create a new tokenizer from the specified string.
- *
+ *
* @param strang
* The string to create a tokenizer from.
* @return A new tokenizer that splits the provided string on spaces.
*/
public static FunctionalStringTokenizer fromString(String strang) {
- if (strang == null) {
- throw new NullPointerException("String to tokenize must be non-null");
- }
+ if(strang == null) throw new NullPointerException("String to tokenize must be non-null");
return new FunctionalStringTokenizer(new StringTokenizer(strang, " "));
}
@@ -33,14 +31,12 @@ public class FunctionalStringTokenizer {
/**
* Create a functional string tokenizer from a given string
- *
+ *
* @param inp
* The string to tokenize
*/
public FunctionalStringTokenizer(String inp) {
- if (inp == null) {
- throw new NullPointerException("String to tokenize must be non-null");
- }
+ if(inp == null) throw new NullPointerException("String to tokenize must be non-null");
this.input = new StringTokenizer(inp);
}
@@ -48,55 +44,49 @@ public class FunctionalStringTokenizer {
/**
* Create a functional string tokenizer from a given string and set of
* separators
- *
+ *
* @param input
* The string to tokenize
* @param seperators
* The set of separating tokens to use for splitting
*/
public FunctionalStringTokenizer(String input, String seperators) {
- if (input == null) {
+ if(input == null)
throw new NullPointerException("String to tokenize must not be null");
- } else if (seperators == null) {
- throw new NullPointerException("Tokens to split on must not be null");
- }
+ else if(seperators == null) throw new NullPointerException("Tokens to split on must not be null");
this.input = new StringTokenizer(input, seperators);
}
/**
* Create a functional string tokenizer from a non-functional one
- *
+ *
* @param toWrap
* The non-functional string tokenizer to wrap
*/
public FunctionalStringTokenizer(StringTokenizer toWrap) {
- if (toWrap == null) {
- throw new NullPointerException("Wrapped tokenizer must not be null");
- }
+ if(toWrap == null) throw new NullPointerException("Wrapped tokenizer must not be null");
this.input = toWrap;
}
/**
* Execute a provided action for each of the remaining tokens
- *
+ *
* @param action
* The action to execute for each token
*/
public void forEachToken(Consumer<String> action) {
- if (action == null) {
- throw new NullPointerException("Action must not be null");
- }
+ if(action == null) throw new NullPointerException("Action must not be null");
- while (input.hasMoreTokens()) {
+ while(input.hasMoreTokens()) {
action.accept(input.nextToken());
}
}
/**
* Get the string tokenizer encapsulated by this tokenizer
- *
+ *
* @return The encapsulated tokenizer
*/
public StringTokenizer getInternal() {
@@ -105,7 +95,7 @@ public class FunctionalStringTokenizer {
/**
* Check if this tokenizer has more tokens
- *
+ *
* @return Whether or not this tokenizer has more tokens
*/
public boolean hasMoreTokens() {
@@ -116,14 +106,12 @@ public class FunctionalStringTokenizer {
* Return the next token from the tokenizer.
*
* Returns null if no more tokens are available
- *
+ *
* @return The next token from the tokenizer
*/
public String nextToken() {
- if (input.hasMoreTokens()) {
- // Return the next available token
+ if(input.hasMoreTokens()) // Return the next available token
return input.nextToken();
- }
// Return no token
return null;
@@ -131,7 +119,7 @@ public class FunctionalStringTokenizer {
/**
* Convert this tokenizer into a list of strings
- *
+ *
* @return This tokenizer, converted into a list of strings
*/
public IList<String> toList() {
@@ -141,18 +129,16 @@ public class FunctionalStringTokenizer {
/**
* Convert the contents of this tokenizer into a list. Consumes all of
* the input from this tokenizer.
- *
+ *
* @param <E>
* The type of the converted tokens
- *
+ *
* @param transformer
* The function to use to convert tokens.
* @return A list containing all of the converted tokens.
*/
public <E> IList<E> toList(Function<String, E> transformer) {
- if (transformer == null) {
- throw new NullPointerException("Transformer must not be null");
- }
+ if(transformer == null) throw new NullPointerException("Transformer must not be null");
IList<E> returned = new FunctionalList<>();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
index 0feaf06..95f4813 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
@@ -1,5 +1,7 @@
package bjc.utils.funcdata;
+import bjc.utils.data.IPair;
+
import java.util.Comparator;
import java.util.Iterator;
import java.util.function.BiConsumer;
@@ -9,11 +11,9 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collector;
-import bjc.utils.data.IPair;
-
/**
* A wrapper over another list that provides functional operations over it.
- *
+ *
* @author ben
*
* @param <ContainedType>
@@ -22,7 +22,7 @@ import bjc.utils.data.IPair;
public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Add an item to this list
- *
+ *
* @param item
* The item to add to this list.
* @return Whether the item was added to the list successfully.
@@ -31,7 +31,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Add all of the elements in the provided list to this list
- *
+ *
* @param items
* The list of items to add
* @return True if every item was successfully added to the list, false
@@ -44,7 +44,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Check if all of the elements of this list match the specified
* predicate.
- *
+ *
* @param matcher
* The predicate to use for checking.
* @return Whether all of the elements of the list match the specified
@@ -54,7 +54,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Check if any of the elements in this list match the specified list.
- *
+ *
* @param matcher
* The predicate to use for checking.
* @return Whether any element in the list matches the provided
@@ -64,7 +64,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Reduce the contents of this list using a collector
- *
+ *
* @param <StateType>
* The intermediate accumulation type
* @param <ReducedType>
@@ -90,15 +90,15 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
*
* Works sort of like a combined zip/map over resulting pairs. Does not
* change the underlying list.
- *
+ *
* NOTE: The returned list will have the length of the shorter of this
* list and the combined one.
- *
+ *
* @param <OtherType>
* The type of the second list
* @param <CombinedType>
* The type of the combined list
- *
+ *
* @param list
* The list to combine with
* @param combiner
@@ -110,7 +110,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Check if the list contains the specified item
- *
+ *
* @param item
* The item to see if it is contained
* @return Whether or not the specified item is in the list
@@ -119,7 +119,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Get the first element in the list
- *
+ *
* @return The first element in this list.
*/
ContainedType first();
@@ -129,10 +129,10 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
* results.
*
* Does not change the underlying list.
- *
+ *
* @param <MappedType>
* The type of the flattened list
- *
+ *
* @param expander
* The function to apply to each member of the list.
* @return A new list containing the flattened results of applying the
@@ -142,15 +142,16 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Apply a given action for each member of the list
- *
+ *
* @param action
* The action to apply to each member of the list.
*/
+ @Override
void forEach(Consumer<? super ContainedType> action);
/**
* Apply a given function to each element in the list and its index.
- *
+ *
* @param action
* The function to apply to each element in the list and
* its index.
@@ -159,7 +160,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Retrieve a value in the list by its index.
- *
+ *
* @param index
* The index to retrieve a value from.
* @return The value at the specified index in the list.
@@ -168,7 +169,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Retrieve a list containing all elements matching a predicate
- *
+ *
* @param predicate
* The predicate to match by
* @return A list containing all elements that match the predicate
@@ -177,14 +178,14 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Retrieve the size of the wrapped list
- *
+ *
* @return The size of the wrapped list
*/
int getSize();
/**
* Check if this list is empty.
- *
+ *
* @return Whether or not this list is empty.
*/
boolean isEmpty();
@@ -194,10 +195,10 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
* the list.
*
* Does not change the underlying list.
- *
+ *
* @param <MappedType>
* The type of the transformed list
- *
+ *
* @param transformer
* The function to apply to each element in the list
* @return A new list containing the mapped elements of this list.
@@ -206,10 +207,10 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Zip two lists into a list of pairs
- *
+ *
* @param <OtherType>
* The type of the second list
- *
+ *
* @param list
* The list to use as the left side of the pair
* @return A list containing pairs of this element and the specified
@@ -219,7 +220,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Partition this list into a list of sublists
- *
+ *
* @param partitionSize
* The size of elements to put into each one of the
* sublists
@@ -229,7 +230,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Prepend an item to the list
- *
+ *
* @param item
* The item to prepend to the list
*/
@@ -238,7 +239,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Select a random item from the list, using a default random number
* generator
- *
+ *
* @return A random item from the list
*/
default ContainedType randItem() {
@@ -248,7 +249,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Select a random item from this list, using the provided random number
* generator.
- *
+ *
* @param rnd
* The random number generator to use.
* @return A random element from this list.
@@ -257,12 +258,12 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Reduce this list to a single value, using a accumulative approach.
- *
+ *
* @param <StateType>
* The in-between type of the values
* @param <ReducedType>
* The final value type
- *
+ *
* @param initial
* The initial value of the accumulative state.
* @param accumulator
@@ -280,7 +281,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Remove all elements that match a given predicate
- *
+ *
* @param predicate
* The predicate to use to determine elements to delete
* @return Whether there was anything that satisfied the predicate
@@ -289,7 +290,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Remove all parameters that match a given parameter
- *
+ *
* @param element
* The object to remove all matching copies of
*/
@@ -306,7 +307,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
*
* Since this IS a binary search, the list must have been sorted before
* hand.
- *
+ *
* @param key
* The key to search for.
* @param comparator
@@ -321,7 +322,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
* elements.
*
* Does change the underlying list.
- *
+ *
* @param comparator
* The way to compare elements for sorting. Pass null to
* use E's natural ordering
@@ -330,14 +331,14 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Get the tail of this list (the list without the first element
- *
+ *
* @return The list without the first element
*/
IList<ContainedType> tail();
/**
* Convert this list into an array
- *
+ *
* @param type
* The type of array to return
* @return The list, as an array
@@ -346,7 +347,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
/**
* Convert the list into a Iterable
- *
+ *
* @return An iterable view onto the list
*/
Iterable<ContainedType> toIterable();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java
index ff8f973..d83b5c2 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java
@@ -6,9 +6,9 @@ import java.util.function.Function;
/**
* Functional wrapper over map providing some useful things
- *
+ *
* @author ben
- *
+ *
* @param <KeyType>
* The type of this map's keys
* @param <ValueType>
@@ -23,7 +23,7 @@ public interface IMap<KeyType, ValueType> {
/**
* Check if this map contains the specified key
- *
+ *
* @param key
* The key to check
* @return Whether or not the map contains the key
@@ -33,14 +33,14 @@ public interface IMap<KeyType, ValueType> {
/**
* Extends this map, creating a new map that will delegate queries to
* the map, but store any added values itself
- *
+ *
* @return An extended map
*/
IMap<KeyType, ValueType> extend();
/**
* Execute an action for each entry in the map
- *
+ *
* @param action
* the action to execute for each entry in the map
*/
@@ -48,7 +48,7 @@ public interface IMap<KeyType, ValueType> {
/**
* Perform an action for each key in the map
- *
+ *
* @param action
* The action to perform on each key in the map
*/
@@ -56,7 +56,7 @@ public interface IMap<KeyType, ValueType> {
/**
* Perform an action for each value in the map
- *
+ *
* @param action
* The action to perform on each value in the map
*/
@@ -64,19 +64,19 @@ public interface IMap<KeyType, ValueType> {
/**
* Get the value assigned to the given key
- *
+ *
* @param key
* The key to look for a value under
* @return The value of the key
- *
- *
+ *
+ *
*/
ValueType get(KeyType key);
/**
* Get a value from the map, and return a default value if the key
* doesn't exist
- *
+ *
* @param key
* The key to attempt to retrieve
* @param defaultValue
@@ -87,7 +87,7 @@ public interface IMap<KeyType, ValueType> {
default ValueType getOrDefault(KeyType key, ValueType defaultValue) {
try {
return get(key);
- } catch (IllegalArgumentException iaex) {
+ } catch(IllegalArgumentException iaex) {
// We don't care about this, because it indicates a key
// is
// missing
@@ -97,25 +97,25 @@ public interface IMap<KeyType, ValueType> {
/**
* Get the number of entries in this map
- *
+ *
* @return The number of entries in this map
*/
int getSize();
/**
* Get a list of all the keys in this map
- *
+ *
* @return A list of all the keys in this map
*/
IList<KeyType> keyList();
/**
* Transform the values returned by this map.
- *
+ *
* NOTE: This transform is applied once for each lookup of a value, so
* the transform passed should be a proper function, or things will
* likely not work as expected.
- *
+ *
* @param <V2>
* The new type of returned values
* @param transformer
@@ -126,7 +126,7 @@ public interface IMap<KeyType, ValueType> {
/**
* Add an entry to the map
- *
+ *
* @param key
* The key to put the value under
* @param val
@@ -134,7 +134,7 @@ public interface IMap<KeyType, ValueType> {
* @return The previous value of the key in the map, or null if the key
* wasn't in the map. However, note that it may also return null
* if the key was set to null.
- *
+ *
* @throws UnsupportedOperationException
* if the map implementation doesn't support modifying
* the map
@@ -143,7 +143,7 @@ public interface IMap<KeyType, ValueType> {
/**
* Remove the value bound to the key
- *
+ *
* @param key
* The key to remove from the map
* @return The previous value for the key in the map, or null if the key
@@ -155,7 +155,7 @@ public interface IMap<KeyType, ValueType> {
/**
* Get a list of the values in this map
- *
+ *
* @return A list of values in this map
*/
IList<ValueType> valueList();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/SentryList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/SentryList.java
index 32ec7cd..060f69e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/SentryList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/SentryList.java
@@ -11,11 +11,13 @@ public class SentryList<T> extends FunctionalList<T> {
super(backing);
}
+ @Override
public boolean add(T item) {
boolean val = super.add(item);
- if (val)
+ if(val) {
System.out.println("Added item (" + item + ") to list");
+ }
return val;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java
index 36bfaab..d4e1762 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java
@@ -6,7 +6,7 @@ import java.util.function.Function;
/**
* A map that transforms values from one type to another
- *
+ *
* @author ben
*
* @param <OldKey>
@@ -17,8 +17,8 @@ import java.util.function.Function;
* The type of the transformed values
*/
final class TransformedValueMap<OldKey, OldValue, NewValue> implements IMap<OldKey, NewValue> {
- private IMap<OldKey, OldValue> backing;
- private Function<OldValue, NewValue> transformer;
+ private IMap<OldKey, OldValue> backing;
+ private Function<OldValue, NewValue> transformer;
public TransformedValueMap(IMap<OldKey, OldValue> backingMap, Function<OldValue, NewValue> transform) {
backing = backingMap;
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java
index b3772a4..060b3f5 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java
@@ -1,16 +1,16 @@
package bjc.utils.funcdata.bst;
+import bjc.utils.funcdata.FunctionalList;
+import bjc.utils.funcdata.IList;
+
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
/**
* A binary search tree, with some mild support for functional traversal.
- *
+ *
* @author ben
*
* @param <T>
@@ -34,14 +34,12 @@ public class BinarySearchTree<T> {
/**
* Create a new tree using the specified way to compare elements.
- *
+ *
* @param cmp
* The thing to use for comparing elements
*/
public BinarySearchTree(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,14 +47,14 @@ public class BinarySearchTree<T> {
/**
* Add a node to the binary search tree.
- *
+ *
* @param element
* The data to add to the binary search tree.
*/
public void addNode(T element) {
elementCount++;
- if (root == null) {
+ if(root == null) {
root = new BinarySearchTreeNode<>(element, null, null);
} else {
root.add(element, comparator);
@@ -65,7 +63,7 @@ public class BinarySearchTree<T> {
/**
* Check if an adjusted pivot falls with the bounds of a list
- *
+ *
* @param elements
* The list to get bounds from
* @param pivot
@@ -75,7 +73,7 @@ public class BinarySearchTree<T> {
* @return Whether the adjusted pivot is with the list
*/
private boolean adjustedPivotInBounds(IList<T> elements, int pivot, int pivotAdjustment) {
- return (pivot - pivotAdjustment) >= 0 && (pivot + pivotAdjustment) < elements.getSize();
+ return pivot - pivotAdjustment >= 0 && pivot + pivotAdjustment < elements.getSize();
}
/**
@@ -97,8 +95,8 @@ public class BinarySearchTree<T> {
int pivotAdjustment = 0;
// Add elements until there aren't any left
- while (adjustedPivotInBounds(elements, pivot, pivotAdjustment)) {
- if (root == null) {
+ while(adjustedPivotInBounds(elements, pivot, pivotAdjustment)) {
+ if(root == null) {
// Create a new root element
root = new BinarySearchTreeNode<>(elements.getByIndex(pivot), null, null);
} else {
@@ -114,9 +112,9 @@ public class BinarySearchTree<T> {
}
// Add any trailing unbalanced elements
- if ((pivot - pivotAdjustment) >= 0) {
+ if(pivot - pivotAdjustment >= 0) {
root.add(elements.getByIndex(pivot - pivotAdjustment), comparator);
- } else if ((pivot + pivotAdjustment) < elements.getSize()) {
+ } else if(pivot + pivotAdjustment < elements.getSize()) {
root.add(elements.getByIndex(pivot + pivotAdjustment), comparator);
}
}
@@ -126,7 +124,7 @@ public class BinarySearchTree<T> {
*
* Soft-deleted nodes stay in the tree until trim()/balance() is
* invoked, and are not included in traversals/finds.
- *
+ *
* @param element
* The node to delete
*/
@@ -138,7 +136,7 @@ public class BinarySearchTree<T> {
/**
* Get the root of the tree.
- *
+ *
* @return The root of the tree.
*/
public ITreePart<T> getRoot() {
@@ -147,7 +145,7 @@ public class BinarySearchTree<T> {
/**
* Check if a node is in the tree
- *
+ *
* @param element
* The node to check the presence of for the tree.
* @return Whether or not the node is in the tree.
@@ -158,18 +156,16 @@ public class BinarySearchTree<T> {
/**
* Traverse the tree in a specified way until the function fails
- *
+ *
* @param linearizationMethod
* The way to linearize the tree for traversal
* @param traversalPredicate
* The function to use until it fails
*/
public void traverse(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) {
- if (linearizationMethod == null) {
+ if(linearizationMethod == null)
throw new NullPointerException("Linearization method must not be null");
- } else if (traversalPredicate == null) {
- throw new NullPointerException("Predicate must not be nulls");
- }
+ else if(traversalPredicate == null) throw new NullPointerException("Predicate must not be nulls");
root.forEach(linearizationMethod, traversalPredicate);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java
index 04765b4..2696577 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java
@@ -7,7 +7,7 @@ import java.util.function.Predicate;
/**
* A leaf in a tree.
- *
+ *
* @author ben
*
* @param <T>
@@ -26,7 +26,7 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
/**
* Create a new leaf holding the specified data.
- *
+ *
* @param element
* The data for the leaf to hold.
*/
@@ -41,9 +41,7 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
@Override
public <E> E collapse(Function<T, E> leafTransformer, BiFunction<E, E, E> branchCollapser) {
- if (leafTransformer == null) {
- throw new NullPointerException("Transformer must not be null");
- }
+ if(leafTransformer == null) throw new NullPointerException("Transformer must not be null");
return leafTransformer.apply(data);
}
@@ -60,18 +58,16 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
@Override
public void delete(T element, Comparator<T> comparator) {
- if (data.equals(element)) {
+ if(data.equals(element)) {
isDeleted = true;
}
}
@Override
public boolean directedWalk(DirectedWalkFunction<T> treeWalker) {
- if (treeWalker == null) {
- throw new NullPointerException("Tree walker must not be null");
- }
+ if(treeWalker == null) throw new NullPointerException("Tree walker must not be null");
- switch (treeWalker.walk(data)) {
+ switch(treeWalker.walk(data)) {
case SUCCESS:
return true;
// We don't have any children to care about
@@ -85,9 +81,7 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
@Override
public boolean forEach(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) {
- if (traversalPredicate == null) {
- throw new NullPointerException("Predicate must not be null");
- }
+ if(traversalPredicate == null) throw new NullPointerException("Predicate must not be null");
return traversalPredicate.test(data);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java
index 46a89f2..4fe9de3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java
@@ -1,18 +1,18 @@
package bjc.utils.funcdata.bst;
-import static bjc.utils.funcdata.bst.DirectedWalkFunction.DirectedWalkResult.FAILURE;
-import static bjc.utils.funcdata.bst.DirectedWalkFunction.DirectedWalkResult.LEFT;
-import static bjc.utils.funcdata.bst.DirectedWalkFunction.DirectedWalkResult.RIGHT;
-import static bjc.utils.funcdata.bst.DirectedWalkFunction.DirectedWalkResult.SUCCESS;
-
import java.util.Comparator;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
+import static bjc.utils.funcdata.bst.DirectedWalkFunction.DirectedWalkResult.FAILURE;
+import static bjc.utils.funcdata.bst.DirectedWalkFunction.DirectedWalkResult.LEFT;
+import static bjc.utils.funcdata.bst.DirectedWalkFunction.DirectedWalkResult.RIGHT;
+import static bjc.utils.funcdata.bst.DirectedWalkFunction.DirectedWalkResult.SUCCESS;
+
/**
* A binary node in a tree.
- *
+ *
* @author ben
*
* @param <T>
@@ -31,7 +31,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
/**
* Create a new node with the specified data and children.
- *
+ *
* @param element
* The data to store in this node.
* @param lft
@@ -47,27 +47,24 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public void add(T element, Comparator<T> comparator) {
- if (comparator == null) {
- throw new NullPointerException("Comparator must not be null");
- }
+ if(comparator == null) throw new NullPointerException("Comparator must not be null");
- switch (comparator.compare(data, element)) {
+ switch(comparator.compare(data, element)) {
case -1:
- if (left == null) {
+ if(left == null) {
left = new BinarySearchTreeNode<>(element, null, null);
} else {
left.add(element, comparator);
}
break;
case 0:
- if (isDeleted) {
+ if(isDeleted) {
isDeleted = false;
- } else {
+ } else
throw new IllegalArgumentException("Can't add duplicate values");
- }
break;
case 1:
- if (right == null) {
+ if(right == null) {
right = new BinarySearchTreeNode<>(element, null, null);
} else {
right.add(element, comparator);
@@ -80,16 +77,15 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public <E> E collapse(Function<T, E> nodeCollapser, BiFunction<E, E, E> branchCollapser) {
- if (nodeCollapser == null || branchCollapser == null) {
+ if(nodeCollapser == null || branchCollapser == null)
throw new NullPointerException("Collapser must not be null");
- }
E collapsedNode = nodeCollapser.apply(data);
- if (left != null) {
+ if(left != null) {
E collapsedLeftBranch = left.collapse(nodeCollapser, branchCollapser);
- if (right != null) {
+ if(right != null) {
E collapsedRightBranch = right.collapse(nodeCollapser, branchCollapser);
E collapsedBranches = branchCollapser.apply(collapsedLeftBranch, collapsedRightBranch);
@@ -100,7 +96,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
return branchCollapser.apply(collapsedNode, collapsedLeftBranch);
}
- if (right != null) {
+ if(right != null) {
E collapsedRightBranch = right.collapse(nodeCollapser, branchCollapser);
return branchCollapser.apply(collapsedNode, collapsedRightBranch);
@@ -111,12 +107,10 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public boolean contains(T element, Comparator<T> comparator) {
- if (comparator == null) {
- throw new NullPointerException("Comparator must not be null");
- }
+ if(comparator == null) throw new NullPointerException("Comparator must not be null");
return directedWalk(currentElement -> {
- switch (comparator.compare(element, currentElement)) {
+ switch(comparator.compare(element, currentElement)) {
case -1:
return LEFT;
case 0:
@@ -131,12 +125,10 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public void delete(T element, Comparator<T> comparator) {
- if (comparator == null) {
- throw new NullPointerException("Comparator must not be null");
- }
+ if(comparator == null) throw new NullPointerException("Comparator must not be null");
directedWalk(currentElement -> {
- switch (comparator.compare(data, element)) {
+ switch(comparator.compare(data, element)) {
case -1:
return left == null ? FAILURE : LEFT;
case 0:
@@ -152,11 +144,9 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public boolean directedWalk(DirectedWalkFunction<T> treeWalker) {
- if (treeWalker == null) {
- throw new NullPointerException("Walker must not be null");
- }
+ if(treeWalker == null) throw new NullPointerException("Walker must not be null");
- switch (treeWalker.walk(data)) {
+ switch(treeWalker.walk(data)) {
case SUCCESS:
return true;
case LEFT:
@@ -172,13 +162,11 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public boolean forEach(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) {
- if (linearizationMethod == null) {
+ if(linearizationMethod == null)
throw new NullPointerException("Linearization method must not be null");
- } else if (traversalPredicate == null) {
- throw new NullPointerException("Predicate must not be null");
- }
+ else if(traversalPredicate == null) throw new NullPointerException("Predicate must not be null");
- switch (linearizationMethod) {
+ switch(linearizationMethod) {
case PREORDER:
return preorderTraverse(linearizationMethod, traversalPredicate);
case INORDER:
@@ -192,51 +180,33 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
}
private boolean inorderTraverse(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) {
- if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) {
- return false;
- }
+ if(!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false;
- if (!traverseElement(traversalPredicate)) {
- return false;
- }
+ if(!traverseElement(traversalPredicate)) return false;
- if (!traverseRightBranch(linearizationMethod, traversalPredicate)) {
- return false;
- }
+ if(!traverseRightBranch(linearizationMethod, traversalPredicate)) return false;
return true;
}
private boolean postorderTraverse(TreeLinearizationMethod linearizationMethod,
Predicate<T> traversalPredicate) {
- if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) {
- return false;
- }
+ if(!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false;
- if (!traverseRightBranch(linearizationMethod, traversalPredicate)) {
- return false;
- }
+ if(!traverseRightBranch(linearizationMethod, traversalPredicate)) return false;
- if (!traverseElement(traversalPredicate)) {
- return false;
- }
+ if(!traverseElement(traversalPredicate)) return false;
return true;
}
private boolean preorderTraverse(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) {
- if (!traverseElement(traversalPredicate)) {
- return false;
- }
+ if(!traverseElement(traversalPredicate)) return false;
- if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) {
- return false;
- }
+ if(!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false;
- if (!traverseRightBranch(linearizationMethod, traversalPredicate)) {
- return false;
- }
+ if(!traverseRightBranch(linearizationMethod, traversalPredicate)) return false;
return true;
}
@@ -244,7 +214,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
private boolean traverseElement(Predicate<T> traversalPredicate) {
boolean nodeSuccesfullyTraversed;
- if (isDeleted) {
+ if(isDeleted) {
nodeSuccesfullyTraversed = true;
} else {
nodeSuccesfullyTraversed = traversalPredicate.test(data);
@@ -257,7 +227,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
Predicate<T> traversalPredicate) {
boolean leftSuccesfullyTraversed;
- if (left == null) {
+ if(left == null) {
leftSuccesfullyTraversed = true;
} else {
leftSuccesfullyTraversed = left.forEach(linearizationMethod, traversalPredicate);
@@ -270,7 +240,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
Predicate<T> traversalPredicate) {
boolean rightSuccesfullyTraversed;
- if (right == null) {
+ if(right == null) {
rightSuccesfullyTraversed = true;
} else {
rightSuccesfullyTraversed = right.forEach(linearizationMethod, traversalPredicate);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java
index e68bef6..e11524a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java
@@ -2,7 +2,7 @@ package bjc.utils.funcdata.bst;
/**
* Represents a function for doing a directed walk of a binary tree.
- *
+ *
* @author ben
*
* @param <T>
@@ -12,7 +12,7 @@ package bjc.utils.funcdata.bst;
public interface DirectedWalkFunction<T> {
/**
* Represents the results used to direct a walk in a binary tree.
- *
+ *
* @author ben
*
*/
@@ -33,14 +33,14 @@ public interface DirectedWalkFunction<T> {
RIGHT,
/**
* Specifies that the function has succesfully completed
- *
+ *
*/
SUCCESS
}
/**
* Perform a directed walk on a node of a tree.
- *
+ *
* @param element
* The data stored in the node currently being visited
* @return The way the function wants the walk to go next.
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/ITreePart.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/ITreePart.java
index c648001..3aa8880 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/ITreePart.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/ITreePart.java
@@ -7,7 +7,7 @@ import java.util.function.Predicate;
/**
* A interface for the fundamental things that want to be part of a tree.
- *
+ *
* @author ben
*
* @param <T>
@@ -16,7 +16,7 @@ import java.util.function.Predicate;
public interface ITreePart<T> {
/**
* Add a element below this tree part somewhere.
- *
+ *
* @param element
* The element to add below this tree part
* @param comparator
@@ -28,10 +28,10 @@ public interface ITreePart<T> {
/**
* Collapses this tree part into a single value. Does not change the
* underlying tree.
- *
+ *
* @param <E>
* The type of the final collapsed value
- *
+ *
* @param nodeCollapser
* The function to use to transform data into mapped
* form.
@@ -44,7 +44,7 @@ public interface ITreePart<T> {
/**
* Check if this tre part or below it contains the specified data item
- *
+ *
* @param element
* The data item to look for.
* @param comparator
@@ -56,14 +56,14 @@ public interface ITreePart<T> {
/**
* Get the data associated with this tree part.
- *
+ *
* @return The data associated with this tree part.
*/
public T data();
/**
* Remove the given node from this tree part and any of its children.
- *
+ *
* @param element
* The data item to remove.
* @param comparator
@@ -73,7 +73,7 @@ public interface ITreePart<T> {
/**
* Execute a directed walk through the tree.
- *
+ *
* @param walker
* The function to use to direct the walk through the
* tree.
@@ -84,7 +84,7 @@ public interface ITreePart<T> {
/**
* Execute a provided function for each element of tree it succesfully
* completes for
- *
+ *
* @param linearizationMethod
* The way to linearize the tree for executing
* @param predicate
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/TreeLinearizationMethod.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/TreeLinearizationMethod.java
index f7d6280..0c83867 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/TreeLinearizationMethod.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/TreeLinearizationMethod.java
@@ -2,7 +2,7 @@ package bjc.utils.funcdata.bst;
/**
* Represents the ways to linearize a tree for traversal.
- *
+ *
* @author ben
*
*/
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java
index fa69f31..d6da637 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java
@@ -4,7 +4,7 @@ import java.util.function.Function;
/**
* A functor over a pair of heterogenous types
- *
+ *
* @author ben
* @param <LeftType>
* The type stored on the 'left' of the pair
@@ -16,7 +16,7 @@ public interface Bifunctor<LeftType, RightType> {
/**
* Lift a pair of functions to a single function that maps over both
* parts of a pair
- *
+ *
* @param <OldLeft>
* The old left type of the pair
* @param <OldRight>
@@ -49,7 +49,7 @@ public interface Bifunctor<LeftType, RightType> {
/**
* Lift a function to operate over the left part of this pair
- *
+ *
* @param <OldLeft>
* The old left type of the pair
* @param <OldRight>
@@ -66,7 +66,7 @@ public interface Bifunctor<LeftType, RightType> {
/**
* Lift a function to operate over the right part of this pair
- *
+ *
* @param <OldLeft>
* The old left type of the pair
* @param <OldRight>
@@ -83,14 +83,14 @@ public interface Bifunctor<LeftType, RightType> {
/**
* Get the value contained on the left of this bifunctor
- *
+ *
* @return The value on the left side of this bifunctor
*/
public LeftType getLeft();
/**
* Get the value contained on the right of this bifunctor
- *
+ *
* @return The value on the right of this bifunctor
*/
public RightType getRight();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java
index a5007f1..1c53284 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/Functor.java
@@ -5,7 +5,7 @@ import java.util.function.Function;
/**
* Represents a container or context some sort usually, but the precise
* definition is that it represents exactly what it is defined as
- *
+ *
* @author ben
* @param <ContainedType>
* The value inside the functor
@@ -13,11 +13,11 @@ import java.util.function.Function;
public interface Functor<ContainedType> {
/**
* Converts a normal function to operate over values in a functor.
- *
+ *
* N.B: Even though the type signature implies that you can apply the
* resulting function to any type of functor, it is only safe to call it
* on instances of the type of functor you called fmap on.
- *
+ *
* @param <ArgType>
* The argument of the function
* @param <ReturnType>
@@ -32,7 +32,7 @@ public interface Functor<ContainedType> {
/**
* Retrieve the thing inside this functor
- *
+ *
* @return The thing inside this functor
*/
public ContainedType getValue();
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/package-info.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/package-info.java
index 33c80d6..713eb9f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/package-info.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/theory/package-info.java
@@ -1,6 +1,6 @@
/**
* Random functional type things that don't belong elsewhere
- *
+ *
* @author ben
*
*/