diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2018-02-12 22:45:04 -0500 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2018-02-12 22:45:04 -0500 |
| commit | df94066e3af02ff02d5ab4d033a3d603f743234c (patch) | |
| tree | 168a1edaf58d386c175ffb601e9d4da8e13d31e2 /base/src/main/java/bjc/utils/funcdata | |
| parent | ae51c587c53f7ca311e556e3cbd0c5566d6c2843 (diff) | |
Formatting pass
Diffstat (limited to 'base/src/main/java/bjc/utils/funcdata')
15 files changed, 385 insertions, 434 deletions
diff --git a/base/src/main/java/bjc/utils/funcdata/ExtendedMap.java b/base/src/main/java/bjc/utils/funcdata/ExtendedMap.java index 0c6389e..a2ace67 100644 --- a/base/src/main/java/bjc/utils/funcdata/ExtendedMap.java +++ b/base/src/main/java/bjc/utils/funcdata/ExtendedMap.java @@ -13,10 +13,10 @@ import bjc.utils.funcutils.ListUtils; * @author Ben Culkin * * @param <KeyType> - * The type of the keys of the map. + * The type of the keys of the map. * * @param <ValueType> - * The type of the values of the map. + * The type of the values of the map. */ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { /* The map we delegate lookups to. */ @@ -28,10 +28,10 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { * Create a new extended map. * * @param delegate - * The map to lookup things in. + * The map to lookup things in. * * @param store - * The map to store things in. + * The map to store things in. */ public ExtendedMap(final IMap<KeyType, ValueType> delegate, final IMap<KeyType, ValueType> store) { this.delegate = delegate; @@ -45,7 +45,7 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { @Override public boolean containsKey(final KeyType key) { - if (store.containsKey(key)) return true; + if(store.containsKey(key)) return true; return delegate.containsKey(key); } @@ -78,7 +78,7 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { @Override public ValueType get(final KeyType key) { - if (store.containsKey(key)) return store.get(key); + if(store.containsKey(key)) return store.get(key); return delegate.get(key); } @@ -105,7 +105,7 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { @Override public ValueType remove(final KeyType key) { - if (!store.containsKey(key)) return delegate.remove(key); + if(!store.containsKey(key)) return delegate.remove(key); return store.remove(key); } @@ -126,18 +126,18 @@ class ExtendedMap<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 ExtendedMap)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof ExtendedMap)) return false; final ExtendedMap<?, ?> other = (ExtendedMap<?, ?>) obj; - if (delegate == null) { - if (other.delegate != null) return false; - } else if (!delegate.equals(other.delegate)) return false; - if (store == null) { - if (other.store != null) return false; - } else if (!store.equals(other.store)) return false; + if(delegate == null) { + if(other.delegate != null) return false; + } else if(!delegate.equals(other.delegate)) return false; + if(store == null) { + if(other.store != null) return false; + } else if(!store.equals(other.store)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/funcdata/FunctionalList.java b/base/src/main/java/bjc/utils/funcdata/FunctionalList.java index 4cae085..c730424 100644 --- a/base/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/base/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -27,7 +27,7 @@ import bjc.utils.data.Pair; * @author ben * * @param <E> - * The type in this list + * The type in this list */ public class FunctionalList<E> implements Cloneable, IList<E> { /* The list used as a backing store */ @@ -44,13 +44,13 @@ public class FunctionalList<E> implements Cloneable, IList<E> { * Takes O(n) time, where n is the number of items specified * * @param items - * The items to put into this functional list. + * The items to put into this functional list. */ @SafeVarargs public FunctionalList(final E... items) { wrapped = new ArrayList<>(items.length); - for (final E item : items) { + for(final E item : items) { wrapped.add(item); } } @@ -59,7 +59,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { * Create a new functional list with the specified size. * * @param size - * The size of the backing list . + * The size of the backing list . */ private FunctionalList(final int size) { wrapped = new ArrayList<>(size); @@ -71,10 +71,10 @@ public class FunctionalList<E> implements Cloneable, IList<E> { * Takes O(1) time, since it doesn't copy the list. * * @param backing - * The list to use as a backing list. + * The list to use as a backing list. */ public FunctionalList(final 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; } @@ -86,10 +86,10 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public boolean allMatch(final 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 (final E item : wrapped) { - if (!predicate.test(item)) + for(final E item : wrapped) { + if(!predicate.test(item)) /* We've found a non-matching item. */ return false; } @@ -100,10 +100,10 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public boolean anyMatch(final 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 (final E item : wrapped) { - if (predicate.test(item)) + for(final E item : wrapped) { + if(predicate.test(item)) /* We've found a matching item. */ return true; } @@ -117,14 +117,13 @@ public class FunctionalList<E> implements Cloneable, IList<E> { * * Takes O(n) time, where n is the number of elements in the list. * - * @return - * A copy of the list. + * @return A copy of the list. */ @Override public IList<E> clone() { final IList<E> cloned = new FunctionalList<>(); - for (final E element : wrapped) { + for(final E element : wrapped) { cloned.add(element); } @@ -133,9 +132,9 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public <T, F> IList<F> combineWith(final IList<T> rightList, final 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) { + } else if(itemCombiner == null) { throw new NullPointerException("Combiner must not be null"); } @@ -144,7 +143,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { /* Get the iterator for the other list. */ final Iterator<T> rightIterator = rightList.toIterable().iterator(); - for (final Iterator<E> leftIterator = wrapped.iterator(); leftIterator.hasNext() + for(final Iterator<E> leftIterator = wrapped.iterator(); leftIterator.hasNext() && rightIterator.hasNext();) { /* Add the transformed items to the result list. */ final E leftVal = leftIterator.next(); @@ -164,22 +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(final 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"); final IList<T> returned = new FunctionalList<>(this.wrapped.size()); forEach(element -> { final 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); @@ -190,16 +188,19 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public void forEach(final 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(final 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. */ + /* + * This is held b/c ref'd variables must be final/effectively + * final. + */ final IHolder<Integer> currentIndex = new Identity<>(0); wrapped.forEach((element) -> { @@ -219,8 +220,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { /** * Get the internal backing list. * - * @return - * The backing list this list is based off of. + * @return The backing list this list is based off of. */ public List<E> getInternal() { return wrapped; @@ -228,13 +228,16 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public IList<E> getMatching(final 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"); final IList<E> returned = new FunctionalList<>(); wrapped.forEach((element) -> { - if (predicate.test(element)) { - /* The item matches, so add it to the returned list. */ + if(predicate.test(element)) { + /* + * The item matches, so add it to the returned + * list. + */ returned.add(element); } }); @@ -259,7 +262,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public <T> IList<T> map(final 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"); final IList<T> returned = new FunctionalList<>(this.wrapped.size()); @@ -278,7 +281,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public IList<IList<E>> partition(final int numberPerPartition) { - if (numberPerPartition < 1 || numberPerPartition > wrapped.size()) { + if(numberPerPartition < 1 || numberPerPartition > wrapped.size()) { final String fmt = "%s is an invalid partition size. Must be between 1 and %d"; final String msg = String.format(fmt, numberPerPartition, wrapped.size()); @@ -291,7 +294,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { final 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)); @@ -313,7 +316,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public E randItem(final 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"); final int randomIndex = rnd.apply(wrapped.size()); @@ -323,9 +326,9 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public <T, F> F reduceAux(final T initialValue, final BiFunction<E, T, T> stateAccumulator, final Function<T, F> resultTransformer) { - if (stateAccumulator == null) { + if(stateAccumulator == null) { throw new NullPointerException("Accumulator must not be null"); - } else if (resultTransformer == null) { + } else if(resultTransformer == null) { throw new NullPointerException("Transformer must not be null"); } @@ -343,7 +346,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public boolean removeIf(final 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); } @@ -363,7 +366,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { /* Search our internal list. */ final int foundIndex = Collections.binarySearch(wrapped, searchKey, comparator); - if (foundIndex >= 0) { + if(foundIndex >= 0) { /* We found a matching element. */ return wrapped.get(foundIndex); } @@ -396,19 +399,19 @@ public class FunctionalList<E> implements Cloneable, IList<E> { public String toString() { final int lSize = getSize(); - if (lSize == 0) return "()"; + if(lSize == 0) return "()"; final StringBuilder sb = new StringBuilder("("); final Iterator<E> itr = toIterable().iterator(); final E itm = itr.next(); int i = 0; - if (lSize == 1) return "(" + itm + ")"; + if(lSize == 1) return "(" + itm + ")"; - for (final E item : toIterable()) { + for(final E item : toIterable()) { sb.append(item.toString()); - if (i < lSize - 1) { + if(i < lSize - 1) { sb.append(", "); } diff --git a/base/src/main/java/bjc/utils/funcdata/FunctionalMap.java b/base/src/main/java/bjc/utils/funcdata/FunctionalMap.java index 1218833..115005c 100644 --- a/base/src/main/java/bjc/utils/funcdata/FunctionalMap.java +++ b/base/src/main/java/bjc/utils/funcdata/FunctionalMap.java @@ -14,10 +14,10 @@ import bjc.utils.data.IPair; * @author ben * * @param <KeyType> - * The type of the map's keys. + * The type of the map's keys. * * @param <ValueType> - * The type of the map's values. + * The type of the map's values. */ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { /* Our backing store. */ @@ -32,13 +32,13 @@ 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. + * The entries to put into the map. */ @SafeVarargs public FunctionalMap(final IPair<KeyType, ValueType>... entries) { this(); - for (final IPair<KeyType, ValueType> entry : entries) { + for(final IPair<KeyType, ValueType> entry : entries) { entry.doWith((key, val) -> { wrappedMap.put(key, val); }); @@ -49,10 +49,10 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp * Create a new functional map wrapping the specified map. * * @param wrap - * The map to wrap. + * The map to wrap. */ public FunctionalMap(final 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; } @@ -89,9 +89,9 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp @Override public ValueType get(final 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)) { final String msg = String.format("Key %s is not present in the map", key); throw new IllegalArgumentException(msg); @@ -118,14 +118,14 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp @Override public <MappedValue> IMap<KeyType, MappedValue> transform(final 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(final KeyType key, final 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); } @@ -161,15 +161,15 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof FunctionalMap)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof FunctionalMap)) return false; final FunctionalMap<?, ?> other = (FunctionalMap<?, ?>) obj; - if (wrappedMap == null) { - if (other.wrappedMap != null) return false; - } else if (!wrappedMap.equals(other.wrappedMap)) return false; + if(wrappedMap == null) { + if(other.wrappedMap != null) return false; + } else if(!wrappedMap.equals(other.wrappedMap)) return false; return true; } } diff --git a/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java b/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java index 384572d..4935e3d 100644 --- a/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java +++ b/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java @@ -14,13 +14,12 @@ public class FunctionalStringTokenizer { * Create a new tokenizer from the specified string. * * @param strang - * The string to create a tokenizer from. + * The string to create a tokenizer from. * - * @return - * A new tokenizer that splits the provided string on spaces. + * @return A new tokenizer that splits the provided string on spaces. */ public static FunctionalStringTokenizer fromString(final 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, " ")); } @@ -32,10 +31,10 @@ public class FunctionalStringTokenizer { * Create a functional string tokenizer from a given string. * * @param inp - * The string to tokenize. + * The string to tokenize. */ public FunctionalStringTokenizer(final 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); } @@ -45,15 +44,15 @@ public class FunctionalStringTokenizer { * separators. * * @param input - * The string to tokenize. + * The string to tokenize. * * @param seperators - * The set of separating tokens to use for splitting. + * The set of separating tokens to use for splitting. */ public FunctionalStringTokenizer(final String input, final String seperators) { - if (input == null) { + if(input == null) { throw new NullPointerException("String to tokenize must not be null"); - } else if (seperators == null) { + } else if(seperators == null) { throw new NullPointerException("Tokens to split on must not be null"); } @@ -64,10 +63,10 @@ public class FunctionalStringTokenizer { * Create a functional string tokenizer from a non-functional one. * * @param toWrap - * The non-functional string tokenizer to wrap. + * The non-functional string tokenizer to wrap. */ public FunctionalStringTokenizer(final 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; } @@ -76,12 +75,12 @@ public class FunctionalStringTokenizer { * Execute a provided action for each of the remaining tokens. * * @param action - * The action to execute for each token. + * The action to execute for each token. */ public void forEachToken(final 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()); } } @@ -89,8 +88,7 @@ public class FunctionalStringTokenizer { /** * Get the string tokenizer encapsulated by this tokenizer. * - * @return - * The encapsulated tokenizer. + * @return The encapsulated tokenizer. */ public StringTokenizer getInternal() { return input; @@ -99,8 +97,7 @@ public class FunctionalStringTokenizer { /** * Check if this tokenizer has more tokens. * - * @return - * Whether or not this tokenizer has more tokens. + * @return Whether or not this tokenizer has more tokens. */ public boolean hasMoreTokens() { return input.hasMoreTokens(); @@ -109,12 +106,11 @@ public class FunctionalStringTokenizer { /** * Return the next token from the tokenizer. * - * @return - * The next token from the tokenizer, or null if no more tokens are - * available. + * @return The next token from the tokenizer, or null if no more tokens + * are available. */ public String nextToken() { - if (input.hasMoreTokens()) { + if(input.hasMoreTokens()) { /* Return the next available token. */ return input.nextToken(); } @@ -126,8 +122,7 @@ public class FunctionalStringTokenizer { /** * Convert this tokenizer into a list of strings. * - * @return - * This tokenizer, converted into a list of strings. + * @return This tokenizer, converted into a list of strings. */ public IList<String> toList() { return toList((final String element) -> element); @@ -138,16 +133,15 @@ public class FunctionalStringTokenizer { * the input from this tokenizer. * * @param <E> - * The type of the converted tokens. + * The type of the converted tokens. * * @param transformer - * The function to use to convert tokens. + * The function to use to convert tokens. * - * @return - * A list containing all of the converted tokens. + * @return A list containing all of the converted tokens. */ public <E> IList<E> toList(final 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"); final IList<E> returned = new FunctionalList<>(); diff --git a/base/src/main/java/bjc/utils/funcdata/IList.java b/base/src/main/java/bjc/utils/funcdata/IList.java index 4dd2b1a..cfda68d 100644 --- a/base/src/main/java/bjc/utils/funcdata/IList.java +++ b/base/src/main/java/bjc/utils/funcdata/IList.java @@ -18,17 +18,16 @@ import bjc.utils.functypes.ID; * @author ben * * @param <ContainedType> - * The type in this list + * The type in this list */ public interface IList<ContainedType> extends Iterable<ContainedType> { /** * Add an item to this list. * * @param item - * The item to add to this list. + * The item to add to this list. * - * @return - * Whether the item was added to the list successfully.. + * @return Whether the item was added to the list successfully.. */ boolean add(ContainedType item); @@ -36,10 +35,10 @@ 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. + * The list of items to add. * - * @return - * True if every item was successfully added to the list, false otherwise. + * @return True if every item was successfully added to the list, false + * otherwise. */ default boolean addAll(final IList<ContainedType> items) { return items.map(this::add).anyMatch(bl -> bl == false); @@ -49,17 +48,16 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Add all of the elements in the provided array to this list. * * @param items - * The array of items to add. + * The array of items to add. * - * @return - * True if every item was successfully added to the list, false - * otherwise. + * @return True if every item was successfully added to the list, false + * otherwise. */ @SuppressWarnings("unchecked") default boolean addAll(final ContainedType... items) { boolean succ = true; - for (final ContainedType item : items) { + for(final ContainedType item : items) { final boolean addSucc = add(item); succ = succ ? addSucc : false; @@ -73,11 +71,10 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * predicate. * * @param matcher - * The predicate to use for checking. + * The predicate to use for checking. * - * @return - * Whether all of the elements of the list match the specified - * predicate. + * @return Whether all of the elements of the list match the specified + * predicate. */ boolean allMatch(Predicate<ContainedType> matcher); @@ -85,10 +82,10 @@ 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. + * The predicate to use for checking. * - * @return - * Whether any element in the list matches the provided predicate. + * @return Whether any element in the list matches the provided + * predicate. */ boolean anyMatch(Predicate<ContainedType> matcher); @@ -96,16 +93,15 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Reduce the contents of this list using a collector. * * @param <StateType> - * The intermediate accumulation type. + * The intermediate accumulation type. * * @param <ReducedType> - * The final, reduced type. + * The final, reduced type. * * @param collector - * The collector to use for reduction. + * The collector to use for reduction. * - * @return - * The reduced list. + * @return The reduced list. */ default <StateType, ReducedType> ReducedType collect( final Collector<ContainedType, StateType, ReducedType> collector) { @@ -130,19 +126,18 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * list and the combined one. * * @param <OtherType> - * The type of the second list. + * The type of the second list. * * @param <CombinedType> - * The type of the combined list. + * The type of the combined list. * * @param list - * The list to combine with. + * The list to combine with. * * @param combiner - * The function to use for combining element pairs. + * The function to use for combining element pairs. * - * @return - * A new list containing the merged pairs of lists. + * @return A new list containing the merged pairs of lists. */ <OtherType, CombinedType> IList<CombinedType> combineWith(IList<OtherType> list, BiFunction<ContainedType, OtherType, CombinedType> combiner); @@ -151,18 +146,16 @@ 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. + * The item to see if it is contained. * - * @return - * Whether or not the specified item is in the list. + * @return Whether or not the specified item is in the list. */ boolean contains(ContainedType item); /** * Get the first element in the list. * - * @return - * The first element in this list. + * @return The first element in this list. */ ContainedType first(); @@ -173,14 +166,13 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Does not change the underlying list. * * @param <MappedType> - * The type of the flattened list. + * The type of the flattened list. * * @param expander - * The function to apply to each member of the list. + * The function to apply to each member of the list. * - * @return - * A new list containing the flattened results of applying the - * provided function. + * @return A new list containing the flattened results of applying the + * provided function. */ <MappedType> IList<MappedType> flatMap(Function<ContainedType, IList<MappedType>> expander); @@ -188,7 +180,7 @@ 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. + * The action to apply to each member of the list. */ @Override void forEach(Consumer<? super ContainedType> action); @@ -197,7 +189,8 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * 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. + * The function to apply to each element in the list and its + * index. */ void forEachIndexed(BiConsumer<Integer, ContainedType> action); @@ -205,10 +198,9 @@ 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. + * The index to retrieve a value from. * - * @return - * The value at the specified index in the list. + * @return The value at the specified index in the list. */ ContainedType getByIndex(int index); @@ -216,26 +208,23 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Retrieve a list containing all elements matching a predicate. * * @param predicate - * The predicate to match by. + * The predicate to match by. * - * @return - * A list containing all elements that match the predicate. + * @return A list containing all elements that match the predicate. */ IList<ContainedType> getMatching(Predicate<ContainedType> predicate); /** * Retrieve the size of the wrapped list. * - * @return - * 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. + * @return Whether or not this list is empty. */ boolean isEmpty(); @@ -246,13 +235,12 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Does not change the underlying list. * * @param <MappedType> - * The type of the transformed list. + * The type of the transformed list. * * @param transformer - * The function to apply to each element in the list. + * The function to apply to each element in the list. * - * @return - * A new list containing the mapped elements of this list. + * @return A new list containing the mapped elements of this list. */ <MappedType> IList<MappedType> map(Function<ContainedType, MappedType> transformer); @@ -260,13 +248,13 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Zip two lists into a list of pairs. * * @param <OtherType> - * The type of the second list. + * The type of the second list. * * @param list - * The list to use as the left side of the pair. + * The list to use as the left side of the pair. * - * @return - * A list containing pairs of this element and the specified list. + * @return A list containing pairs of this element and the specified + * list. */ <OtherType> IList<IPair<ContainedType, OtherType>> pairWith(IList<OtherType> list); @@ -274,12 +262,11 @@ 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. - * - * @return - * A list partitioned into partitions of size partitionSize. The last - * partition may not be completely full if the size of the list is - * not a multiple of partitionSize. + * The size of elements to put into each one of the sublists. + * + * @return A list partitioned into partitions of size partitionSize. The + * last partition may not be completely full if the size of the + * list is not a multiple of partitionSize. */ IList<IList<ContainedType>> partition(int partitionSize); @@ -287,7 +274,7 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Prepend an item to the list. * * @param item - * The item to prepend to the list. + * The item to prepend to the list. */ void prepend(ContainedType item); @@ -295,11 +282,11 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Prepend an array of items to the list. * * @param items - * The items to prepend to the list. + * The items to prepend to the list. */ @SuppressWarnings("unchecked") default void prependAll(final ContainedType... items) { - for (final ContainedType item : items) { + for(final ContainedType item : items) { prepend(item); } } @@ -308,8 +295,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 + * @return A random item from the list */ default ContainedType randItem() { return randItem(num -> (int) (Math.random() * num)); @@ -320,10 +306,9 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * generator. * * @param rnd - * The random number generator to use. + * The random number generator to use. * - * @return - * A random element from this list. + * @return A random element from this list. */ ContainedType randItem(Function<Integer, Integer> rnd); @@ -331,25 +316,24 @@ 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 + * The in-between type of the values * * @param <ReducedType> - * The final value type + * The final value type * * @param initial - * The initial value of the accumulative state. + * The initial value of the accumulative state. * * @param accumulator - * The function to use to combine a list element with the - * accumulative state. + * The function to use to combine a list element with the + * accumulative state. * * @param transformer - * The function to use to convert the accumulative state into a - * final result. + * The function to use to convert the accumulative state into a + * final result. * - * @return - * A single value condensed from this list and transformed into its - * final state. + * @return A single value condensed from this list and transformed into + * its final state. */ <StateType, ReducedType> ReducedType reduceAux(StateType initial, BiFunction<ContainedType, StateType, StateType> accumulator, @@ -359,17 +343,16 @@ 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. + * The in-between type of the values. * * @param initial - * The initial value of the accumulative state. + * The initial value of the accumulative state. * * @param accumulator - * The function to use to combine a list element with the - * accumulative state. + * The function to use to combine a list element with the + * accumulative state. * - * @return - * A single value condensed from this list. + * @return A single value condensed from this list. */ default <StateType> StateType reduceAux(StateType initial, BiFunction<ContainedType, StateType, StateType> accumulator) { @@ -380,10 +363,9 @@ 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. + * The predicate to use to determine elements to delete. * - * @return - * Whether there was anything that satisfied the predicate. + * @return Whether there was anything that satisfied the predicate. */ boolean removeIf(Predicate<ContainedType> predicate); @@ -391,7 +373,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. + * The object to remove all matching copies of. */ void removeMatching(ContainedType element); @@ -406,14 +388,13 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * hand. * * @param key - * The key to search for. + * The key to search for. * * @param comparator - * The way to compare elements for searching. Pass null to use the - * natural ordering for E. + * The way to compare elements for searching. Pass null to use + * the natural ordering for E. * - * @return - * The element if it is in this list, or null if it is not. + * @return The element if it is in this list, or null if it is not. */ ContainedType search(ContainedType key, Comparator<ContainedType> comparator); @@ -424,16 +405,15 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Does change the underlying list. * * @param comparator - * The way to compare elements for sorting. Pass null to use E's - * natural ordering + * The way to compare elements for sorting. Pass null to use E's + * natural ordering */ void sort(Comparator<ContainedType> comparator); /** * Get the tail of this list (the list without the first element). * - * @return - * The list without the first element. + * @return The list without the first element. */ IList<ContainedType> tail(); @@ -441,18 +421,16 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Convert this list into an array. * * @param type - * The type of array to return. + * The type of array to return. * - * @return - * The list, as an array. + * @return The list, as an array. */ ContainedType[] toArray(ContainedType[] type); /** * Convert the list into a Iterable. * - * @return - * An iterable view onto the list. + * @return An iterable view onto the list. */ Iterable<ContainedType> toIterable(); diff --git a/base/src/main/java/bjc/utils/funcdata/IMap.java b/base/src/main/java/bjc/utils/funcdata/IMap.java index 35dc64b..9449898 100644 --- a/base/src/main/java/bjc/utils/funcdata/IMap.java +++ b/base/src/main/java/bjc/utils/funcdata/IMap.java @@ -10,17 +10,17 @@ import java.util.function.Function; * @author ben * * @param <KeyType> - * The type of this map's keys. + * The type of this map's keys. * * @param <ValueType> - * The type of this map's values. + * The type of this map's values. */ public interface IMap<KeyType, ValueType> { /** * Execute an action for each entry in the map. * * @param action - * The action to execute for each entry in the map. + * The action to execute for each entry in the map. */ void forEach(BiConsumer<KeyType, ValueType> action); @@ -28,7 +28,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. + * The action to perform on each key in the map. */ default void forEachKey(final Consumer<KeyType> action) { forEach((key, val) -> action.accept(key)); @@ -38,7 +38,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. + * The action to perform on each value in the map. */ default void forEachValue(final Consumer<ValueType> action) { forEach((key, val) -> action.accept(val)); @@ -48,10 +48,9 @@ public interface IMap<KeyType, ValueType> { * Check if this map contains the specified key. * * @param key - * The key to check. + * The key to check. * - * @return - * Whether or not the map contains the key. + * @return Whether or not the map contains the key. */ boolean containsKey(KeyType key); @@ -59,10 +58,9 @@ public interface IMap<KeyType, ValueType> { * Get the value assigned to the given key. * * @param key - * The key to look for a value under. + * The key to look for a value under. * - * @return - * The value of the key. + * @return The value of the key. */ ValueType get(KeyType key); @@ -71,14 +69,13 @@ public interface IMap<KeyType, ValueType> { * doesn't exist. * * @param key - * The key to attempt to retrieve. + * The key to attempt to retrieve. * * @param defaultValue - * The value to return if the key doesn't exist. + * The value to return if the key doesn't exist. * - * @return - * The value associated with the key, or the default value if the - * key doesn't exist. + * @return The value associated with the key, or the default value if + * the key doesn't exist. */ default ValueType getOrDefault(final KeyType key, final ValueType defaultValue) { try { @@ -96,18 +93,17 @@ public interface IMap<KeyType, ValueType> { * Add an entry to the map. * * @param key - * The key to put the value under. + * The key to put the value under. * * @param val - * The value to add. + * The value to add. * - * @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. + * @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. + * If the map implementation doesn't support modifying the map. */ ValueType put(KeyType key, ValueType val); @@ -119,17 +115,16 @@ public interface IMap<KeyType, ValueType> { /** * Get the number of entries in this map. * - * @return - * The number of entries in this map. + * @return The number of entries in this map. */ default int size() { return keyList().getSize(); } - /* @NOTE - * Do we want this to be the semantics for transform, or do we want - * to go to semantics using something like Isomorphism, or doing a - * one-time bulk conversion of the values? + /* + * @NOTE Do we want this to be the semantics for transform, or do we + * want to go to semantics using something like Isomorphism, or doing a + * one-time bulk conversion of the values? */ /** * Transform the values returned by this map. @@ -139,13 +134,12 @@ public interface IMap<KeyType, ValueType> { * likely not work as expected. * * @param <V2> - * The new type of returned values. + * The new type of returned values. * * @param transformer - * The function to use to transform values. + * The function to use to transform values. * - * @return - * The map where each value will be transformed after lookup. + * @return The map where each value will be transformed after lookup. */ default <V2> IMap<KeyType, V2> transform(final Function<ValueType, V2> transformer) { return new TransformedValueMap<>(this, transformer); @@ -155,8 +149,7 @@ 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. + * @return An extended map. */ IMap<KeyType, ValueType> extend(); @@ -164,34 +157,31 @@ public interface IMap<KeyType, ValueType> { * Remove the value bound to the key. * * @param key - * The key to remove from the map. + * The key to remove from the map. * - * @return - * The previous value for the key in the map, or null if the key - * wasn't in the class. NOTE: Just because you received null, - * doesn't mean the map wasn't changed. It may mean that someone - * put a null value for that key into the map. + * @return The previous value for the key in the map, or null if the key + * wasn't in the class. NOTE: Just because you received null, + * doesn't mean the map wasn't changed. It may mean that someone + * put a null value for that key into the map. */ ValueType remove(KeyType key); /** * Get a list of all the keys in this map. * - * @return - * A list of all the keys in this map. + * @return A list of all the keys in this map. */ IList<KeyType> keyList(); /** * Get a list of the values in this map. * - * @return - * A list of values in this map. + * @return A list of values in this map. */ default IList<ValueType> valueList() { final IList<ValueType> returns = new FunctionalList<>(); - for (final KeyType key : keyList()) { + for(final KeyType key : keyList()) { returns.add(get(key)); } diff --git a/base/src/main/java/bjc/utils/funcdata/SentryList.java b/base/src/main/java/bjc/utils/funcdata/SentryList.java index 1040328..a6a960a 100644 --- a/base/src/main/java/bjc/utils/funcdata/SentryList.java +++ b/base/src/main/java/bjc/utils/funcdata/SentryList.java @@ -8,7 +8,7 @@ import java.util.List; * @author bjculkin * * @param <T> - * The type of item in the list. + * The type of item in the list. */ public class SentryList<T> extends FunctionalList<T> { /** Create a new sentry list. */ @@ -20,7 +20,7 @@ public class SentryList<T> extends FunctionalList<T> { * Create a new sentry list backed by an existing list. * * @param backing - * The backing list. + * The backing list. */ public SentryList(final List<T> backing) { super(backing); @@ -30,7 +30,7 @@ public class SentryList<T> extends FunctionalList<T> { public boolean add(final T item) { final boolean val = super.add(item); - if (val) { + if(val) { System.out.println("Added item (" + item + ") to list"); } diff --git a/base/src/main/java/bjc/utils/funcdata/TransformedValueMap.java b/base/src/main/java/bjc/utils/funcdata/TransformedValueMap.java index a8cb762..d6d85dd 100644 --- a/base/src/main/java/bjc/utils/funcdata/TransformedValueMap.java +++ b/base/src/main/java/bjc/utils/funcdata/TransformedValueMap.java @@ -10,18 +10,18 @@ import java.util.function.Function; * @author ben * * @param <OldKey> - * The type of the map's keys + * The type of the map's keys * * @param <OldValue> - * The type of the map's values + * The type of the map's values * * @param <NewValue> - * The type of the transformed values + * The type of the transformed values * */ final class TransformedValueMap<OldKey, OldValue, NewValue> implements IMap<OldKey, NewValue> { /* Our backing map. */ - private final IMap<OldKey, OldValue> backing; + private final IMap<OldKey, OldValue> backing; /* Our transforming function. */ private final Function<OldValue, NewValue> transformer; @@ -29,10 +29,10 @@ final class TransformedValueMap<OldKey, OldValue, NewValue> implements IMap<OldK * Create a new transformed-value loop. * * @param backingMap - * The map to use as backing. + * The map to use as backing. * * @param transform - * The function to use for the transform. + * The function to use for the transform. */ public TransformedValueMap(final IMap<OldKey, OldValue> backingMap, final Function<OldValue, NewValue> transform) { diff --git a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java index f9dc4a2..6631834 100644 --- a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java +++ b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTree.java @@ -14,7 +14,7 @@ import bjc.utils.funcdata.IList; * @author ben * * @param <T> - * The data type stored in the node. + * The data type stored in the node. */ public class BinarySearchTree<T> { /* The comparator for use in ordering items */ @@ -30,10 +30,10 @@ public class BinarySearchTree<T> { * Create a new tree using the specified way to compare elements. * * @param cmp - * The thing to use for comparing elements + * 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; @@ -43,12 +43,12 @@ public class BinarySearchTree<T> { * Add a node to the binary search tree. * * @param element - * The data to add to the binary search tree. + * The data to add to the binary search tree. */ public void addNode(final T element) { elementCount++; - if (root == null) { + if(root == null) { root = new BinarySearchTreeNode<>(element, null, null); } else { root.add(element, comparator); @@ -59,16 +59,15 @@ public class BinarySearchTree<T> { * Check if an adjusted pivot falls with the bounds of a list. * * @param elements - * The list to get bounds from. + * The list to get bounds from. * * @param pivot - * The pivot. + * The pivot. * * @param pivotAdjustment - * The distance from the pivot. + * The distance from the pivot. * - * @return - * Whether the adjusted pivot is with the list. + * @return Whether the adjusted pivot is with the list. */ private boolean adjustedPivotInBounds(final IList<T> elements, final int pivot, final int pivotAdjustment) { return ((pivot - pivotAdjustment) >= 0) && ((pivot + pivotAdjustment) < elements.getSize()); @@ -93,8 +92,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 { @@ -111,9 +110,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); } } @@ -125,7 +124,7 @@ public class BinarySearchTree<T> { * invoked, and are not included in traversals/finds. * * @param element - * The node to delete + * The node to delete */ public void deleteNode(final T element) { elementCount--; @@ -136,8 +135,7 @@ public class BinarySearchTree<T> { /** * Get the root of the tree. * - * @return - * The root of the tree. + * @return The root of the tree. */ public ITreePart<T> getRoot() { return root; @@ -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.. + * The node to check the presence of for the tree.. * * @return Whether or not the node is in the tree. */ @@ -159,15 +157,15 @@ 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. + * The way to linearize the tree for traversal. * * @param traversalPredicate - * The function to use until it fails. + * The function to use until it fails. */ public void traverse(final TreeLinearizationMethod linearizationMethod, final Predicate<T> traversalPredicate) { - if (linearizationMethod == null) { + if(linearizationMethod == null) { throw new NullPointerException("Linearization method must not be null"); - } else if (traversalPredicate == null) { + } else if(traversalPredicate == null) { throw new NullPointerException("Predicate must not be nulls"); } @@ -210,16 +208,16 @@ public class BinarySearchTree<T> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof BinarySearchTree<?>)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof BinarySearchTree<?>)) return false; final BinarySearchTree<?> other = (BinarySearchTree<?>) obj; - if (elementCount != other.elementCount) return false; - if (root == null) { - if (other.root != null) return false; - } else if (!root.equals(other.root)) return false; + if(elementCount != other.elementCount) return false; + if(root == null) { + if(other.root != null) return false; + } else if(!root.equals(other.root)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java index 46f597e..762288f 100644 --- a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java +++ b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeLeaf.java @@ -11,7 +11,7 @@ import java.util.function.Predicate; * @author ben * * @param <T> - * The data stored in the tree. + * The data stored in the tree. */ public class BinarySearchTreeLeaf<T> implements ITreePart<T> { /** The data held in this tree leaf */ @@ -24,7 +24,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. + * The data for the leaf to hold. */ public BinarySearchTreeLeaf(final T element) { data = element; @@ -37,7 +37,7 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> { @Override public <E> E collapse(final Function<T, E> leafTransformer, final 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); } @@ -54,16 +54,16 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> { @Override public void delete(final T element, final Comparator<T> comparator) { - if (data.equals(element)) { + if(data.equals(element)) { isDeleted = true; } } @Override public boolean directedWalk(final 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. */ @@ -78,7 +78,7 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> { @Override public boolean forEach(final TreeLinearizationMethod linearizationMethod, final 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); } @@ -99,16 +99,16 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof BinarySearchTreeLeaf<?>)) return false; + if(this == obj) return true; + if(obj == null) return false; + if(!(obj instanceof BinarySearchTreeLeaf<?>)) return false; final BinarySearchTreeLeaf<?> other = (BinarySearchTreeLeaf<?>) obj; - if (data == null) { - if (other.data != null) return false; - } else if (!data.equals(other.data)) return false; - if (isDeleted != other.isDeleted) return false; + if(data == null) { + if(other.data != null) return false; + } else if(!data.equals(other.data)) return false; + if(isDeleted != other.isDeleted) return false; return true; } diff --git a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java index 3124474..eb7b6b5 100644 --- a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java +++ b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java @@ -16,7 +16,7 @@ import java.util.function.Predicate; * @author ben * * @param <T> - * The data type stored in the tree. + * The data type stored in the tree. */ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { /* The left child of this node */ @@ -29,13 +29,13 @@ 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. + * The data to store in this node. * * @param lft - * The left child of this node. + * The left child of this node. * * @param rght - * The right child of this node. + * The right child of this node. */ public BinarySearchTreeNode(final T element, final ITreePart<T> lft, final ITreePart<T> rght) { super(element); @@ -45,23 +45,24 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { @Override public void add(final T element, final 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 throw new IllegalArgumentException("Can't add duplicate values"); + } 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); @@ -74,15 +75,15 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { @Override public <E> E collapse(final Function<T, E> nodeCollapser, final BiFunction<E, E, E> branchCollapser) { - if (nodeCollapser == null || branchCollapser == null) + if(nodeCollapser == null || branchCollapser == null) throw new NullPointerException("Collapser must not be null"); final E collapsedNode = nodeCollapser.apply(data); - if (left != null) { + if(left != null) { final E collapsedLeftBranch = left.collapse(nodeCollapser, branchCollapser); - if (right != null) { + if(right != null) { final E collapsedRightBranch = right.collapse(nodeCollapser, branchCollapser); final E collapsedBranches = branchCollapser.apply(collapsedLeftBranch, @@ -94,7 +95,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { return branchCollapser.apply(collapsedNode, collapsedLeftBranch); } - if (right != null) { + if(right != null) { final E collapsedRightBranch = right.collapse(nodeCollapser, branchCollapser); return branchCollapser.apply(collapsedNode, collapsedRightBranch); @@ -105,10 +106,10 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { @Override public boolean contains(final T element, final 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: @@ -123,10 +124,10 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { @Override public void delete(final T element, final 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: @@ -142,9 +143,9 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { @Override public boolean directedWalk(final 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: @@ -160,13 +161,13 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { @Override public boolean forEach(final TreeLinearizationMethod linearizationMethod, final Predicate<T> traversalPredicate) { - if (linearizationMethod == null) { + if(linearizationMethod == null) { throw new NullPointerException("Linearization method must not be null"); - } else if (traversalPredicate == 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: @@ -174,7 +175,8 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { case POSTORDER: return postorderTraverse(linearizationMethod, traversalPredicate); default: - String msg = String.format("Passed an incorrect TreeLinearizationMethod %s. WAT", linearizationMethod); + String msg = String.format("Passed an incorrect TreeLinearizationMethod %s. WAT", + linearizationMethod); throw new IllegalArgumentException(msg); } @@ -183,11 +185,11 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { /* Do an in-order traversal. */ private boolean inorderTraverse(final TreeLinearizationMethod linearizationMethod, final 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; } @@ -195,11 +197,11 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { /* Do a post-order traversal. */ private boolean postorderTraverse(final TreeLinearizationMethod linearizationMethod, final 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; @@ -208,11 +210,11 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { /* Do a pre-order traversal. */ private boolean preorderTraverse(final TreeLinearizationMethod linearizationMethod, final 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; } @@ -221,7 +223,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { private boolean traverseElement(final Predicate<T> traversalPredicate) { boolean nodeSuccesfullyTraversed; - if (isDeleted) { + if(isDeleted) { nodeSuccesfullyTraversed = true; } else { nodeSuccesfullyTraversed = traversalPredicate.test(data); @@ -235,7 +237,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { final Predicate<T> traversalPredicate) { boolean leftSuccesfullyTraversed; - if (left == null) { + if(left == null) { leftSuccesfullyTraversed = true; } else { leftSuccesfullyTraversed = left.forEach(linearizationMethod, traversalPredicate); @@ -249,7 +251,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { final Predicate<T> traversalPredicate) { boolean rightSuccesfullyTraversed; - if (right == null) { + if(right == null) { rightSuccesfullyTraversed = true; } else { rightSuccesfullyTraversed = right.forEach(linearizationMethod, traversalPredicate); @@ -274,19 +276,19 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (!super.equals(obj)) return false; - if (!(obj instanceof BinarySearchTreeNode<?>)) return false; + if(this == obj) return true; + if(!super.equals(obj)) return false; + if(!(obj instanceof BinarySearchTreeNode<?>)) return false; final BinarySearchTreeNode<?> other = (BinarySearchTreeNode<?>) obj; - if (left == null) { - if (other.left != null) return false; - } else if (!left.equals(other.left)) return false; + if(left == null) { + if(other.left != null) return false; + } else if(!left.equals(other.left)) return false; - if (right == null) { - if (other.right != null) return false; - } else if (!right.equals(other.right)) return false; + if(right == null) { + if(other.right != null) return false; + } else if(!right.equals(other.right)) return false; return true; } diff --git a/base/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java b/base/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java index fdf86d7..e341320 100644 --- a/base/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java +++ b/base/src/main/java/bjc/utils/funcdata/bst/DirectedWalkFunction.java @@ -6,7 +6,7 @@ package bjc.utils.funcdata.bst; * @author ben * * @param <T> - * The type of element stored in the walked tree + * The type of element stored in the walked tree */ @FunctionalInterface public interface DirectedWalkFunction<T> { @@ -36,10 +36,9 @@ public interface DirectedWalkFunction<T> { * Perform a directed walk on a node of a tree. * * @param element - * The data stored in the node currently being visited. + * The data stored in the node currently being visited. * - * @return - * The way the function wants the walk to go next. + * @return The way the function wants the walk to go next. */ public DirectedWalkResult walk(T element); } diff --git a/base/src/main/java/bjc/utils/funcdata/bst/ITreePart.java b/base/src/main/java/bjc/utils/funcdata/bst/ITreePart.java index a2ce71f..f9b3d4a 100644 --- a/base/src/main/java/bjc/utils/funcdata/bst/ITreePart.java +++ b/base/src/main/java/bjc/utils/funcdata/bst/ITreePart.java @@ -11,18 +11,18 @@ import java.util.function.Predicate; * @author ben * * @param <T> - * The data contained in this part of the tree. + * The data contained in this part of the tree. */ public interface ITreePart<T> { /** * Add a element below this tree part somewhere. * * @param element - * The element to add below this tree part + * The element to add below this tree part * * @param comparator - * The thing to use for comparing values to find where to - * insert the tree part. + * The thing to use for comparing values to find where to insert + * the tree part. */ public void add(T element, Comparator<T> comparator); @@ -32,17 +32,16 @@ public interface ITreePart<T> { * Does not change the underlying tree. * * @param <E> - * The type of the final collapsed value + * The type of the final collapsed value * * @param nodeCollapser - * The function to use to transform data into mapped form. + * The function to use to transform data into mapped form. * * @param branchCollapser - * The function to use to collapse data in mapped form into a - * single value. + * The function to use to collapse data in mapped form into a + * single value. * - * @return - * A single value from collapsing the tree. + * @return A single value from collapsing the tree. */ public <E> E collapse(Function<T, E> nodeCollapser, BiFunction<E, E, E> branchCollapser); @@ -50,22 +49,20 @@ 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. + * The data item to look for. * * @param comparator - * The comparator to use to search for the data item. + * The comparator to use to search for the data item. * - * @return - * Whether or not the given item is contained in this tree part or - * its children. + * @return Whether or not the given item is contained in this tree part + * or its children. */ public boolean contains(T element, Comparator<T> comparator); /** * Get the data associated with this tree part. * - * @return - * The data associated with this tree part. + * @return The data associated with this tree part. */ public T data(); @@ -73,10 +70,10 @@ public interface ITreePart<T> { * Remove the given node from this tree part and any of its children. * * @param element - * The data item to remove. + * The data item to remove. * * @param comparator - * The comparator to use to search for the data item. + * The comparator to use to search for the data item. */ public void delete(T element, Comparator<T> comparator); @@ -84,11 +81,9 @@ public interface ITreePart<T> { * Execute a directed walk through the tree. * * @param walker - * The function to use to direct the walk through the - * tree. + * The function to use to direct the walk through the tree. * - * @return - * Whether the directed walk finished successfully. + * @return Whether the directed walk finished successfully. */ public boolean directedWalk(DirectedWalkFunction<T> walker); @@ -97,14 +92,13 @@ public interface ITreePart<T> { * completes for. * * @param linearizationMethod - * The way to linearize the tree for executing. + * The way to linearize the tree for executing. * * @param predicate - * The predicate to apply to each element, where it returning false - * terminates traversal early. + * The predicate to apply to each element, where it returning + * false terminates traversal early. * - * @return - * Whether the traversal finished succesfully. + * @return Whether the traversal finished succesfully. */ public boolean forEach(TreeLinearizationMethod linearizationMethod, Predicate<T> predicate); } diff --git a/base/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java b/base/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java index a94a7b5..4bbc154 100644 --- a/base/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java +++ b/base/src/main/java/bjc/utils/funcdata/theory/Bifunctor.java @@ -8,10 +8,10 @@ import java.util.function.Function; * @author ben * * @param <LeftType> - * The type stored on the 'left' of the pair. + * The type stored on the 'left' of the pair. * * @param <RightType> - * The type stored on the 'right' of the pair. + * The type stored on the 'right' of the pair. */ public interface Bifunctor<LeftType, RightType> { /** @@ -19,17 +19,17 @@ public interface Bifunctor<LeftType, RightType> { * * @author EVE * - * @param <OldLeft> - * The old left type. + * @param <OldLeft> + * The old left type. * * @param <OldRight> - * The old right type. + * The old right type. * * @param <NewLeft> - * The new left type. + * The new left type. * * @param <NewRight> - * The new right type. + * The new right type. */ public interface BifunctorMap<OldLeft, OldRight, NewLeft, NewRight> extends Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, NewRight>> { @@ -42,13 +42,13 @@ public interface Bifunctor<LeftType, RightType> { * @author EVE * * @param <OldLeft> - * The old left type. + * The old left type. * * @param <OldRight> - * The old right type. + * The old right type. * * @param <NewLeft> - * The new left type. + * The new left type. */ public interface LeftBifunctorMap<OldLeft, OldRight, NewLeft> extends BifunctorMap<OldLeft, OldRight, NewLeft, OldRight> { @@ -61,13 +61,13 @@ public interface Bifunctor<LeftType, RightType> { * @author EVE * * @param <OldLeft> - * The old left type. + * The old left type. * * @param <OldRight> - * The old right type. + * The old right type. * * @param <NewRight> - * The new right type. + * The new right type. */ public interface RightBifunctorMap<OldLeft, OldRight, NewRight> extends BifunctorMap<OldLeft, OldRight, OldLeft, NewRight> { @@ -79,25 +79,24 @@ public interface Bifunctor<LeftType, RightType> { * parts of a pair. * * @param <OldLeft> - * The old left type of the pair. + * The old left type of the pair. * * @param <OldRight> - * The old right type of the pair. + * The old right type of the pair. * * @param <NewLeft> - * The new left type of the pair. + * The new left type of the pair. * * @param <NewRight> - * The new right type of the pair. + * The new right type of the pair. * * @param leftFunc - * The function that maps over the left of the pair. + * The function that maps over the left of the pair. * * @param rightFunc - * The function that maps over the right of the pair. + * The function that maps over the right of the pair. * - * @return - * A function that maps over both parts of the pair. + * @return A function that maps over both parts of the pair. */ public default <OldLeft, OldRight, NewLeft, NewRight> BifunctorMap<OldLeft, OldRight, NewLeft, NewRight> bimap( final Function<OldLeft, NewLeft> leftFunc, final Function<OldRight, NewRight> rightFunc) { @@ -118,19 +117,18 @@ 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. + * The old left type of the pair. * * @param <OldRight> - * The old right type of the pair. + * The old right type of the pair. * * @param <NewLeft> - * The new left type of the pair. + * The new left type of the pair. * * @param func - * The function to lift to work over the left side of the pair. + * The function to lift to work over the left side of the pair. * - * @return - * The function lifted to work over the left side of bifunctors. + * @return The function lifted to work over the left side of bifunctors. */ public <OldLeft, OldRight, NewLeft> LeftBifunctorMap<OldLeft, OldRight, NewLeft> fmapLeft( Function<OldLeft, NewLeft> func); @@ -139,20 +137,19 @@ 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. + * The old left type of the pair. * * @param <OldRight> - * The old right type of the pair. + * The old right type of the pair. * * @param <NewRight> - * The new right type of the pair. + * The new right type of the pair. * * @param func - * The function to lift to work over the right side of - * the pair. + * The function to lift to work over the right side of the pair. * - * @return - * The function lifted to work over the right side of bifunctors. + * @return The function lifted to work over the right side of + * bifunctors. */ public <OldLeft, OldRight, NewRight> RightBifunctorMap<OldLeft, OldRight, NewRight> fmapRight( Function<OldRight, NewRight> func); @@ -160,16 +157,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. + * @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. + * @return The value on the right of this bifunctor. */ public RightType getRight(); } diff --git a/base/src/main/java/bjc/utils/funcdata/theory/Functor.java b/base/src/main/java/bjc/utils/funcdata/theory/Functor.java index 9efa883..13852e6 100644 --- a/base/src/main/java/bjc/utils/funcdata/theory/Functor.java +++ b/base/src/main/java/bjc/utils/funcdata/theory/Functor.java @@ -9,7 +9,7 @@ import java.util.function.Function; * @author ben * * @param <ContainedType> - * The value inside the functor. + * The value inside the functor. */ public interface Functor<ContainedType> { /** @@ -20,17 +20,16 @@ public interface Functor<ContainedType> { * on instances of the type of functor you called fmap on.. * * @param <ArgType> - * The argument of the function. + * The argument of the function. * * @param <ReturnType> - * The return type of the function. + * The return type of the function. * * @param func - * The function to convert. + * The function to convert. * - * @return - * The passed in function converted to work over a particular - * type of functors. + * @return The passed in function converted to work over a particular + * type of functors. */ public <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap( Function<ArgType, ReturnType> func); @@ -38,8 +37,7 @@ public interface Functor<ContainedType> { /** * Retrieve the thing inside this functor. * - * @return - * The thing inside this functor. + * @return The thing inside this functor. */ public ContainedType getValue(); } |
