diff options
| author | EVE <EVE@EVE-PC> | 2017-03-13 16:42:21 -0400 |
|---|---|---|
| committer | EVE <EVE@EVE-PC> | 2017-03-13 16:42:21 -0400 |
| commit | 27bf571d6413c3cc6a5d664b5bddd38d21d7b1cd (patch) | |
| tree | 847fb52acb091c1c613d37b8477094d5762c6988 /BJC-Utils2/src/main/java/bjc/utils/funcdata | |
| parent | aa807a96cae2c47259fb38f710640883060339e9 (diff) | |
Formatting
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata')
16 files changed, 309 insertions, 340 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 0a2ee39..7e6c23b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java @@ -7,12 +7,11 @@ import java.util.function.Function; import bjc.utils.funcutils.ListUtils; class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { - private IMap<KeyType, ValueType> delegate; + private IMap<KeyType, ValueType> delegate; - private IMap<KeyType, ValueType> store; + private IMap<KeyType, ValueType> store; - public ExtendedMap(IMap<KeyType, ValueType> delegate, - IMap<KeyType, ValueType> store) { + public ExtendedMap(IMap<KeyType, ValueType> delegate, IMap<KeyType, ValueType> store) { this.delegate = delegate; this.store = store; } @@ -77,8 +76,7 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { } @Override - public <MappedValue> IMap<KeyType, MappedValue> mapValues( - Function<ValueType, MappedValue> transformer) { + public <MappedValue> IMap<KeyType, MappedValue> mapValues(Function<ValueType, MappedValue> transformer) { return new TransformedValueMap<>(this, transformer); } @@ -94,7 +92,6 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { @Override public IList<ValueType> valueList() { - return ListUtils.mergeLists(store.valueList(), - delegate.valueList()); + return ListUtils.mergeLists(store.valueList(), delegate.valueList()); } } 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 3f61303..f98f32c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -18,16 +18,16 @@ import bjc.utils.data.Identity; import bjc.utils.data.Pair; /** - * A wrapper over another list that provides eager functional operations - * over it. + * 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. + * Differs from a stream in every way except for the fact that they both provide + * functional operations. * * @author ben * * @param <E> - * The type in this list + * The type in this list */ public class FunctionalList<E> implements Cloneable, IList<E> { /* @@ -48,7 +48,7 @@ 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(E... items) { @@ -63,7 +63,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(int size) { wrapped = new ArrayList<>(size); @@ -75,12 +75,11 @@ 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(List<E> backing) { if (backing == null) { - throw new NullPointerException( - "Backing list must be non-null"); + throw new NullPointerException("Backing list must be non-null"); } wrapped = backing; @@ -144,10 +143,9 @@ public class FunctionalList<E> implements Cloneable, IList<E> { } @Override - public <T, F> IList<F> combineWith(IList<T> rightList, - BiFunction<E, T, F> itemCombiner) { + public <T, F> IList<F> combineWith(IList<T> rightList, BiFunction<E, T, F> itemCombiner) { if (rightList == null) { - throw new NullPointerException( "Target combine list must not be null"); + throw new NullPointerException("Target combine list must not be null"); } else if (itemCombiner == null) { throw new NullPointerException("Combiner must not be null"); } @@ -157,8 +155,8 @@ public class FunctionalList<E> implements Cloneable, IList<E> { // 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(); @@ -220,7 +218,8 @@ public class FunctionalList<E> implements Cloneable, IList<E> { 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 IHolder<Integer> currentIndex = new Identity<>(0); wrapped.forEach((element) -> { @@ -256,7 +255,8 @@ public class FunctionalList<E> implements Cloneable, IList<E> { wrapped.forEach((element) -> { if (predicate.test(element)) { - // The item matches, so add it to the returned list + // The item matches, so add it to the returned + // list returned.add(element); } }); @@ -277,8 +277,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { /* * Check if a partition has room for another item */ - private Boolean isPartitionFull(int numberPerPartition, - IHolder<IList<E>> currentPartition) { + private Boolean isPartitionFull(int numberPerPartition, IHolder<IList<E>> currentPartition) { return currentPartition.unwrap((partition) -> partition.getSize() >= numberPerPartition); } @@ -305,18 +304,15 @@ 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()); + + " is an invalid partition size. Must be between 1 and " + wrapped.size()); } IList<IList<E>> returned = new FunctionalList<>(); // The current partition being filled - IHolder<IList<E>> currentPartition = new Identity<>( - new FunctionalList<>()); + IHolder<IList<E>> currentPartition = new Identity<>(new FunctionalList<>()); this.forEach((element) -> { if (isPartitionFull(numberPerPartition, currentPartition)) { @@ -351,8 +347,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { } @Override - public <T, F> F reduceAux(T initialValue, - BiFunction<E, T, T> stateAccumulator, + public <T, F> F reduceAux(T initialValue, BiFunction<E, T, T> stateAccumulator, Function<T, F> resultTransformer) { if (stateAccumulator == null) { throw new NullPointerException("Accumulator must not be null"); @@ -394,8 +389,7 @@ public class FunctionalList<E> implements Cloneable, IList<E> { @Override public E search(E searchKey, Comparator<E> comparator) { // Search our internal list - int foundIndex = Collections.binarySearch(wrapped, searchKey, - comparator); + int foundIndex = Collections.binarySearch(wrapped, searchKey, comparator); if (foundIndex >= 0) { // We found a matching element @@ -431,21 +425,22 @@ 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) { + 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 cc70ae1..3d3fed1 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java @@ -14,9 +14,9 @@ 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> { private Map<KeyType, ValueType> wrappedMap; @@ -32,7 +32,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 + * The entries to put into the map */ @SafeVarargs public FunctionalMap(IPair<KeyType, ValueType>... entries) { @@ -49,7 +49,7 @@ 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(Map<KeyType, ValueType> wrap) { if (wrap == null) { @@ -119,8 +119,7 @@ public class FunctionalMap<KeyType, ValueType> implements IMap<KeyType, ValueTyp } @Override - public <MappedValue> IMap<KeyType, MappedValue> mapValues( - Function<ValueType, MappedValue> transformer) { + public <MappedValue> IMap<KeyType, MappedValue> mapValues(Function<ValueType, MappedValue> transformer) { if (transformer == null) { throw new NullPointerException("Transformer must not be null"); } 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 078bba6..93f2dca 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java @@ -15,13 +15,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. */ public static FunctionalStringTokenizer fromString(String strang) { if (strang == null) { - throw new NullPointerException( - "String to tokenize must be non-null"); + throw new NullPointerException("String to tokenize must be non-null"); } return new FunctionalStringTokenizer(new StringTokenizer(strang, " ")); @@ -36,7 +35,7 @@ public class FunctionalStringTokenizer { * Create a functional string tokenizer from a given string * * @param inp - * The string to tokenize + * The string to tokenize */ public FunctionalStringTokenizer(String inp) { if (inp == null) { @@ -51,12 +50,11 @@ 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(String input, - String seperators) { + public FunctionalStringTokenizer(String input, String seperators) { if (input == null) { throw new NullPointerException("String to tokenize must not be null"); } else if (seperators == null) { @@ -70,7 +68,7 @@ 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(StringTokenizer toWrap) { if (toWrap == null) { @@ -84,7 +82,7 @@ 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(Consumer<String> action) { if (action == null) { @@ -145,10 +143,10 @@ 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. */ public <E> IList<E> toList(Function<String, E> transformer) { 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 f6b207a..0feaf06 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java @@ -17,14 +17,14 @@ import bjc.utils.data.IPair; * @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. */ boolean add(ContainedType item); @@ -33,7 +33,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 + * The list of items to add * @return True if every item was successfully added to the list, false * otherwise */ @@ -46,7 +46,7 @@ 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. */ @@ -56,7 +56,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. + * The predicate to use for checking. * @return Whether any element in the list matches the provided * predicate. */ @@ -66,11 +66,11 @@ 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 */ default <StateType, ReducedType> ReducedType collect( @@ -88,32 +88,31 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { * Combine this list with another one into a new list and merge the * results. * - * Works sort of like a combined zip/map over resulting pairs. - * Does not change the underlying list. + * 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 + * 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. */ - <OtherType, CombinedType> IList<CombinedType> combineWith( - IList<OtherType> list, + <OtherType, CombinedType> IList<CombinedType> combineWith(IList<OtherType> list, BiFunction<ContainedType, OtherType, CombinedType> combiner); /** * 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 */ boolean contains(ContainedType item); @@ -132,21 +131,20 @@ 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. */ - <MappedType> IList<MappedType> flatMap( - Function<ContainedType, IList<MappedType>> expander); + <MappedType> IList<MappedType> flatMap(Function<ContainedType, IList<MappedType>> expander); /** * 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. */ void forEach(Consumer<? super ContainedType> action); @@ -154,8 +152,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); @@ -163,7 +161,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. + * The index to retrieve a value from. * @return The value at the specified index in the list. */ ContainedType getByIndex(int index); @@ -172,7 +170,7 @@ 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 */ IList<ContainedType> getMatching(Predicate<ContainedType> predicate); @@ -193,28 +191,27 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { /** * Create a new list by applying the given function to each element in - * the list. + * the list. * * 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. */ - <MappedType> IList<MappedType> map( - Function<ContainedType, MappedType> transformer); + <MappedType> IList<MappedType> map(Function<ContainedType, MappedType> transformer); /** * 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 */ @@ -224,7 +221,8 @@ 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 + * The size of elements to put into each one of the + * sublists * @return A list partitioned into partitions of size nPerPart */ IList<IList<ContainedType>> partition(int partitionSize); @@ -233,7 +231,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); @@ -248,11 +246,11 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { } /** - * Select a random item from this list, using the provided random - * number generator. + * Select a random item from this list, using the provided random number + * generator. * * @param rnd - * The random number generator to use. + * The random number generator to use. * @return A random element from this list. */ ContainedType randItem(Function<Integer, Integer> rnd); @@ -261,18 +259,18 @@ 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. */ @@ -284,7 +282,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 + * The predicate to use to determine elements to delete * @return Whether there was anything that satisfied the predicate */ boolean removeIf(Predicate<ContainedType> predicate); @@ -293,7 +291,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); @@ -304,29 +302,29 @@ public interface IList<ContainedType> extends Iterable<ContainedType> { /** * Perform a binary search for the specified key using the provided - * means of comparing elements. + * means of comparing elements. * - * Since this IS a binary search, the list must have been sorted before hand. + * Since this IS a binary search, the list must have been sorted before + * 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. */ - ContainedType search(ContainedType key, - Comparator<ContainedType> comparator); + ContainedType search(ContainedType key, Comparator<ContainedType> comparator); /** * Sort the elements of this list using the provided way of comparing - * elements. + * elements. * * 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); @@ -341,7 +339,7 @@ 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 */ ContainedType[] toArray(ContainedType[] type); 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 9e74628..ff8f973 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java @@ -10,9 +10,9 @@ 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> { @@ -25,7 +25,7 @@ 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 */ boolean containsKey(KeyType key); @@ -42,7 +42,7 @@ 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); @@ -50,7 +50,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 */ void forEachKey(Consumer<KeyType> action); @@ -58,7 +58,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 */ void forEachValue(Consumer<ValueType> action); @@ -66,7 +66,7 @@ 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 * * @@ -78,9 +78,9 @@ 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 */ @@ -88,7 +88,8 @@ public interface IMap<KeyType, ValueType> { try { return get(key); } catch (IllegalArgumentException iaex) { - // We don't care about this, because it indicates a key is + // We don't care about this, because it indicates a key + // is // missing return defaultValue; } @@ -116,9 +117,9 @@ 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 */ <V2> IMap<KeyType, V2> mapValues(Function<ValueType, V2> transformer); @@ -127,16 +128,16 @@ 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. + * 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); @@ -144,11 +145,11 @@ 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 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 + * 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 */ ValueType remove(KeyType key); 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 49cb106..32ec7cd 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/SentryList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/SentryList.java @@ -13,8 +13,8 @@ public class SentryList<T> extends FunctionalList<T> { 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 c87c34b..36bfaab 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java @@ -10,19 +10,17 @@ 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> { - private IMap<OldKey, OldValue> backing; - private Function<OldValue, NewValue> transformer; +final class TransformedValueMap<OldKey, OldValue, NewValue> implements IMap<OldKey, NewValue> { + private IMap<OldKey, OldValue> backing; + private Function<OldValue, NewValue> transformer; - public TransformedValueMap(IMap<OldKey, OldValue> backingMap, - Function<OldValue, NewValue> transform) { + public TransformedValueMap(IMap<OldKey, OldValue> backingMap, Function<OldValue, NewValue> transform) { backing = backingMap; transformer = transform; } @@ -77,8 +75,7 @@ final class TransformedValueMap<OldKey, OldValue, NewValue> } @Override - public <MappedValue> IMap<OldKey, MappedValue> - mapValues(Function<NewValue, MappedValue> transform) { + public <MappedValue> IMap<OldKey, MappedValue> mapValues(Function<NewValue, MappedValue> transform) { return new TransformedValueMap<>(this, transform); } 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 b595946..b3772a4 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 @@ -14,29 +14,29 @@ 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 */ - private Comparator<T> comparator; + private Comparator<T> comparator; /* * The current count of elements in the tree */ - private int elementCount; + private int elementCount; /* * The root element of the tree */ - private ITreePart<T> root; + private ITreePart<T> root; /** * 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(Comparator<T> cmp) { if (cmp == null) { @@ -51,7 +51,7 @@ 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(T element) { elementCount++; @@ -67,11 +67,11 @@ 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 */ private boolean adjustedPivotInBounds(IList<T> elements, int pivot, int pivotAdjustment) { @@ -102,7 +102,8 @@ public class BinarySearchTree<T> { // Create a new root element root = new BinarySearchTreeNode<>(elements.getByIndex(pivot), null, null); } else { - // Add the left and right elements in a balanced manner + // Add the left and right elements in a balanced + // manner root.add(elements.getByIndex(pivot + pivotAdjustment), comparator); root.add(elements.getByIndex(pivot - pivotAdjustment), comparator); @@ -123,11 +124,11 @@ public class BinarySearchTree<T> { /** * Soft-delete a node from the tree. * - * Soft-deleted nodes stay in the tree until trim()/balance() is invoked, and - * are not included in traversals/finds. + * 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 + * The node to delete */ public void deleteNode(T element) { elementCount--; @@ -148,7 +149,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. */ public boolean isInTree(T element) { @@ -159,9 +160,9 @@ 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(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) { if (linearizationMethod == null) { 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 d647742..04765b4 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 @@ -11,24 +11,24 @@ 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 */ - protected T data; + protected T data; /** * Whether this node is soft-deleted or not */ - protected boolean isDeleted; + protected boolean isDeleted; /** * 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(T element) { data = element; @@ -72,14 +72,14 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> { } switch (treeWalker.walk(data)) { - case SUCCESS: - return true; - // We don't have any children to care about - case FAILURE: - case LEFT: - case RIGHT: - default: - return false; + case SUCCESS: + return true; + // We don't have any children to care about + case FAILURE: + case LEFT: + case RIGHT: + default: + return false; } } 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 fa3add0..46a89f2 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 @@ -16,31 +16,30 @@ 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 */ - private ITreePart<T> left; + private ITreePart<T> left; /* * The right child of this node */ - private ITreePart<T> right; + private ITreePart<T> right; /** * 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(T element, ITreePart<T> lft, - ITreePart<T> rght) { + public BinarySearchTreeNode(T element, ITreePart<T> lft, ITreePart<T> rght) { super(element); this.left = lft; this.right = rght; @@ -53,29 +52,29 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { } switch (comparator.compare(data, element)) { - case -1: - if (left == null) { - left = new BinarySearchTreeNode<>(element, null, null); - } else { - left.add(element, comparator); - } - break; - case 0: - if (isDeleted) { - isDeleted = false; - } else { - throw new IllegalArgumentException("Can't add duplicate values"); - } - break; - case 1: - if (right == null) { - right = new BinarySearchTreeNode<>(element, null, null); - } else { - right.add(element, comparator); - } - break; - default: - throw new IllegalStateException("Error: Comparator yielded invalid value"); + case -1: + if (left == null) { + left = new BinarySearchTreeNode<>(element, null, null); + } else { + left.add(element, comparator); + } + break; + case 0: + if (isDeleted) { + isDeleted = false; + } else { + throw new IllegalArgumentException("Can't add duplicate values"); + } + break; + case 1: + if (right == null) { + right = new BinarySearchTreeNode<>(element, null, null); + } else { + right.add(element, comparator); + } + break; + default: + throw new IllegalStateException("Error: Comparator yielded invalid value"); } } @@ -118,14 +117,14 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { return directedWalk(currentElement -> { switch (comparator.compare(element, currentElement)) { - case -1: - return LEFT; - case 0: - return isDeleted ? FAILURE : SUCCESS; - case 1: - return RIGHT; - default: - return FAILURE; + case -1: + return LEFT; + case 0: + return isDeleted ? FAILURE : SUCCESS; + case 1: + return RIGHT; + default: + return FAILURE; } }); } @@ -138,15 +137,15 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { directedWalk(currentElement -> { switch (comparator.compare(data, element)) { - case -1: - return left == null ? FAILURE : LEFT; - case 0: - isDeleted = true; - return FAILURE; - case 1: - return right == null ? FAILURE : RIGHT; - default: - return FAILURE; + case -1: + return left == null ? FAILURE : LEFT; + case 0: + isDeleted = true; + return FAILURE; + case 1: + return right == null ? FAILURE : RIGHT; + default: + return FAILURE; } }); } @@ -158,16 +157,16 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { } switch (treeWalker.walk(data)) { - case SUCCESS: - return true; - case LEFT: - return left.directedWalk(treeWalker); - case RIGHT: - return right.directedWalk(treeWalker); - case FAILURE: - return false; - default: - return false; + case SUCCESS: + return true; + case LEFT: + return left.directedWalk(treeWalker); + case RIGHT: + return right.directedWalk(treeWalker); + case FAILURE: + return false; + default: + return false; } } @@ -180,20 +179,19 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { } switch (linearizationMethod) { - case PREORDER: - return preorderTraverse(linearizationMethod, traversalPredicate); - case INORDER: - return inorderTraverse(linearizationMethod, traversalPredicate); - case POSTORDER: - return postorderTraverse(linearizationMethod, traversalPredicate); - default: - throw new IllegalArgumentException( - "Passed an incorrect TreeLinearizationMethod " - + linearizationMethod + ". WAT"); + case PREORDER: + return preorderTraverse(linearizationMethod, traversalPredicate); + case INORDER: + return inorderTraverse(linearizationMethod, traversalPredicate); + case POSTORDER: + return postorderTraverse(linearizationMethod, traversalPredicate); + default: + throw new IllegalArgumentException( + "Passed an incorrect TreeLinearizationMethod " + linearizationMethod + ". WAT"); } } - private boolean inorderTraverse( TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) { + private boolean inorderTraverse(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) { if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) { return false; } @@ -209,7 +207,8 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { return true; } - private boolean postorderTraverse(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) { + private boolean postorderTraverse(TreeLinearizationMethod linearizationMethod, + Predicate<T> traversalPredicate) { if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) { return false; } @@ -254,7 +253,8 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { return nodeSuccesfullyTraversed; } - private boolean traverseLeftBranch(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) { + private boolean traverseLeftBranch(TreeLinearizationMethod linearizationMethod, + Predicate<T> traversalPredicate) { boolean leftSuccesfullyTraversed; if (left == null) { @@ -266,7 +266,8 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { return leftSuccesfullyTraversed; } - private boolean traverseRightBranch(TreeLinearizationMethod linearizationMethod, Predicate<T> traversalPredicate) { + private boolean traverseRightBranch(TreeLinearizationMethod linearizationMethod, + Predicate<T> traversalPredicate) { boolean rightSuccesfullyTraversed; if (right == null) { 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 3f12fb6..e68bef6 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 @@ -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> { @@ -22,7 +22,8 @@ public interface DirectedWalkFunction<T> { */ FAILURE, /** - * Specifies that the function wants to move left in the tree next. + * Specifies that the function wants to move left in the tree + * next. */ LEFT, /** @@ -41,7 +42,7 @@ 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. */ public DirectedWalkResult walk(T element); 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 c574196..c648001 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 @@ -11,17 +11,17 @@ 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); @@ -30,25 +30,25 @@ public interface ITreePart<T> { * 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. */ - public <E> E collapse(Function<T, E> nodeCollapser, - BiFunction<E, E, E> branchCollapser); + public <E> E collapse(Function<T, E> nodeCollapser, BiFunction<E, E, E> branchCollapser); /** * 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. */ @@ -65,9 +65,9 @@ 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); @@ -75,7 +75,8 @@ 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. */ public boolean directedWalk(DirectedWalkFunction<T> walker); @@ -85,12 +86,11 @@ 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 */ - public boolean forEach(TreeLinearizationMethod linearizationMethod, - Predicate<T> predicate); + public boolean forEach(TreeLinearizationMethod linearizationMethod, Predicate<T> 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 eedb189..f7d6280 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 @@ -8,8 +8,8 @@ package bjc.utils.funcdata.bst; */ public enum TreeLinearizationMethod { /** - * Visit the left side of this tree part, the tree part itself, and - * then the right part. + * Visit the left side of this tree part, the tree part itself, and then + * the right part. */ INORDER, /** @@ -18,8 +18,8 @@ public enum TreeLinearizationMethod { */ POSTORDER, /** - * Visit the tree part itself, then the left side of tthis tree part - * and then the right part. + * Visit the tree part itself, then the left side of tthis tree part and + * then the right part. */ PREORDER }
\ No newline at end of file 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 a8f27c6..fa69f31 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 @@ -7,9 +7,9 @@ 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> { @@ -18,44 +18,31 @@ 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 */ - public default <OldLeft, OldRight, NewLeft, - NewRight> Function<Bifunctor<OldLeft, OldRight>, - Bifunctor<NewLeft, NewRight>> bimap( - Function<OldLeft, NewLeft> leftFunc, - Function<OldRight, NewRight> rightFunc) { - Function<Bifunctor<OldLeft, OldRight>, - Bifunctor<NewLeft, NewRight>> bimappedFunc = (argPair) -> { - Function<Bifunctor<OldLeft, OldRight>, - Bifunctor<NewLeft, - OldRight>> leftMapper = argPair.< - OldLeft, OldRight, - NewLeft> fmapLeft(leftFunc); + public default <OldLeft, OldRight, NewLeft, NewRight> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, NewRight>> bimap( + Function<OldLeft, NewLeft> leftFunc, Function<OldRight, NewRight> rightFunc) { + Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, NewRight>> bimappedFunc = (argPair) -> { + Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, OldRight>> leftMapper = argPair + .<OldLeft, OldRight, NewLeft>fmapLeft(leftFunc); - Bifunctor<NewLeft, - OldRight> leftMappedFunctor = leftMapper - .apply(argPair); - Function<Bifunctor<NewLeft, OldRight>, - Bifunctor<NewLeft, - NewRight>> rightMapper = leftMappedFunctor - .<NewLeft, OldRight, - NewRight> fmapRight( - rightFunc); + Bifunctor<NewLeft, OldRight> leftMappedFunctor = leftMapper.apply(argPair); + Function<Bifunctor<NewLeft, OldRight>, Bifunctor<NewLeft, NewRight>> rightMapper = leftMappedFunctor + .<NewLeft, OldRight, NewRight>fmapRight(rightFunc); - return rightMapper.apply(leftMappedFunctor); - }; + return rightMapper.apply(leftMappedFunctor); + }; return bimappedFunc; } @@ -64,40 +51,35 @@ 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 */ - public <OldLeft, OldRight, - NewLeft> Function<Bifunctor<OldLeft, OldRight>, - Bifunctor<NewLeft, OldRight>> fmapLeft( - Function<OldLeft, NewLeft> func); + public <OldLeft, OldRight, NewLeft> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<NewLeft, OldRight>> fmapLeft( + Function<OldLeft, NewLeft> func); /** * 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 - * @return The function lifted to work over the right side of - * bifunctors + * 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 */ - public <OldLeft, OldRight, - NewRight> Function<Bifunctor<OldLeft, OldRight>, - Bifunctor<OldLeft, NewRight>> fmapRight( - Function<OldRight, NewRight> func); + public <OldLeft, OldRight, NewRight> Function<Bifunctor<OldLeft, OldRight>, Bifunctor<OldLeft, NewRight>> fmapRight( + Function<OldRight, NewRight> func); /** * Get the value contained on the left of this bifunctor 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 9749d95..a5007f1 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 @@ -8,28 +8,27 @@ import java.util.function.Function; * * @author ben * @param <ContainedType> - * The value inside the functor + * The value inside the functor */ 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. + * 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 + * 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 */ - public <ArgType, ReturnType> - Function<Functor<ArgType>, Functor<ReturnType>> - fmap(Function<ArgType, ReturnType> func); + public <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> fmap( + Function<ArgType, ReturnType> func); /** * Retrieve the thing inside this functor |
