diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-06 13:50:00 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-06 13:50:00 -0400 |
| commit | 79d3a4a47cbc1fcf17c77c6fc12ff826a3077bac (patch) | |
| tree | a69e533c558326d583b3aee891fc815208c7b650 /BJC-Utils2/src/main/java/bjc/utils/funcdata | |
| parent | 4355418164c44170cfb329fcbb7e6f1358c0e314 (diff) | |
Minor bugfixes/changes, as well as beginnings of CLI systems
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata')
4 files changed, 45 insertions, 46 deletions
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 ff02515..c680879 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -207,8 +207,8 @@ public class FunctionalList<E> implements Cloneable { // Get the iterator for the other list Iterator<T> rightIterator = rightList.toIterable().iterator(); - for (Iterator<E> leftIterator = - wrappedList.iterator(); leftIterator.hasNext() + for (Iterator<E> leftIterator = wrappedList + .iterator(); leftIterator.hasNext() && rightIterator.hasNext();) { // Add the transformed items to the result list E leftVal = leftIterator.next(); @@ -258,18 +258,18 @@ public class FunctionalList<E> implements Cloneable { * @return A new list containing the flattened results of applying the * provided function. */ - public <T> FunctionalList<T> - flatMap(Function<E, FunctionalList<T>> elementExpander) { + public <T> FunctionalList<T> flatMap( + Function<E, FunctionalList<T>> elementExpander) { if (elementExpander == null) { throw new NullPointerException("Expander must not be null"); } - FunctionalList<T> returnedList = - new FunctionalList<>(this.wrappedList.size()); + FunctionalList<T> returnedList = new FunctionalList<>( + this.wrappedList.size()); forEach(element -> { - FunctionalList<T> expandedElement = - elementExpander.apply(element); + FunctionalList<T> expandedElement = elementExpander + .apply(element); if (expandedElement == null) { throw new NullPointerException( @@ -400,8 +400,8 @@ public class FunctionalList<E> implements Cloneable { throw new NullPointerException("Transformer must be not null"); } - FunctionalList<T> returnedList = - new FunctionalList<>(this.wrappedList.size()); + FunctionalList<T> returnedList = new FunctionalList<>( + this.wrappedList.size()); forEach(element -> { // Add the transformed item to the result @@ -422,8 +422,8 @@ public class FunctionalList<E> implements Cloneable { * @return A list containing pairs of this element and the specified * list */ - public <T> FunctionalList<Pair<E, T>> - pairWith(FunctionalList<T> rightList) { + public <T> FunctionalList<Pair<E, T>> pairWith( + FunctionalList<T> rightList) { return combineWith(rightList, Pair<E, T>::new); } @@ -434,8 +434,8 @@ public class FunctionalList<E> implements Cloneable { * The size of elements to put into each one of the sublists * @return A list partitioned into partitions of size nPerPart */ - public FunctionalList<FunctionalList<E>> - partition(int numberPerPartition) { + public FunctionalList<FunctionalList<E>> partition( + int numberPerPartition) { if (numberPerPartition < 1 || numberPerPartition > wrappedList.size()) { throw new IllegalArgumentException("" + numberPerPartition @@ -443,12 +443,11 @@ public class FunctionalList<E> implements Cloneable { + wrappedList.size()); } - FunctionalList<FunctionalList<E>> returnedList = - new FunctionalList<>(); + FunctionalList<FunctionalList<E>> returnedList = new FunctionalList<>(); // The current partition being filled - GenHolder<FunctionalList<E>> currentPartition = - new GenHolder<>(new FunctionalList<>()); + GenHolder<FunctionalList<E>> currentPartition = new GenHolder<>( + new FunctionalList<>()); this.forEach((element) -> { if (isPartitionFull(numberPerPartition, currentPartition)) { @@ -593,10 +592,10 @@ public class FunctionalList<E> implements Cloneable { if (foundIndex >= 0) { // We found a matching element return wrappedList.get(foundIndex); - } else { - // We didn't find an element - return null; } + + // We didn't find an element + return null; } /** 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 f1d4cc6..0453988 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java @@ -118,12 +118,12 @@ public class FunctionalMap<K, V> { throw new NullPointerException("Key must not be null"); } - if (wrappedMap.containsKey(key)) { - return wrappedMap.get(key); - } else { + if (!wrappedMap.containsKey(key)) { throw new IllegalArgumentException( "Key " + key + " is not present in the map"); } + + return wrappedMap.get(key); } /** @@ -139,8 +139,8 @@ public class FunctionalMap<K, V> { * The function to use to transform values * @return The map where each value will be transformed after lookup */ - public <V2> FunctionalMap<K, V2> - mapValues(Function<V, V2> transformer) { + public <V2> FunctionalMap<K, V2> mapValues( + Function<V, V2> 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 386b732..9ef59fb 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java @@ -120,10 +120,10 @@ public class FunctionalStringTokenizer { if (input.hasMoreTokens()) { // Return the next availible token return input.nextToken(); - } else { - // Return no token - return null; } + + // Return no token + return null; } /** @@ -137,8 +137,8 @@ public class FunctionalStringTokenizer { * The function to use to convert tokens. * @return A list containing all of the converted tokens. */ - public <E> FunctionalList<E> - toList(Function<String, E> tokenTransformer) { + public <E> FunctionalList<E> toList( + Function<String, E> tokenTransformer) { if (tokenTransformer == null) { throw new NullPointerException("Transformer must not be null"); } 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 09a4912..58e07f7 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 @@ -90,8 +90,8 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { E collapsedNode = nodeCollapser.apply(data); if (leftBranch != null) { - E collapsedLeftBranch = - leftBranch.collapse(nodeCollapser, branchCollapser); + E collapsedLeftBranch = leftBranch.collapse(nodeCollapser, + branchCollapser); if (rightBranch != null) { E collapsedRightBranch = rightBranch .collapse(nodeCollapser, branchCollapser); @@ -101,21 +101,21 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { return branchCollapser.apply(collapsedNode, collapsedBranches); - } else { - return branchCollapser.apply(collapsedNode, - collapsedLeftBranch); } - } else { - if (rightBranch != null) { - E collapsedRightBranch = rightBranch - .collapse(nodeCollapser, branchCollapser); - return branchCollapser.apply(collapsedNode, - collapsedRightBranch); - } else { - return collapsedNode; - } + return branchCollapser.apply(collapsedNode, + collapsedLeftBranch); + } + + if (rightBranch != null) { + E collapsedRightBranch = rightBranch.collapse(nodeCollapser, + branchCollapser); + + return branchCollapser.apply(collapsedNode, + collapsedRightBranch); } + + return collapsedNode; } @Override @@ -188,7 +188,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> { } else if (traversalPredicate == null) { throw new NullPointerException("Predicate must not be null"); } - + switch (linearizationMethod) { case PREORDER: return preorderTraverse(linearizationMethod, |
