From 42f7d379a430aaf2fad169f0170de04072b08b10 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Fri, 22 Apr 2016 14:48:04 -0400 Subject: Formatting changes --- .../main/java/bjc/utils/funcdata/ExtendedMap.java | 68 ++++++------ .../java/bjc/utils/funcdata/FunctionalList.java | 48 ++++----- .../java/bjc/utils/funcdata/FunctionalMap.java | 120 ++++++++++----------- .../utils/funcdata/FunctionalStringTokenizer.java | 36 +++---- .../java/bjc/utils/funcdata/IFunctionalList.java | 24 ++--- .../java/bjc/utils/funcdata/IFunctionalMap.java | 120 ++++++++++----------- .../bjc/utils/funcdata/TransformedValueMap.java | 64 +++++------ .../bjc/utils/funcdata/bst/BinarySearchTree.java | 34 +++--- 8 files changed, 257 insertions(+), 257 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata') 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 7e4c7fd..9776961 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ExtendedMap.java @@ -19,49 +19,47 @@ class ExtendedMap } @Override - public ValueType put(KeyType key, ValueType val) { - return store.put(key, val); - } - - @Override - public ValueType get(KeyType key) { + public boolean containsKey(KeyType key) { if (store.containsKey(key)) { - return store.get(key); + return true; } - return delegate.get(key); + return delegate.containsKey(key); } @Override - public IFunctionalMap mapValues( - Function transformer) { - return new TransformedValueMap<>(this, transformer); + public IFunctionalMap extend() { + return new ExtendedMap<>(this, new FunctionalMap<>()); } @Override - public boolean containsKey(KeyType key) { - if (store.containsKey(key)) { - return true; - } + public void forEach(BiConsumer action) { + store.forEach(action); - return delegate.containsKey(key); + delegate.forEach(action); } @Override - public IFunctionalList keyList() { - return ListUtils.mergeLists(store.keyList(), delegate.keyList()); + public void forEachKey(Consumer action) { + store.forEachKey(action); + + delegate.forEachKey(action); } @Override - public void forEach(BiConsumer action) { - store.forEach(action); + public void forEachValue(Consumer action) { + store.forEachValue(action); - delegate.forEach(action); + delegate.forEachValue(action); } @Override - public ValueType remove(KeyType key) { - return store.remove(key); + public ValueType get(KeyType key) { + if (store.containsKey(key)) { + return store.get(key); + } + + return delegate.get(key); } @Override @@ -70,17 +68,24 @@ class ExtendedMap } @Override - public void forEachKey(Consumer action) { - store.forEachKey(action); + public IFunctionalList keyList() { + return ListUtils.mergeLists(store.keyList(), delegate.keyList()); + } - delegate.forEachKey(action); + @Override + public IFunctionalMap mapValues( + Function transformer) { + return new TransformedValueMap<>(this, transformer); } @Override - public void forEachValue(Consumer action) { - store.forEachValue(action); + public ValueType put(KeyType key, ValueType val) { + return store.put(key, val); + } - delegate.forEachValue(action); + @Override + public ValueType remove(KeyType key) { + return store.remove(key); } @Override @@ -88,9 +93,4 @@ class ExtendedMap return ListUtils.mergeLists(store.valueList(), delegate.valueList()); } - - @Override - public IFunctionalMap extend() { - return new ExtendedMap<>(this, new FunctionalMap<>()); - } } 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 c8f2269..8579693 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -357,6 +357,15 @@ public class FunctionalList implements Cloneable, IFunctionalList { return wrappedList.isEmpty(); } + /* + * Check if a partition has room for another item + */ + private Boolean isPartitionFull(int numberPerPartition, + IHolder> currentPartition) { + return currentPartition.unwrap( + (partition) -> partition.getSize() >= numberPerPartition); + } + /* * (non-Javadoc) * @@ -432,15 +441,6 @@ public class FunctionalList implements Cloneable, IFunctionalList { return returnedList; } - /* - * Check if a partition has room for another item - */ - private Boolean isPartitionFull(int numberPerPartition, - IHolder> currentPartition) { - return currentPartition.unwrap( - (partition) -> partition.getSize() >= numberPerPartition); - } - /* * (non-Javadoc) * @@ -522,6 +522,11 @@ public class FunctionalList implements Cloneable, IFunctionalList { removeIf((element) -> element.equals(desiredElement)); } + @Override + public void reverse() { + Collections.reverse(wrappedList); + } + /* * (non-Javadoc) * @@ -553,6 +558,16 @@ public class FunctionalList implements Cloneable, IFunctionalList { Collections.sort(wrappedList, comparator); } + @Override + public IFunctionalList tail() { + return new FunctionalList<>(wrappedList.subList(1, getSize())); + } + + @Override + public E[] toArray(E[] arrType) { + return wrappedList.toArray(arrType); + } + /* * (non-Javadoc) * @@ -584,19 +599,4 @@ public class FunctionalList implements Cloneable, IFunctionalList { return sb.toString(); } - - @Override - public E[] toArray(E[] arrType) { - return wrappedList.toArray(arrType); - } - - @Override - public IFunctionalList tail() { - return new FunctionalList<>(wrappedList.subList(1, getSize())); - } - - @Override - public void reverse() { - Collections.reverse(wrappedList); - } } \ No newline at end of file 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 eaa425b..fb8bb81 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalMap.java @@ -29,20 +29,6 @@ public class FunctionalMap wrappedMap = new HashMap<>(); } - /** - * Create a new functional map wrapping the specified map - * - * @param wrap - * The map to wrap - */ - public FunctionalMap(Map wrap) { - if (wrap == null) { - throw new NullPointerException("Map to wrap must not be null"); - } - - wrappedMap = wrap; - } - /** * Create a new functional map with the specified entries * @@ -60,18 +46,48 @@ public class FunctionalMap } } + /** + * Create a new functional map wrapping the specified map + * + * @param wrap + * The map to wrap + */ + public FunctionalMap(Map wrap) { + if (wrap == null) { + throw new NullPointerException("Map to wrap must not be null"); + } + + wrappedMap = wrap; + } + /* * (non-Javadoc) * - * @see bjc.utils.funcdata.IFunctionalMap#put(K, V) + * @see bjc.utils.funcdata.IFunctionalMap#containsKey(K) */ @Override - public ValueType put(KeyType key, ValueType val) { - if (key == null) { - throw new NullPointerException("Key must not be null"); - } + public boolean containsKey(KeyType key) { + return wrappedMap.containsKey(key); + } - return wrappedMap.put(key, val); + @Override + public IFunctionalMap extend() { + return new ExtendedMap<>(this, new FunctionalMap<>()); + } + + @Override + public void forEach(BiConsumer action) { + wrappedMap.forEach(action); + } + + @Override + public void forEachKey(Consumer action) { + wrappedMap.keySet().forEach(action); + } + + @Override + public void forEachValue(Consumer action) { + wrappedMap.values().forEach(action); } /* @@ -93,6 +109,22 @@ public class FunctionalMap return wrappedMap.get(key); } + @Override + public int getSize() { + return wrappedMap.size(); + } + + @Override + public IFunctionalList keyList() { + FunctionalList keys = new FunctionalList<>(); + + wrappedMap.keySet().forEach((key) -> { + keys.add(key); + }); + + return keys; + } + /* * (non-Javadoc) * @@ -112,32 +144,15 @@ public class FunctionalMap /* * (non-Javadoc) * - * @see bjc.utils.funcdata.IFunctionalMap#containsKey(K) + * @see bjc.utils.funcdata.IFunctionalMap#put(K, V) */ @Override - public boolean containsKey(KeyType key) { - return wrappedMap.containsKey(key); - } - - @Override - public String toString() { - return wrappedMap.toString(); - } - - @Override - public IFunctionalList keyList() { - FunctionalList keys = new FunctionalList<>(); - - wrappedMap.keySet().forEach((key) -> { - keys.add(key); - }); - - return keys; - } + public ValueType put(KeyType key, ValueType val) { + if (key == null) { + throw new NullPointerException("Key must not be null"); + } - @Override - public void forEach(BiConsumer action) { - wrappedMap.forEach(action); + return wrappedMap.put(key, val); } @Override @@ -146,18 +161,8 @@ public class FunctionalMap } @Override - public int getSize() { - return wrappedMap.size(); - } - - @Override - public void forEachKey(Consumer action) { - wrappedMap.keySet().forEach(action); - } - - @Override - public void forEachValue(Consumer action) { - wrappedMap.values().forEach(action); + public String toString() { + return wrappedMap.toString(); } @Override @@ -170,9 +175,4 @@ public class FunctionalMap return values; } - - @Override - public IFunctionalMap extend() { - return new ExtendedMap<>(this, new FunctionalMap<>()); - } } \ No newline at end of file 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 0e2d199..aa6fca3 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java @@ -110,6 +110,15 @@ public class FunctionalStringTokenizer { return input; } + /** + * Check if this tokenizer has more tokens + * + * @return Whether or not this tokenizer has more tokens + */ + public boolean hasMoreTokens() { + return input.hasMoreTokens(); + } + /** * Return the next token from the tokenizer. Returns null if no more * tokens are available @@ -126,6 +135,15 @@ public class FunctionalStringTokenizer { return null; } + /** + * Convert this tokenizer into a list of strings + * + * @return This tokenizer, converted into a list of strings + */ + public IFunctionalList toList() { + return toList((String element) -> element); + } + /** * Convert the contents of this tokenizer into a list. Consumes all of * the input from this tokenizer. @@ -154,22 +172,4 @@ public class FunctionalStringTokenizer { return returnList; } - - /** - * Convert this tokenizer into a list of strings - * - * @return This tokenizer, converted into a list of strings - */ - public IFunctionalList toList() { - return toList((String element) -> element); - } - - /** - * Check if this tokenizer has more tokens - * - * @return Whether or not this tokenizer has more tokens - */ - public boolean hasMoreTokens() { - return input.hasMoreTokens(); - } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java index 3358da0..91b2ba3 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java @@ -285,6 +285,11 @@ public interface IFunctionalList { */ void removeMatching(ContainedType desiredElement); + /** + * Reverse the contents of this list in place + */ + void reverse(); + /** * Perform a binary search for the specified key using the provided * means of comparing elements. Since this IS a binary search, the list @@ -310,6 +315,13 @@ public interface IFunctionalList { */ void sort(Comparator comparator); + /** + * Get the tail of this list (the list without the first element + * + * @return The list without the first element + */ + public IFunctionalList tail(); + /** * Convert this list into an array * @@ -325,16 +337,4 @@ public interface IFunctionalList { * @return An iterable view onto the list */ Iterable toIterable(); - - /** - * Get the tail of this list (the list without the first element - * - * @return The list without the first element - */ - public IFunctionalList tail(); - - /** - * Reverse the contents of this list in place - */ - void reverse(); } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java index 0c96a9f..8a54246 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalMap.java @@ -18,21 +18,45 @@ import java.util.function.Function; public interface IFunctionalMap { /** - * Add an entry to the map + * Check if this map contains the specified key * * @param key - * The key to put the value under - * @param val - * 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. + * The key to check + * @return Whether or not the map contains the key + */ + boolean containsKey(KeyType key); + + /** + * Extends this map, creating a new map that will delegate queries to + * the map, but store any added values itself * - * @throws UnsupportedOperationException - * if the map implementation doesn't support modifying the - * map + * @return An extended map */ - ValueType put(KeyType key, ValueType val); + IFunctionalMap extend(); + + /** + * Execute an action for each entry in the map + * + * @param action + * the action to execute for each entry in the map + */ + void forEach(BiConsumer action); + + /** + * Perform an action for each key in the map + * + * @param action + * The action to perform on each key in the map + */ + void forEachKey(Consumer action); + + /** + * Perform an action for each value in the map + * + * @param action + * The action to perform on each value in the map + */ + void forEachValue(Consumer action); /** * Get the value assigned to the given key @@ -45,6 +69,20 @@ public interface IFunctionalMap { */ ValueType get(KeyType key); + /** + * Get the number of entries in this map + * + * @return The number of entries in this map + */ + int getSize(); + + /** + * Get a list of all the keys in this map + * + * @return A list of all the keys in this map + */ + IFunctionalList keyList(); + /** * Transform the values returned by this map. * @@ -62,28 +100,21 @@ public interface IFunctionalMap { Function transformer); /** - * Check if this map contains the specified key + * Add an entry to the map * * @param key - * The key to check - * @return Whether or not the map contains the key - */ - boolean containsKey(KeyType key); - - /** - * Get a list of all the keys in this map - * - * @return A list of all the keys in this map - */ - IFunctionalList keyList(); - - /** - * Execute an action for each entry in the map + * The key to put the value under + * @param val + * 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. * - * @param action - * the action to execute for each entry in the map + * @throws UnsupportedOperationException + * if the map implementation doesn't support modifying the + * map */ - void forEach(BiConsumer action); + ValueType put(KeyType key, ValueType val); /** * Remove the value bound to the key @@ -97,41 +128,10 @@ public interface IFunctionalMap { */ ValueType remove(KeyType key); - /** - * Get the number of entries in this map - * - * @return The number of entries in this map - */ - int getSize(); - - /** - * Perform an action for each key in the map - * - * @param action - * The action to perform on each key in the map - */ - void forEachKey(Consumer action); - - /** - * Perform an action for each value in the map - * - * @param action - * The action to perform on each value in the map - */ - void forEachValue(Consumer action); - /** * Get a list of the values in this map * * @return A list of values in this map */ IFunctionalList valueList(); - - /** - * Extends this map, creating a new map that will delegate queries to - * the map, but store any added values itself - * - * @return An extended map - */ - IFunctionalMap extend(); } \ No newline at end of file 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 75557fa..1d52d82 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TransformedValueMap.java @@ -28,73 +28,73 @@ final class TransformedValueMap } @Override - public NewValue get(OldKey key) { - return transformer.apply(mapToTransform.get(key)); + public boolean containsKey(OldKey key) { + return mapToTransform.containsKey(key); } @Override - public boolean containsKey(OldKey key) { - return mapToTransform.containsKey(key); + public IFunctionalMap extend() { + return new ExtendedMap<>(this, new FunctionalMap<>()); } @Override - public String toString() { - return mapToTransform.toString(); + public void forEach(BiConsumer action) { + mapToTransform.forEach((key, val) -> { + action.accept(key, transformer.apply(val)); + }); } @Override - public NewValue put(OldKey key, NewValue val) { - throw new UnsupportedOperationException( - "Can't add items to transformed map"); + public void forEachKey(Consumer action) { + mapToTransform.forEachKey(action); } @Override - public IFunctionalMap mapValues( - Function transform) { - return new TransformedValueMap<>(this, transform); + public void forEachValue(Consumer action) { + mapToTransform.forEachValue((val) -> { + action.accept(transformer.apply(val)); + }); } @Override - public IFunctionalList keyList() { - return mapToTransform.keyList(); + public NewValue get(OldKey key) { + return transformer.apply(mapToTransform.get(key)); } @Override - public void forEach(BiConsumer action) { - mapToTransform.forEach((key, val) -> { - action.accept(key, transformer.apply(val)); - }); + public int getSize() { + return mapToTransform.getSize(); } @Override - public NewValue remove(OldKey key) { - return transformer.apply(mapToTransform.remove(key)); + public IFunctionalList keyList() { + return mapToTransform.keyList(); } @Override - public int getSize() { - return mapToTransform.getSize(); + public IFunctionalMap mapValues( + Function transform) { + return new TransformedValueMap<>(this, transform); } @Override - public void forEachKey(Consumer action) { - mapToTransform.forEachKey(action); + public NewValue put(OldKey key, NewValue val) { + throw new UnsupportedOperationException( + "Can't add items to transformed map"); } @Override - public void forEachValue(Consumer action) { - mapToTransform.forEachValue((val) -> { - action.accept(transformer.apply(val)); - }); + public NewValue remove(OldKey key) { + return transformer.apply(mapToTransform.remove(key)); } @Override - public IFunctionalList valueList() { - return mapToTransform.valueList().map(transformer); + public String toString() { + return mapToTransform.toString(); } @Override - public IFunctionalMap extend() { - return new ExtendedMap<>(this, new FunctionalMap<>()); + public IFunctionalList valueList() { + return mapToTransform.valueList().map(transformer); } } \ No newline at end of file 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 c147646..712f0e3 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 @@ -63,6 +63,23 @@ public class BinarySearchTree { } } + /** + * Check if an adjusted pivot falls with the bounds of a list + * + * @param elements + * The list to get bounds from + * @param pivot + * The pivot + * @param pivotAdjustment + * The distance from the pivot + * @return Whether the adjusted pivot is with the list + */ + private boolean adjustedPivotInBounds(IFunctionalList elements, + int pivot, int pivotAdjustment) { + return (pivot - pivotAdjustment) >= 0 + && (pivot + pivotAdjustment) < elements.getSize(); + } + /** * Balance the tree, and remove soft-deleted nodes for free. Takes O(N) * time, but also O(N) space. @@ -112,23 +129,6 @@ public class BinarySearchTree { } } - /** - * Check if an adjusted pivot falls with the bounds of a list - * - * @param elements - * The list to get bounds from - * @param pivot - * The pivot - * @param pivotAdjustment - * The distance from the pivot - * @return Whether the adjusted pivot is with the list - */ - private boolean adjustedPivotInBounds(IFunctionalList elements, - int pivot, int pivotAdjustment) { - return (pivot - pivotAdjustment) >= 0 - && (pivot + pivotAdjustment) < elements.getSize(); - } - /** * Soft-delete a node from the tree. Soft-deleted nodes stay in the * tree until trim()/balance() is invoked, and are not included in -- cgit v1.2.3