From 0017697b07ae999be0ffe9de8a9001aeb00c2002 Mon Sep 17 00:00:00 2001 From: Speiger Date: Sun, 25 Apr 2021 21:37:22 +0200 Subject: [PATCH] Adding more JavaDoc (fixing roughly 8k javadoc errors) -Added: JavaDocs to Map classes/constructors -Added: JavaDocs to the Maps Class --- build.gradle | 1 + .../templates/functions/Comparator.template | 4 + .../templates/functions/Consumer.template | 6 + .../functions/consumer/BiConsumer.template | 18 ++ .../functions/function/UnaryOperator.template | 13 ++ .../templates/lists/ArrayList.template | 2 - .../collections/templates/lists/List.template | 6 +- .../templates/lists/ListIterator.template | 4 + .../LinkedOpenCustomHashMap.template | 95 ++++++++ .../customHash/OpenCustomHashMap.template | 106 ++++++++- .../maps/impl/hash/LinkedOpenHashMap.template | 73 ++++++ .../maps/impl/hash/OpenHashMap.template | 82 +++++++ .../maps/impl/misc/ArrayMap.template | 59 +++++ .../templates/maps/impl/misc/EnumMap.template | 19 ++ .../maps/impl/tree/AVLTreeMap.template | 92 +++++++- .../maps/impl/tree/RBTreeMap.template | 92 +++++++- .../templates/maps/interfaces/Map.template | 4 +- .../templates/queues/PriorityQueue.template | 6 + .../templates/utils/Iterators.template | 6 +- .../templates/utils/maps/Maps.template | 220 +++++++++++++++++- .../src/collections/utils/SanityChecks.java | 2 +- .../speiger/src/collections/utils/Stack.java | 2 +- 22 files changed, 877 insertions(+), 35 deletions(-) diff --git a/build.gradle b/build.gradle index 6859490f..e6124443 100644 --- a/build.gradle +++ b/build.gradle @@ -72,6 +72,7 @@ task srcJar(type: Jar) { } javadoc.failOnError = false +javadoc.options.memberLevel = JavadocMemberLevel.PUBLIC //javadoc.options.showAll() javadoc.options.quiet() diff --git a/src/builder/resources/speiger/assets/collections/templates/functions/Comparator.template b/src/builder/resources/speiger/assets/collections/templates/functions/Comparator.template index 344e069d..ec8ccde5 100644 --- a/src/builder/resources/speiger/assets/collections/templates/functions/Comparator.template +++ b/src/builder/resources/speiger/assets/collections/templates/functions/Comparator.template @@ -38,10 +38,14 @@ public interface COMPARATOR extends Comparator return (K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V)); } + @Override public default COMPARATOR reversed() { return new Reversed(this); } + /** + * A Type Specific Reversed Comparator to reduce boxing/unboxing + */ static class Reversed implements COMPARATOR { COMPARATOR original; diff --git a/src/builder/resources/speiger/assets/collections/templates/functions/Consumer.template b/src/builder/resources/speiger/assets/collections/templates/functions/Consumer.template index 42421f02..806c9288 100644 --- a/src/builder/resources/speiger/assets/collections/templates/functions/Consumer.template +++ b/src/builder/resources/speiger/assets/collections/templates/functions/Consumer.template @@ -20,6 +20,12 @@ public interface CONSUMER extends Consumer */ void accept(KEY_TYPE t); + /** + * Type Specific sequencing method to reduce boxing/unboxing. + * @param after a operation that should be performed afterwards + * @return a sequenced consumer that does 2 operations + * @throws NullPointerException if after is null + */ public default CONSUMER andThen(CONSUMER after) { Objects.requireNonNull(after); return T -> {accept(T); after.accept(T);}; diff --git a/src/builder/resources/speiger/assets/collections/templates/functions/consumer/BiConsumer.template b/src/builder/resources/speiger/assets/collections/templates/functions/consumer/BiConsumer.template index bd0bdfd0..3716b13b 100644 --- a/src/builder/resources/speiger/assets/collections/templates/functions/consumer/BiConsumer.template +++ b/src/builder/resources/speiger/assets/collections/templates/functions/consumer/BiConsumer.template @@ -3,10 +3,28 @@ package speiger.src.collections.PACKAGE.functions.consumer; import java.util.Objects; import java.util.function.BiConsumer; +/** + * A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has. + * @Type(T) + * @ValueType(V) + */ public interface BI_CONSUMER KEY_VALUE_GENERIC_TYPE extends BiConsumer { + /** + * A Type Specific operation method to reduce boxing/unboxing + * Performs this operation on the given arguments. + * + * @param k the first input argument + * @param v the second input argument + */ void accept(KEY_TYPE k, VALUE_TYPE v); + /** + * Type Specific sequencing method to reduce boxing/unboxing. + * @param after a operation that should be performed afterwards + * @return a sequenced biconsumer that does 2 operations + * @throws NullPointerException if after is null + */ public default BI_CONSUMER KEY_VALUE_GENERIC_TYPE andThen(BI_CONSUMER KEY_VALUE_GENERIC_TYPE after) { Objects.requireNonNull(after); return (K, V) -> {accept(K, V); after.accept(K, V);}; diff --git a/src/builder/resources/speiger/assets/collections/templates/functions/function/UnaryOperator.template b/src/builder/resources/speiger/assets/collections/templates/functions/function/UnaryOperator.template index 14750b50..3556157b 100644 --- a/src/builder/resources/speiger/assets/collections/templates/functions/function/UnaryOperator.template +++ b/src/builder/resources/speiger/assets/collections/templates/functions/function/UnaryOperator.template @@ -2,6 +2,11 @@ package speiger.src.collections.PACKAGE.functions.function; import java.util.function.BiFunction; +/** + * A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing + * @Type(T) + * @ValueType(V) + */ #if !SAME_TYPE || TYPE_BOOLEAN || !JDK_TYPE public interface UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE extends BiFunction #else @@ -17,6 +22,14 @@ public interface UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE extends BiFunction c) { @@ -452,7 +451,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE * Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort * @param c the sorter of the elements, can be null * @see java.util.List#sort(Comparator) - * @see ARRAYS#unstableSort(KEY_TYPE[], Comparator) */ @Override public void unstableSort(Comparator c) { diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/List.template b/src/builder/resources/speiger/assets/collections/templates/lists/List.template index 66c6652e..ad2ae33f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/List.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/List.template @@ -20,6 +20,10 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.utils.SanityChecks; #endif +/** + * A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features + * @Type(T) + */ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List { #if !TYPE_OBJECT @@ -212,7 +216,6 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List /** * Sorts the elements specified by the Natural order either by using the Comparator or the elements * @see java.util.List#sort(Comparator) - * @see ARRAYS#stableSort(KEY_TYPE[], Comparator) */ @Override public default void sort(Comparator c) { @@ -230,7 +233,6 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List * Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort * @param c the sorter of the elements, can be null * @see java.util.List#sort(Comparator) - * @see ARRAYS#unstableSort(KEY_TYPE[], Comparator) */ public default void unstableSort(Comparator c) { KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY(); diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/ListIterator.template b/src/builder/resources/speiger/assets/collections/templates/lists/ListIterator.template index fa75da1a..528e6de7 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/ListIterator.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/ListIterator.template @@ -4,6 +4,10 @@ import java.util.ListIterator; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; +/** + * A Type Specific ListIterator that reduces boxing/unboxing + * @Type(T) + */ public interface LIST_ITERATOR KEY_GENERIC_TYPE extends ListIterator, BI_ITERATOR KEY_GENERIC_TYPE { #if !TYPE_OBJECT diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template index 5483a31b..6f42058f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template @@ -34,30 +34,79 @@ import speiger.src.collections.objects.sets.ObjectSet; #endif import speiger.src.collections.utils.HashUtil; +/** + * A Type Specific LinkedHashMap that allows for custom HashControl. That uses arrays to create links between nodes. + * For cases where Objects/primitive do not allow hashcoding this can be really useful and provide a lot of control. + * This implementation of SortedMap does not support SubMaps of any kind. It implements the interface due to sortability and first/last access + * @Type(T) + * @ValueType(V) + */ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE { + /** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */ protected transient long[] links; + /** The First Index in the Map */ protected int firstIndex = -1; + /** The Last Index in the Map */ protected int lastIndex = -1; + /** + * Default Constructor + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + */ public LINKED_CUSTOM_HASH_MAP(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(HashUtil.DEFAULT_MIN_CAPACITY, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * Constructor that defines the minimum capacity + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the minimum capacity is negative + */ public LINKED_CUSTOM_HASH_MAP(int minCapacity, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * Constructor that defines the minimum capacity and load factor + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the minimum capacity is negative + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_CUSTOM_HASH_MAP(int minCapacity, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { super(minCapacity, loadFactor, strategy); links = new long[nullIndex + 1]; } #if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the keys and values do not match in lenght + */ public LINKED_CUSTOM_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the keys and values do not match in lenght + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_CUSTOM_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(keys.length, loadFactor, strategy); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); @@ -65,29 +114,75 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M } #endif + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the keys and values do not match in lenght + */ public LINKED_CUSTOM_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the keys and values do not match in lenght + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_CUSTOM_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(keys.length, loadFactor, strategy); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); for(int i = 0,m=keys.length;i map, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(map, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * A Helper constructor that allows to create a Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_CUSTOM_HASH_MAP(Map map, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(map.size(), loadFactor, strategy); putAll(map); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + */ public LINKED_CUSTOM_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(map, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_CUSTOM_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(map.size(), loadFactor, strategy); putAll(map); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template index 4450dfb8..494cd3c4 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template @@ -31,31 +31,71 @@ import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.ObjectSet; import speiger.src.collections.utils.HashUtil; +/** + * A Type Specific HashMap that allows for custom HashControl. + * For cases where Objects/primitive do not allow hashcoding this can be really useful and provide a lot of control. + * @Type(T) + * @ValueType(V) + */ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE { + /** The Backing keys array */ protected transient KEY_TYPE[] keys; + /** The Backing values array */ protected transient VALUE_TYPE[] values; + /** If a null value is present */ protected transient boolean containsNull; + /** Minimum array size the HashMap will be */ protected transient int minCapacity; + /** Index of the Null Value */ protected transient int nullIndex; + /** Maximum amount of Values that can be stored before the array gets expanded usually 75% */ protected transient int maxFill; + /** Max Index that is allowed to be searched through nullIndex - 1 */ protected transient int mask; + /** EntrySet cache */ protected transient FastEntrySet KEY_VALUE_GENERIC_TYPE entrySet; + /** KeySet cache */ protected transient SET KEY_GENERIC_TYPE keySet; + /** Values cache */ protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC; + /** Amount of Elements stored in the HashMap */ protected int size; + /** How full the Arrays are allowed to get before resize */ protected final float loadFactor; + /** Strategy that allows to control the Hash Generation and equals comparason */ protected final STRATEGY KEY_SUPER_GENERIC_TYPE strategy; - + + /** + * Default Contstructor + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + */ public CUSTOM_HASH_MAP(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(HashUtil.DEFAULT_MIN_CAPACITY, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * Constructor that defines the minimum capacity + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the minimum capacity is negative + */ public CUSTOM_HASH_MAP(int minCapacity, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * Constructor that defines the minimum capacity and load factor + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the minimum capacity is negative + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public CUSTOM_HASH_MAP(int minCapacity, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed"); if(loadFactor <= 0 || loadFactor >= 1F) throw new IllegalStateException("Load Factor is not between 0 and 1"); @@ -69,10 +109,28 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL } #if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the keys and values do not match in lenght + */ public CUSTOM_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the keys and values do not match in lenght + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public CUSTOM_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(keys.length, loadFactor, strategy); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); @@ -80,29 +138,75 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL } #endif + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the keys and values do not match in lenght + */ public CUSTOM_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the keys and values do not match in lenght + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public CUSTOM_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(keys.length, loadFactor, strategy); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); for(int i = 0,m=keys.length;i map, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(map, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * A Helper constructor that allows to create a Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public CUSTOM_HASH_MAP(Map map, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(map.size(), loadFactor, strategy); putAll(map); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + */ public CUSTOM_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(map, HashUtil.DEFAULT_LOAD_FACTOR, strategy); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param loadFactor the percentage of how full the backing array can be before they resize + * @param strategy the strategy that allows hash control. + * @throws NullPointerException if Strategy is null + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public CUSTOM_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) { this(map.size(), loadFactor, strategy); putAll(map); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template index 47433eba..54705664 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template @@ -36,30 +36,69 @@ import speiger.src.collections.objects.sets.ObjectSet; #endif import speiger.src.collections.utils.HashUtil; +/** + * A Type Specific LinkedHashMap implementation that uses specific arrays to create links between nodes to remove the wrapping of elements + * to greatly reduce memory usage. In Addition adding some helper methods to move around elements. + * This implementation of SortedMap does not support SubMaps of any kind. It implements the interface due to sortability and first/last access + * @Type(T) + * @ValueType(V) + */ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE { + /** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */ protected long[] links; + /** The First Index in the Map */ protected int firstIndex = -1; + /** The Last Index in the Map */ protected int lastIndex = -1; + /** + * Default Constructor + */ public LINKED_HASH_MAP() { this(HashUtil.DEFAULT_MIN_CAPACITY, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * Constructor that defines the minimum capacity + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @throws IllegalStateException if the minimum capacity is negative + */ public LINKED_HASH_MAP(int minCapacity) { this(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * Constructor that defines the minimum capacity and load factor + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the minimum capacity is negative + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_HASH_MAP(int minCapacity, float loadFactor) { super(minCapacity, loadFactor); links = new long[nullIndex + 1]; } #if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public LINKED_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the keys and values do not match in lenght + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, float loadFactor) { this(keys.length, loadFactor); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); @@ -67,29 +106,63 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G } #endif + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public LINKED_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) { this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the keys and values do not match in lenght + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, float loadFactor) { this(keys.length, loadFactor); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); for(int i = 0,m=keys.length;i map) { this(map, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * A Helper constructor that allows to create a Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_HASH_MAP(Map map, float loadFactor) { this(map.size(), loadFactor); putAll(map); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ public LINKED_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map) { this(map, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public LINKED_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, float loadFactor) { this(map.size(), loadFactor); putAll(map); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template index 40fbea3d..24c59734 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template @@ -30,30 +30,64 @@ import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.ObjectSet; import speiger.src.collections.utils.HashUtil; +/** + * A Type Specific Custom implementation of the HashMap + * Instead of using Wrapper Object Arrays for storing keys and values there is dedicated arrays for storing keys and values. + * Extra to that there is a couple quality of life functions provided + * @Type(T) + * @ValueType(V) + */ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE { + /** The Backing keys array */ protected transient KEY_TYPE[] keys; + /** The Backing values array */ protected transient VALUE_TYPE[] values; + /** If a null value is present */ protected transient boolean containsNull; + /** Minimum array size the HashMap will be */ protected transient int minCapacity; + /** Index of the Null Value */ protected transient int nullIndex; + /** Maximum amount of Values that can be stored before the array gets expanded usually 75% */ protected transient int maxFill; + /** Max Index that is allowed to be searched through nullIndex - 1 */ protected transient int mask; + /** EntrySet cache */ protected transient FastEntrySet KEY_VALUE_GENERIC_TYPE entrySet; + /** KeySet cache */ protected transient SET KEY_GENERIC_TYPE keySet; + /** Values cache */ protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC; + /** Amount of Elements stored in the HashMap */ protected int size; + /** How full the Arrays are allowed to get before resize */ protected final float loadFactor; + /** + * Default Constructor + */ public HASH_MAP() { this(HashUtil.DEFAULT_MIN_CAPACITY, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * Constructor that defines the minimum capacity + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @throws IllegalStateException if the minimum capacity is negative + */ public HASH_MAP(int minCapacity) { this(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * Constructor that defines the minimum capacity and load factor + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the minimum capacity is negative + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public HASH_MAP(int minCapacity, float loadFactor) { if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed"); if(loadFactor <= 0 || loadFactor >= 1F) throw new IllegalStateException("Load Factor is not between 0 and 1"); @@ -66,10 +100,24 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE } #if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the keys and values do not match in lenght + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, float loadFactor) { this(keys.length, loadFactor); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); @@ -77,29 +125,63 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE } #endif + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) { this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the keys and values do not match in lenght + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, float loadFactor) { this(keys.length, loadFactor); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); for(int i = 0,m=keys.length;i map) { this(map, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * A Helper constructor that allows to create a Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public HASH_MAP(Map map, float loadFactor) { this(map.size(), loadFactor); putAll(map); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ public HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map) { this(map, HashUtil.DEFAULT_LOAD_FACTOR); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param loadFactor the percentage of how full the backing array can be before they resize + * @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1 + */ public HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, float loadFactor) { this(map.size(), loadFactor); putAll(map); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template index 4d90a9ef..b1fd5893 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template @@ -40,19 +40,44 @@ import speiger.src.collections.objects.sets.ObjectSet; #endif import speiger.src.collections.utils.HashUtil; +/** + * A Very Specific Type Specific implementation of a ArrayMap. + * This type of map is for very specific use cases that usaully would have lead to Tupled Lists otherwise. + * It also does not allow duplication (except for array constructors) and checks from last to first. + * It is not designed to be used as a HashMap replacement due to the poor performance it would cause. + * @note in this implementation SubMaps do NOT keep track of parent changes fully. For performance reasons it will just have a start/end index and not values + * Anything within that range will be updated appropiatly a shrink/growth of elements will break SubMaps in some ways. This can be useful but be careful + * @note this implementation does not shrink and only grows. + * @Type(T) + * @ValueType(V) + */ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE { + /** The Backing keys array */ protected transient KEY_TYPE[] keys; + /** The Backing values array */ protected transient VALUE_TYPE[] values; + /** Amount of Elements stored in the ArrayMap */ protected int size = 0; + /** KeySet cache */ protected SET KEY_GENERIC_TYPE keySet; + /** Values cache */ protected VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC; + /** EntrySet cache */ protected FastSortedSet KEY_VALUE_GENERIC_TYPE entrySet; + /** + * Default Constructor + */ public ARRAY_MAP() { this(HashUtil.DEFAULT_MIN_CAPACITY); } + /** + * Constructor that defines the minimum capacity + * @param minCapacity the minimum capacity the HashMap is allowed to be. + * @throws IllegalStateException if the minimum capacity is negative + */ public ARRAY_MAP(int minCapacity) { if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed"); keys = NEW_KEY_ARRAY(minCapacity); @@ -60,10 +85,23 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN } #if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in length + */ public ARRAY_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { this(keys, values, keys.length); } + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) with a custom length + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param length the amount of values that should be pulled from the array + * @throws IllegalStateException if the keys and values do not match in length + */ public ARRAY_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int length) { this(length); if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); @@ -75,10 +113,23 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN } #endif + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public ARRAY_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) { this(keys, values, keys.length); } + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param length the amount of values that should be pulled from the array + * @throws IllegalStateException if the keys and values do not match in lenght + */ public ARRAY_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, int length) { if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); this.keys = Arrays.copyOf(keys, length); @@ -86,11 +137,19 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN this.size = length; } + /** + * A Helper constructor that allows to create a Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ public ARRAY_MAP(Map map) { this(map.size()); putAll(map); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ public ARRAY_MAP(MAP KEY_VALUE_GENERIC_TYPE map) { this(map.size()); for(ObjectIterator iter = MAPS.fastIterator(map);iter.hasNext();size++) { diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/EnumMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/EnumMap.template index 18f73704..eaf485b2 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/EnumMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/EnumMap.template @@ -18,17 +18,36 @@ import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.ObjectSet; import sun.misc.SharedSecrets; +/** + * A Type Specific EnumMap implementation that allows for Primitive Values. + * Unlike javas implementation this one does not jump around between a single long or long array implementation based around the enum size + * This will cause a bit more memory usage but allows for a simpler implementation. + * @Type(T) + * @ValueType(V) + */ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE { + /** Enum Type that is being used */ protected final Class keyType; + /** The Backing keys array. */ protected transient final T[] keys; + /** The Backing values array */ protected transient final VALUE_TYPE[] values; + /** The Backing array that indicates which index is present or not */ protected transient final long[] present; + /** Amount of Elements stored in the ArrayMap */ protected int size = 0; + /** EntrySet cache */ protected transient ObjectSet entrySet; + /** KeySet cache */ protected transient ObjectSet keySet; + /** Values cache */ protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC; + /** + * Default Constructor + * @param keyType the type of Enum that should be used + */ public ENUM_MAP(Class keyType) { this.keyType = keyType; keys = getKeyUniverse(keyType); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template index 9d5f4bc5..9900f3c0 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template @@ -39,38 +39,73 @@ import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.ObjectSet; #endif +/** + * A Simple Type Specific AVL TreeMap implementation that reduces boxing/unboxing. + * It is using a bit more memory then FastUtil, + * but it saves a lot of Performance on the Optimized removal and iteration logic. + * Which makes the implementation actually useable and does not force to use Javas default implementation. + * @Type(T) + * @ValueType(V) + */ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE { + /** The center of the Tree */ protected transient Entry KEY_VALUE_GENERIC_TYPE tree; + /** The Lowest possible Node */ protected transient Entry KEY_VALUE_GENERIC_TYPE first; + /** The Highest possible Node */ protected transient Entry KEY_VALUE_GENERIC_TYPE last; + /** The amount of elements stored in the Map */ protected int size = 0; + /** The Sorter of the Tree */ protected transient COMPARATOR KEY_GENERIC_TYPE comparator; -#if TYPE_OBJECT - protected KEY_TYPE defaultMaxNotFound = null; - protected KEY_TYPE defaultMinNotFound = null; -#else +#if !TYPE_OBJECT + /** the default return value for max searches */ protected KEY_TYPE defaultMaxNotFound = CLASS_TYPE.MIN_VALUE; + /** the default return value for min searches */ protected KEY_TYPE defaultMinNotFound = CLASS_TYPE.MAX_VALUE; #endif + /** KeySet Cache */ protected NAVIGABLE_SET KEY_GENERIC_TYPE keySet; + /** Values Cache */ protected VALUE_COLLECTION VALUE_GENERIC_TYPE values; + /** EntrySet Cache */ protected ObjectSet entrySet; + /** + * Default Constructor + */ public AVL_TREE_MAP() { } + /** + * Constructor that allows to define the sorter + * @param comp the function that decides how the tree is sorted, can be null + */ public AVL_TREE_MAP(COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; } #if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public AVL_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { this(keys, values, null); } + /** + * Helper constructor that has a custom sorter and allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param comp the function that decides how the tree is sorted, can be null + * @throws IllegalStateException if the keys and values do not match in lenght + */ public AVL_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); @@ -78,37 +113,74 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ } #endif + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public AVL_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) { this(keys, values, null); } + /** + * Helper constructor that has a custom sorter and allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param comp the function that decides how the tree is sorted, can be null + * @throws IllegalStateException if the keys and values do not match in lenght + */ public AVL_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); for(int i = 0,m=keys.length;i map) { this(map, null); } + /** + * A Helper constructor that has a custom sorter and allows to create a Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param comp the function that decides how the tree is sorted, can be null + */ public AVL_TREE_MAP(Map map, COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; putAll(map); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ public AVL_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map) { this(map, null); } + /** + * A Type Specific Helper function that has a custom sorter and allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param comp the function that decides how the tree is sorted, can be null + */ public AVL_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; putAll(map); } #if TYPE_OBJECT - public KEY_TYPE getDefaultMaxValue() { return defaultMaxNotFound; } - public KEY_TYPE getDefaultMinValue() { return defaultMinNotFound; } + /** only used for primitives + * @return null + */ + public KEY_TYPE getDefaultMaxValue() { return null; } + /** only used for primitives + * @return null + */ + public KEY_TYPE getDefaultMinValue() { return null; } #else @Override @@ -443,25 +515,25 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ @Override public KEY_TYPE lowerKey(KEY_TYPE e) { Entry KEY_VALUE_GENERIC_TYPE node = findLowerNode(e); - return node != null ? node.key : defaultMinNotFound; + return node != null ? node.key : getDefaultMinValue(); } @Override public KEY_TYPE floorKey(KEY_TYPE e) { Entry KEY_VALUE_GENERIC_TYPE node = findFloorNode(e); - return node != null ? node.key : defaultMinNotFound; + return node != null ? node.key : getDefaultMinValue(); } @Override public KEY_TYPE higherKey(KEY_TYPE e) { Entry KEY_VALUE_GENERIC_TYPE node = findHigherNode(e); - return node != null ? node.key : defaultMaxNotFound; + return node != null ? node.key : getDefaultMaxValue(); } @Override public KEY_TYPE ceilingKey(KEY_TYPE e) { Entry KEY_VALUE_GENERIC_TYPE node = findCeilingNode(e); - return node != null ? node.key : defaultMaxNotFound; + return node != null ? node.key : getDefaultMaxValue(); } @Override diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template index 174b7e53..ce8caca9 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template @@ -39,38 +39,73 @@ import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.ObjectSet; #endif +/** + * A Simple Type Specific RB TreeMap implementation that reduces boxing/unboxing. + * It is using a bit more memory then FastUtil, + * but it saves a lot of Performance on the Optimized removal and iteration logic. + * Which makes the implementation actually useable and does not force to use Javas default implementation. + * @Type(T) + * @ValueType(V) + */ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE { + /** The center of the Tree */ protected transient Entry KEY_VALUE_GENERIC_TYPE tree; + /** The Lowest possible Node */ protected transient Entry KEY_VALUE_GENERIC_TYPE first; + /** The Highest possible Node */ protected transient Entry KEY_VALUE_GENERIC_TYPE last; + /** The amount of elements stored in the Map */ protected int size = 0; + /** The Sorter of the Tree */ protected transient COMPARATOR KEY_GENERIC_TYPE comparator; -#if TYPE_OBJECT - protected KEY_TYPE defaultMaxNotFound = null; - protected KEY_TYPE defaultMinNotFound = null; -#else +#if !TYPE_OBJECT + /** the default return value for max searches */ protected KEY_TYPE defaultMaxNotFound = CLASS_TYPE.MIN_VALUE; + /** the default return value for min searches */ protected KEY_TYPE defaultMinNotFound = CLASS_TYPE.MAX_VALUE; #endif + /** KeySet Cache */ protected NAVIGABLE_SET KEY_GENERIC_TYPE keySet; + /** Values Cache */ protected VALUE_COLLECTION VALUE_GENERIC_TYPE values; + /** EntrySet Cache */ protected ObjectSet entrySet; + /** + * Default Constructor + */ public RB_TREE_MAP() { } + /** + * Constructor that allows to define the sorter + * @param comp the function that decides how the tree is sorted, can be null + */ public RB_TREE_MAP(COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; } #if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper constructor that allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public RB_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { this(keys, values, null); } + /** + * Helper constructor that has a custom sorter and allow to create a map from boxed values (it will unbox them) + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param comp the function that decides how the tree is sorted, can be null + * @throws IllegalStateException if the keys and values do not match in lenght + */ public RB_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); @@ -78,37 +113,74 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G } #endif + /** + * Helper constructor that allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @throws IllegalStateException if the keys and values do not match in lenght + */ public RB_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) { this(keys, values, null); } + /** + * Helper constructor that has a custom sorter and allow to create a map from unboxed values + * @param keys the keys that should be put into the map + * @param values the values that should be put into the map. + * @param comp the function that decides how the tree is sorted, can be null + * @throws IllegalStateException if the keys and values do not match in lenght + */ public RB_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size"); for(int i = 0,m=keys.length;i map) { this(map, null); } + /** + * A Helper constructor that has a custom sorter and allows to create a Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param comp the function that decides how the tree is sorted, can be null + */ public RB_TREE_MAP(Map map, COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; putAll(map); } + /** + * A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ public RB_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map) { this(map, null); } + /** + * A Type Specific Helper function that has a custom sorter and allows to create a new Map with exactly the same values as the provided map. + * @param map the values that should be present in the map + * @param comp the function that decides how the tree is sorted, can be null + */ public RB_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) { comparator = comp; putAll(map); } #if TYPE_OBJECT - public KEY_TYPE getDefaultMaxValue() { return defaultMaxNotFound; } - public KEY_TYPE getDefaultMinValue() { return defaultMinNotFound; } + /** only used for primitives + * @return null + */ + public KEY_TYPE getDefaultMaxValue() { return null; } + /** only used for primitives + * @return null + */ + public KEY_TYPE getDefaultMinValue() { return null; } #else @Override @@ -442,25 +514,25 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G @Override public KEY_TYPE lowerKey(KEY_TYPE e) { Entry KEY_VALUE_GENERIC_TYPE node = findLowerNode(e); - return node != null ? node.key : defaultMinNotFound; + return node != null ? node.key : getDefaultMinValue(); } @Override public KEY_TYPE floorKey(KEY_TYPE e) { Entry KEY_VALUE_GENERIC_TYPE node = findFloorNode(e); - return node != null ? node.key : defaultMinNotFound; + return node != null ? node.key : getDefaultMinValue(); } @Override public KEY_TYPE higherKey(KEY_TYPE e) { Entry KEY_VALUE_GENERIC_TYPE node = findHigherNode(e); - return node != null ? node.key : defaultMaxNotFound; + return node != null ? node.key : getDefaultMaxValue(); } @Override public KEY_TYPE ceilingKey(KEY_TYPE e) { Entry KEY_VALUE_GENERIC_TYPE node = findCeilingNode(e); - return node != null ? node.key : defaultMaxNotFound; + return node != null ? node.key : getDefaultMaxValue(); } @Override diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/Map.template b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/Map.template index 5781f5e6..2db85b81 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/Map.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/Map.template @@ -142,7 +142,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map fastIterator(MAP KEY_VALUE_GENERIC_TYPE map) { ObjectSet entries = map.ENTRY_SET(); return entries instanceof MAP.FastEntrySet ? ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastIterator() : entries.iterator(); } + /** + * Helper method that provides the fastIterable that recycles a single Entry to increase throughput. + * @param map the map the fastIterable should be accessed from + * @return either a normal iterable if it does not support this feature ot a fastIterable + */ public static GENERIC_KEY_VALUE_BRACES ObjectIterable fastIterable(MAP KEY_VALUE_GENERIC_TYPE map) { ObjectSet entries = map.ENTRY_SET(); return map instanceof MAP.FastEntrySet ? new ObjectIterable(){ @@ -69,6 +85,11 @@ public class MAPS } : entries; } + /** + * A Helper function that provides a faster forEach iterator implementation that recycles the entry to increase throughput + * @param map the map the fast forEach should be accessed from + * @note if the fast forEach is not supported will default to a normal forEach + */ public static GENERIC_KEY_VALUE_BRACES void fastForEach(MAP KEY_VALUE_GENERIC_TYPE map, Consumer action) { ObjectSet entries = map.ENTRY_SET(); if(entries instanceof MAP.FastEntrySet) ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastForEach(action); @@ -76,6 +97,10 @@ public class MAPS } #if !TYPE_BOOLEAN + /** + * Empty Map getter function that autocasts to the desired Key and Value + * @return empty map of desired type + */ public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE emptyMap() { #if TYPE_OBJECT || VALUE_OBJECT return (MAP KEY_VALUE_GENERIC_TYPE)EMPTY; @@ -84,23 +109,108 @@ public class MAPS #endif } + /** + * Helper function that creates a Helper wrapper to synchronize access into the map. + * @param map the map that should be synchronized + * @return a synchronized Map + * @note if the inputted map is already synchronized then it will just return it instead + * @note iterators do not support synchronization + */ public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE synchronizeMap(MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof SynchronizedMap ? map : new SynchronizedMapKV_BRACES(map); } + /** + * Helper function that creates a Helper wrapper to synchronize access with custom access control into the map. + * @param map the map that should be synchronized + * @param mutex the object that controls access + * @return a synchronized Map + * @note if the inputted map is already synchronized then it will just return it instead + * @note iterators do not support synchronization + */ public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE synchronizeMap(MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedMap ? map : new SynchronizedMapKV_BRACES(map, mutex); } + /** + * Helper function that creates a Helper wrapper to synchronize access into the SortedMap. + * @param map the SortedMap that should be synchronized + * @return a synchronized SortedMap + * @note if the inputted map is already synchronized then it will just return it instead + * @note iterators do not support synchronization + */ public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronizeMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof SynchronizedSortedMap ? map : new SynchronizedSortedMapKV_BRACES(map); } + /** + * Helper function that creates a Helper wrapper to synchronize access with custom access control into the SortedMap. + * @param map the SortedMap that should be synchronized + * @param mutex the object that controls access + * @return a synchronized SortedMap + * @note if the inputted map is already synchronized then it will just return it instead + * @note iterators do not support synchronization + */ public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronizeMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedSortedMap ? map : new SynchronizedSortedMapKV_BRACES(map, mutex); } + /** + * Helper function that creates a Helper wrapper to synchronize access into the NavigableMap. + * @param map the NavigableMap that should be synchronized + * @return a synchronized NavigableMap + * @note if the inputted map is already synchronized then it will just return it instead + * @note iterators do not support synchronization + */ public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronizeMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof SynchronizedNavigableMap ? map : new SynchronizedNavigableMapKV_BRACES(map); } + /** + * Helper function that creates a Helper wrapper to synchronize access with custom access control into the NavigableMap. + * @param map the NavigableMap that should be synchronized + * @param mutex the object that controls access + * @return a synchronized NavigableMap + * @note if the inputted map is already synchronized then it will just return it instead + * @note iterators do not support synchronization + */ public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronizeMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedNavigableMap ? map : new SynchronizedNavigableMapKV_BRACES(map, mutex); } + /** + * A Helper function that creates a Helper wrapper to only allow Read Access into the Map + * @param map the map that should be made Unmodifiable + * @return a unmodifiable Map + * @note if the inputted map is already unmodifiable then it will just return it instead + */ public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE unmodifyableMap(MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableMap ? map : new UnmodifyableMapKV_BRACES(map); } + /** + * A Helper function that creates a Helper wrapper to only allow Read Access into the SortedMap + * @param map the SortedMap that should be made Unmodifiable + * @return a unmodifiable SortedMap + * @note if the inputted SortedMap is already unmodifiable then it will just return it instead + */ public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifyableMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableSortedMap ? map : new UnmodifyableSortedMapKV_BRACES(map); } + /** + * A Helper function that creates a Helper wrapper to only allow Read Access into NavigableMap Map + * @param map the NavigableMap that should be made Unmodifiable + * @return a unmodifiable NavigableMap + * @note if the inputted NavigableMap is already unmodifiable then it will just return it instead + */ public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifyableMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableNavigableMap ? map : new UnmodifyableNavigableMapKV_BRACES(map); } - public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifyableEntry(MAP.Entry KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableEntry ? map : new UnmodifyableEntryKV_BRACES(map); } - public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifyableEntry(Map.Entry map) { return map instanceof UnmodifyableEntry ? (UnmodifyableEntry KEY_VALUE_GENERIC_TYPE)map : new UnmodifyableEntryKV_BRACES(map); } + /** + * A Helper function that creates a Unmodifyable Entry + * @param entry the Entry that should be made unmodifyable + * @return a Unmodifyable Entry + */ + public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifyableEntry(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { return entry instanceof UnmodifyableEntry ? entry : new UnmodifyableEntryKV_BRACES(entry); } + /** + * A Helper function that creates a Unmodifyable Entry + * @param entry the Entry that should be made unmodifyable + * @return a Unmodifyable Entry + */ + public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifyableEntry(Map.Entry entry) { return entry instanceof UnmodifyableEntry ? (UnmodifyableEntry KEY_VALUE_GENERIC_TYPE)entry : new UnmodifyableEntryKV_BRACES(entry); } + /** + * Creates a Singleton map from the provided values. + * This reduces overhead that normal Map implementations have. + * @param key the key that should be turned into a singleton + * @param value the value that should be turned into a singleton + * @return a unmodifyable Singleton map. + */ public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE singletonMap(KEY_TYPE key, VALUE_TYPE value) { return new SingletonMapKV_BRACES(key, value); } + /** + * Singleton Map instance that is used in the helper method + * @Type(T) + * @ValueType(V) + */ public static class SingletonMap KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE { final KEY_TYPE key; final VALUE_TYPE value; @@ -108,6 +218,11 @@ public class MAPS VALUE_COLLECTION VALUE_GENERIC_TYPE values; ObjectSet entrySet; + /** + * Default constructor + * @param key the key that should be used + * @param value the value that should be used + */ public SingletonMap(KEY_TYPE key, VALUE_TYPE value) { this.key = key; this.value = value; @@ -151,6 +266,11 @@ public class MAPS } } + /** + * Empty Map impementation that is used for the emptyMap() function + * @Type(T) + * @ValueType(V) + */ public static class EmptyMap KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE { @Override public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); } @@ -180,20 +300,45 @@ public class MAPS public ObjectSet ENTRY_SET() { return ObjectSets.empty(); } } + /** + * The Unmodifyable Entry implementation for the helper function unmodifiableEntry() + * @Type(T) + * @ValueType(V) + */ public static class UnmodifyableEntry KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP.BasicEntry KEY_VALUE_GENERIC_TYPE { + /** + * The boxed constructor that will automatically unbox the values + * @param entry the entry that should be used + */ public UnmodifyableEntry(Map.Entry entry) { super(entry.getKey(), entry.getValue()); } + /** + * The Unboxed constructor that should be copied from + * @param entry the entry that should be used + */ public UnmodifyableEntry(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { super(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); } + + @Override + public void set(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); } } + /** + * The Unmodifyable Navigable Map implementation that is sued for the unmodifyableMap function + * @Type(T) + * @ValueType(V) + */ public static class UnmodifyableNavigableMap KEY_VALUE_GENERIC_TYPE extends UnmodifyableSortedMap KEY_VALUE_GENERIC_TYPE implements NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE { NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map; + /** + * Default constructor + * @param map the NavigableMap that should be made unmodifyable + */ public UnmodifyableNavigableMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) { super(map); this.map = map; @@ -253,9 +398,18 @@ public class MAPS public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return unmodifyableEntry(map.ceilingEntry(key)); } } + /** + * The Unmodifyable Sorted Map implementation that is sued for the unmodifyableMap function + * @Type(T) + * @ValueType(V) + */ public static class UnmodifyableSortedMap KEY_VALUE_GENERIC_TYPE extends UnmodifyableMap KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE { SORTED_MAP KEY_VALUE_GENERIC_TYPE map; + /** + * Default constructor + * @param map the SortedMap that should be made unmodifyable + */ public UnmodifyableSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) { super(map); this.map = map; @@ -295,12 +449,21 @@ public class MAPS public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); } } + /** + * The Unmodifyable Map implementation that is sued for the unmodifyableMap function + * @Type(T) + * @ValueType(V) + */ public static class UnmodifyableMap KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements MAP KEY_VALUE_GENERIC_TYPE { MAP KEY_VALUE_GENERIC_TYPE map; VALUE_COLLECTION VALUE_GENERIC_TYPE values; SET KEY_GENERIC_TYPE keys; ObjectSet entrySet; + /** + * Default constructor + * @param map the Map that should be made unmodifyable + */ public UnmodifyableMap(MAP KEY_VALUE_GENERIC_TYPE map) { this.map = map; } @@ -345,10 +508,19 @@ public class MAPS } } + /** + * The Unmodifyable Set implementation for the Unmodifyable Map implementation + * @Type(T) + * @ValueType(V) + */ public static class UnmodifyableEntrySet KEY_VALUE_GENERIC_TYPE extends ObjectSets.UnmodifiableSet { ObjectSet s; - + + /** + * Default constructor + * @param c the EntrySet that should be made unmodifyable + */ public UnmodifyableEntrySet(ObjectSet c) { super(c); @@ -373,14 +545,28 @@ public class MAPS } + /** + * The Synchronized Navigable Map implementation used by the synchronizedMap helper function + * @Type(T) + * @ValueType(V) + */ public static class SynchronizedNavigableMap KEY_VALUE_GENERIC_TYPE extends SynchronizedSortedMap KEY_VALUE_GENERIC_TYPE implements NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE { NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map; + /** + * Default constructor + * @param map the map that should be synchronized + */ public SynchronizedNavigableMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) { super(map); this.map = map; } + /** + * Constructor with Access Control + * @param map the map that should be synchronized + * @param mutex the access controller + */ public SynchronizedNavigableMap(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { super(map, mutex); this.map = map; @@ -482,14 +668,28 @@ public class MAPS #endif } + /** + * The Synchronized Sorted Map implementation used by the synchronizedMap helper function + * @Type(T) + * @ValueType(V) + */ public static class SynchronizedSortedMap KEY_VALUE_GENERIC_TYPE extends SynchronizedMap KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE { SORTED_MAP KEY_VALUE_GENERIC_TYPE map; + /** + * Default constructor + * @param map the map that should be synchronized + */ public SynchronizedSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) { super(map); this.map = map; } + /** + * Constructor with Access Control + * @param map the map that should be synchronized + * @param mutex the access controller + */ public SynchronizedSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { super(map, mutex); this.map = map; @@ -546,6 +746,11 @@ public class MAPS #endif } + /** + * The Synchronized Map implementation used by the synchronizedMap helper function + * @Type(T) + * @ValueType(V) + */ public static class SynchronizedMap KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements MAP KEY_VALUE_GENERIC_TYPE { MAP KEY_VALUE_GENERIC_TYPE map; VALUE_COLLECTION VALUE_GENERIC_TYPE values; @@ -554,11 +759,20 @@ public class MAPS protected Object mutex; + /** + * Default constructor + * @param map the map that should be synchronized + */ public SynchronizedMap(MAP KEY_VALUE_GENERIC_TYPE map) { this.map = map; mutex = this; } + /** + * Constructor with Access Control + * @param map the map that should be synchronized + * @param mutex the access controller + */ public SynchronizedMap(MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { this.map = map; this.mutex = mutex; diff --git a/src/main/java/speiger/src/collections/utils/SanityChecks.java b/src/main/java/speiger/src/collections/utils/SanityChecks.java index f779c73b..5fac5fd9 100644 --- a/src/main/java/speiger/src/collections/utils/SanityChecks.java +++ b/src/main/java/speiger/src/collections/utils/SanityChecks.java @@ -105,7 +105,7 @@ public class SanityChecks /** * Helper method to control what ForkJoinPool is being used for any given task. - * @Note this method is not thread-save. It is only there to provide control over how Library specific Threaded tasks are handled. + * @note this method is not thread-save. It is only there to provide control over how Library specific Threaded tasks are handled. * @param pool The ForkJoinPool that should receive the tasks. If null {@link ForkJoinPool#commonPool()} is set instead */ public static void setWorkPool(ForkJoinPool pool) { diff --git a/src/main/java/speiger/src/collections/utils/Stack.java b/src/main/java/speiger/src/collections/utils/Stack.java index 6252abb3..367b248e 100644 --- a/src/main/java/speiger/src/collections/utils/Stack.java +++ b/src/main/java/speiger/src/collections/utils/Stack.java @@ -2,7 +2,7 @@ package speiger.src.collections.utils; /** - * The Stack Interface represents the Last-In-First-Out layout (LIFO). + * The Stack Interface represents the Last-In-First-Out layout (LIFO). * It provides a simple {@link #push(Object)}, {@link #pop()} function, * with a fast {@link #clear()} function. * The {@link #peek(int)} function allows to view the contents of the stack (top to bottom).