diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-09-28 13:44:04 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-09-28 13:44:04 -0400 |
| commit | f7a10e0e57d6f0ea83643c3d5763ff405af73337 (patch) | |
| tree | 7a56cbf7e5a8b6fa738d2cf469a86eea14d5d89a /BJC-Utils2/src/main/java/bjc/utils/funcdata | |
| parent | ba0a3f53a88842a94ea6a1a6d45f61416b593e47 (diff) | |
Formatting pass
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata')
11 files changed, 92 insertions, 70 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 4d50c56..0a2ee39 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java @@ -18,6 +18,11 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { } @Override + public void clear() { + store.clear(); + } + + @Override public boolean containsKey(KeyType key) { if (store.containsKey(key)) { return true; @@ -92,9 +97,4 @@ class ExtendedMap<KeyType, ValueType> implements IMap<KeyType, ValueType> { return ListUtils.mergeLists(store.valueList(), delegate.valueList()); } - - @Override - public void clear() { - store.clear(); - } } 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 590ed1d..b902207 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -180,9 +180,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 = wrappedList - .iterator(); leftIterator.hasNext() - && rightIterator.hasNext();) { + for (Iterator<E> leftIterator = wrappedList.iterator(); + leftIterator.hasNext() && rightIterator.hasNext();) { // Add the transformed items to the result list E leftVal = leftIterator.next(); T rightVal = rightIterator.next(); 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 ce64519..dfe02dc 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java @@ -60,6 +60,11 @@ public class FunctionalMap<KeyType, ValueType> wrappedMap = wrap; } + @Override + public void clear() { + wrappedMap.clear(); + } + /* * (non-Javadoc) * @@ -175,9 +180,4 @@ public class FunctionalMap<KeyType, ValueType> return values; } - - @Override - public void clear() { - wrappedMap.clear(); - } }
\ No newline at end of file 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 e446b64..47acf1a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java @@ -62,8 +62,8 @@ public interface IList<ContainedType> { */ public default <StateType, ReducedType> ReducedType collect( Collector<ContainedType, StateType, ReducedType> collector) { - BiConsumer<StateType, ContainedType> accumulator = collector - .accumulator(); + BiConsumer<StateType, + ContainedType> accumulator = collector.accumulator(); return reduceAux(collector.supplier().get(), (value, state) -> { accumulator.accept(state, value); @@ -92,8 +92,8 @@ public interface IList<ContainedType> { * @return A new list containing the merged pairs of lists. */ <OtherType, CombinedType> IList<CombinedType> combineWith( - IList<OtherType> rightList, - BiFunction<ContainedType, OtherType, CombinedType> itemCombiner); + IList<OtherType> rightList, BiFunction<ContainedType, + OtherType, CombinedType> itemCombiner); /** * Check if the list contains the specified item @@ -261,7 +261,8 @@ public interface IList<ContainedType> { * its final state. */ <StateType, ReducedType> ReducedType reduceAux(StateType initialValue, - BiFunction<ContainedType, StateType, StateType> stateAccumulator, + BiFunction<ContainedType, StateType, + StateType> stateAccumulator, Function<StateType, ReducedType> resultTransformer); /** 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 4fb7c2b..8522058 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java @@ -17,6 +17,11 @@ import java.util.function.Function; */ public interface IMap<KeyType, ValueType> { /** + * Delete all the values in the map + */ + void clear(); + + /** * Check if this map contains the specified key * * @param key @@ -68,6 +73,16 @@ public interface IMap<KeyType, ValueType> { */ ValueType get(KeyType key); + default ValueType getOrDefault(KeyType key, ValueType defaultValue) { + try { + return get(key); + } catch (IllegalArgumentException iaex) { + // We don't care about this, because it indicates a key is + // missing + return defaultValue; + } + } + /** * Get the number of entries in this map * @@ -132,19 +147,4 @@ public interface IMap<KeyType, ValueType> { * @return A list of values in this map */ IList<ValueType> valueList(); - - /** - * Delete all the values in the map - */ - void clear(); - - default ValueType getOrDefault(KeyType key, ValueType defaultValue) { - try { - return get(key); - } catch (IllegalArgumentException iaex) { - // We don't care about this, because it indicates a key is - // missing - return defaultValue; - } - } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java index e0c63e3..c773f4e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java @@ -43,7 +43,8 @@ public interface ITree<ContainedType> { */ public <NewType, ReturnedType> ReturnedType collapse( Function<ContainedType, NewType> leafTransform, - Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser, + Function<ContainedType, + Function<IList<NewType>, NewType>> nodeCollapser, Function<NewType, ReturnedType> resultTransformer); /** @@ -128,7 +129,8 @@ public interface ITree<ContainedType> { * @return The tree with the transform applied to picked subtrees */ public ITree<ContainedType> topDownTransform( - Function<ContainedType, TopDownTransformResult> transformPicker, + Function<ContainedType, + TopDownTransformResult> transformPicker, UnaryOperator<ITree<ContainedType>> transformer); /** 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 cc60dab..d43e8d5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java @@ -28,6 +28,11 @@ final class TransformedValueMap<OldKey, OldValue, NewValue> } @Override + public void clear() { + mapToTransform.clear(); + } + + @Override public boolean containsKey(OldKey key) { return mapToTransform.containsKey(key); } @@ -97,9 +102,4 @@ final class TransformedValueMap<OldKey, OldValue, NewValue> public IList<NewValue> valueList() { return mapToTransform.valueList().map(transformer); } - - @Override - public void clear() { - mapToTransform.clear(); - } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java index 77b5673..68a0ae1 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java @@ -95,7 +95,8 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public <NewType, ReturnedType> ReturnedType collapse( Function<ContainedType, NewType> leafTransform, - Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser, + Function<ContainedType, + Function<IList<NewType>, NewType>> nodeCollapser, Function<NewType, ReturnedType> resultTransformer) { return resultTransformer @@ -129,16 +130,17 @@ public class Tree<ContainedType> implements ITree<ContainedType> { protected <NewType> NewType internalCollapse( Function<ContainedType, NewType> leafTransform, - Function<ContainedType, Function<IList<NewType>, NewType>> nodeCollapser) { + Function<ContainedType, + Function<IList<NewType>, NewType>> nodeCollapser) { if (hasChildren) { - Function<IList<NewType>, NewType> nodeTransformer = nodeCollapser - .apply(data); + Function<IList<NewType>, + NewType> nodeTransformer = nodeCollapser.apply(data); - @SuppressWarnings("unchecked") - IList<NewType> collapsedChildren = (IList<NewType>) children.map((child) -> { - return child.collapse(leafTransform, nodeCollapser, - (subTreeVal) -> subTreeVal); - }); + IList<NewType> collapsedChildren = (IList<NewType>) children + .map((child) -> { + return child.collapse(leafTransform, nodeCollapser, + (subTreeVal) -> subTreeVal); + }); return nodeTransformer.apply(collapsedChildren); } @@ -195,7 +197,8 @@ public class Tree<ContainedType> implements ITree<ContainedType> { @Override public ITree<ContainedType> topDownTransform( - Function<ContainedType, TopDownTransformResult> transformPicker, + Function<ContainedType, + TopDownTransformResult> transformPicker, UnaryOperator<ITree<ContainedType>> transformer) { TopDownTransformResult transformResult = transformPicker .apply(data); diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java index a6d08a2..9817f91 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 @@ -81,7 +81,8 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { rightBranch.add(element, comparator); } default: - throw new IllegalStateException("Error: Comparator yielded invalid value"); + throw new IllegalStateException( + "Error: Comparator yielded invalid value"); } } 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 d3ebdac..a8f27c6 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 @@ -31,21 +31,31 @@ public interface Bifunctor<LeftType, RightType> { * 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,8 +74,10 @@ public interface Bifunctor<LeftType, RightType> { * 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 @@ -82,8 +94,10 @@ public interface Bifunctor<LeftType, RightType> { * @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 76f48e2..10cfffe 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 @@ -27,8 +27,10 @@ public interface Functor<ContainedType> { * @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 |
