From c4964806f00254808d019d3aa4750669cc74cb32 Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 9 Dec 2021 09:14:55 +0100 Subject: [PATCH] Loads of new features & fixes. - Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly. - Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport) - Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before) - Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead. - Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing. - Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it) - Added: A boxed putAll array variant. - Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date. --- Changelog.md | 10 +- README.md | 2 + .../speiger/src/builder/GlobalVariables.java | 1 + .../templates/collections/Collection.template | 48 +- .../templates/collections/Iterable.template | 12 + .../templates/lists/ArrayList.template | 3 +- .../templates/lists/LinkedList.template | 8 + .../collections/templates/lists/List.template | 23 + .../maps/abstracts/AbstractMap.template | 9 + .../maps/impl/misc/ArrayMap.template | 10 +- .../templates/maps/impl/misc/EnumMap.template | 231 ++- .../maps/impl/misc/LinkedEnumMap.template | 130 ++ .../templates/maps/interfaces/Map.template | 1548 +++++++++++------ .../maps/interfaces/NavigableMap.template | 23 + .../maps/interfaces/SortedMap.template | 23 + .../templates/queues/PriorityDequeue.template | 16 + .../templates/queues/PriorityQueue.template | 31 + .../templates/sets/NavigableSet.template | 25 + .../collections/templates/sets/Set.template | 29 + .../templates/sets/SortedSet.template | 25 + .../templates/utils/Collections.template | 4 +- .../templates/utils/Lists.template | 8 +- .../templates/utils/PriorityQueues.template | 4 +- .../collections/templates/utils/Sets.template | 56 +- .../templates/utils/maps/Maps.template | 74 +- 25 files changed, 1752 insertions(+), 601 deletions(-) diff --git a/Changelog.md b/Changelog.md index e4af2703..ee39165c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,15 @@ # Changelog of versions -### Version 0.4.6 +### Version 0.5.0 - Added: 2 Helper functions to find out how many bits are required to store a Number. +- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly. +- Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport) +- Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before) +- Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead. +- Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing. +- Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it) +- Added: A boxed putAll array variant. +- Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date. ### Version 0.4.5 - Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection diff --git a/README.md b/README.md index e0b36855..ccc4d028 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,13 @@ To highlight things that may be wanted. - count: counts all valid elements in a collection. - forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References - reduce/limit/peek/distinct: Light Versions of the Stream variant, to reduce Stream usage. + - pour: a function that allows to collect all elements within the Collection - Collection: - containsAny: Allows to test if another collection contains an of the elements of the tested collection. - primitiveStream: Provides access to the closest Java Stream Type. - copy: shallowCopies the collection, used instead of clone because this is better to use. (subCollections/synchronized/unmodifiable not supported for obvious reasons) + - toArray: the ToArray function from Java9 and newer that uses a Functional interface and can use a method reference - List: - add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead - extractElements: Allows to remove a Range of elements from the List and get what was removed. diff --git a/src/builder/java/speiger/src/builder/GlobalVariables.java b/src/builder/java/speiger/src/builder/GlobalVariables.java index 7ec17c6c..c230d6fd 100644 --- a/src/builder/java/speiger/src/builder/GlobalVariables.java +++ b/src/builder/java/speiger/src/builder/GlobalVariables.java @@ -75,6 +75,7 @@ public class GlobalVariables addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : ""); addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", type.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>"); addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>"); + addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : "")); addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", type.isObject() ? " <"+type.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>"); addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>"); diff --git a/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template b/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template index d42ce308..6db91290 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template @@ -10,10 +10,12 @@ import java.util.stream.StreamSupport; #endif #if TYPE_OBJECT import java.util.function.Consumer; +import speiger.src.collections.ints.functions.function.Int2ObjectFunction; #else import speiger.src.collections.PACKAGE.functions.CONSUMER; #endif import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; +import speiger.src.collections.PACKAGE.utils.COLLECTIONS; import speiger.src.collections.utils.SanityChecks; /** @@ -148,6 +150,17 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection, ITE */ public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r); + /** + * A Helper function to reduce the usage of Streams and allows to collect all elements + * @param collection that the elements should be inserted to + * @param the collection type + * @return the input with the desired elements + */ + default E pour(E collection) { + collection.addAll(this); + return collection; + } + /** * A Function that does a shallow clone of the Collection itself. * This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted. @@ -157,7 +170,18 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection, ITE */ public COLLECTION KEY_GENERIC_TYPE copy(); -#if !TYPE_OBJECT +#if TYPE_OBJECT + /** + * A Helper function that simplifies the process of creating a new Array. + * @param action the array creation function + * @return an array containing all of the elements in this collection + * @see Collection#toArray(Object[]) + */ + default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction action) { + return TO_ARRAY(action.get(size())); + } + +#else /** * A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array. * @return an array containing all of the elements in this collection @@ -244,6 +268,28 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection, ITE @Override public ITERATOR KEY_GENERIC_TYPE iterator(); + /** + * Creates a Wrapped Collection that is Synchronized + * @return a new Collection that is synchronized + * @see COLLECTIONS#synchronize + */ + public default COLLECTION KEY_GENERIC_TYPE synchronize() { return COLLECTIONS.synchronize(this); } + + /** + * Creates a Wrapped Collection that is Synchronized + * @param mutex is the controller of the synchronization block + * @return a new Collection Wrapper that is synchronized + * @see COLLECTIONS#synchronize + */ + public default COLLECTION KEY_GENERIC_TYPE synchronize(Object mutex) { return COLLECTIONS.synchronize(this, mutex); } + + /** + * Creates a Wrapped Collection that is unmodifiable + * @return a new Collection Wrapper that is unmodifiable + * @see COLLECTIONS#unmodifiable + */ + public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); } + #if PRIMITIVES /** * Returns a Java-Type-Specific Stream to reduce boxing/unboxing. diff --git a/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template b/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template index 6712574b..37f9a010 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Iterable.template @@ -17,6 +17,7 @@ import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERABLES; +import speiger.src.collections.PACKAGE.utils.ITERATORS; /** * A Type-Specific {@link Iterable} that reduces (un)boxing @@ -148,6 +149,17 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable return ITERABLES.peek(this, action); } + /** + * A Helper function to reduce the usage of Streams and allows to collect all elements + * @param collection that the elements should be inserted to + * @param the collection type + * @return the input with the desired elements + */ + default E pour(E collection) { + ITERATORS.pour(iterator(), collection); + return collection; + } + /** * Helper function to reduce stream usage that allows to filter for any matches. * @param filter that should be applied diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template index c1c1eb49..17c533af 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template @@ -1023,8 +1023,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE public E[] toArray(E[] a) { if(a == null) a = (E[])new Object[size]; else if(a.length < size) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size); - for(int i = 0;i action) { + return super.toArray(action); + } + #endif @Override public int size() { 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 026718b2..5c0a2c4c 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,7 @@ import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.functions.COMPARATOR; #endif import speiger.src.collections.PACKAGE.utils.ARRAYS; +import speiger.src.collections.PACKAGE.utils.LISTS; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; #if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT import speiger.src.collections.utils.SanityChecks; @@ -378,6 +379,28 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List @Override public LIST KEY_GENERIC_TYPE subList(int from, int to); + /** + * Creates a Wrapped List that is Synchronized + * @return a new List that is synchronized + * @see LISTS#synchronize + */ + public default LIST KEY_GENERIC_TYPE synchronize() { return LISTS.synchronize(this); } + + /** + * Creates a Wrapped List that is Synchronized + * @param mutex is the controller of the synchronization block + * @return a new List Wrapper that is synchronized + * @see LISTS#synchronize + */ + public default LIST KEY_GENERIC_TYPE synchronize(Object mutex) { return LISTS.synchronize(this, mutex); } + + /** + * Creates a Wrapped List that is unmodifiable + * @return a new List Wrapper that is unmodifiable + * @see LISTS#unmodifiable + */ + public default LIST KEY_GENERIC_TYPE unmodifiable() { return LISTS.unmodifiable(this); } + /** * A function to ensure the elements are within the requested size. * If smaller then the stored elements they get removed as needed. diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/abstracts/AbstractMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/abstracts/AbstractMap.template index 90cc6c67..b8a4c65c 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/abstracts/AbstractMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/abstracts/AbstractMap.template @@ -90,6 +90,15 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap keyType; + protected Class keyType; /** The Backing keys array. */ - protected transient final T[] keys; + protected transient T[] keys; /** The Backing values array */ - protected transient final VALUE_TYPE[] values; + protected transient VALUE_TYPE[] values; /** The Backing array that indicates which index is present or not */ - protected transient final long[] present; + protected transient long[] present; /** Amount of Elements stored in the ArrayMap */ protected int size = 0; /** EntrySet cache */ @@ -44,6 +50,9 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE /** Values cache */ protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC; + protected ENUM_MAP() { + + } /** * Default Constructor * @param keyType the type of Enum that should be used @@ -55,6 +64,86 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE present = new long[((keys.length - 1) >> 6) + 1]; } +#if !VALUE_OBJECT + /** + * Helper constructor that allow to create a EnumMap from boxed values (it will unbox them) + * @param keys the keys that should be put into the EnumMap + * @param values the values that should be put into the EnumMap. + * @throws IllegalStateException if the keys and values do not match in lenght + */ + public ENUM_MAP(T[] keys, CLASS_VALUE_TYPE[] values) { + if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed"); + if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size"); + keyType = keys[0].getDeclaringClass(); + this.keys = getKeyUniverse(keyType); + this.values = NEW_VALUE_ARRAY(keys.length); + present = new long[((keys.length - 1) >> 6) + 1]; + putAll(keys, values); + } + +#endif + /** + * Helper constructor that allow to create a EnumMap 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 ENUM_MAP(T[] keys, VALUE_TYPE[] values) { + if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed"); + if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size"); + keyType = keys[0].getDeclaringClass(); + this.keys = getKeyUniverse(keyType); + this.values = NEW_VALUE_ARRAY(keys.length); + present = new long[((keys.length - 1) >> 6) + 1]; + putAll(keys, values); + } + + /** + * A Helper constructor that allows to create a EnumMap with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ + public ENUM_MAP(Map map) { + if(map instanceof ENUM_MAP) { + ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map; + keyType = enumMap.keyType; + keys = enumMap.keys; + values = enumMap.values.clone(); + present = enumMap.present.clone(); + size = enumMap.size; + } + else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed"); + else { + keyType = map.keySet().iterator().next().getDeclaringClass(); + this.keys = getKeyUniverse(keyType); + this.values = NEW_VALUE_ARRAY(keys.length); + present = new long[((keys.length - 1) >> 6) + 1]; + putAll(map); + } + } + + /** + * A Type Specific Helper function that allows to create a new EnumMap with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ + public ENUM_MAP(MAP KEY_VALUE_GENERIC_TYPE map) { + if(map instanceof ENUM_MAP) { + ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map; + keyType = enumMap.keyType; + keys = enumMap.keys; + values = enumMap.values.clone(); + present = enumMap.present.clone(); + size = enumMap.size; + } + else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed"); + else { + keyType = map.keySet().iterator().next().getDeclaringClass(); + this.keys = getKeyUniverse(keyType); + this.values = NEW_VALUE_ARRAY(keys.length); + present = new long[((keys.length - 1) >> 6) + 1]; + putAll(map); + } + } + @Override public VALUE_TYPE put(T key, VALUE_TYPE value) { int index = key.ordinal(); @@ -203,6 +292,130 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE return valuesC; } + @Override + public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) { + if(size() <= 0) return; + for(int i = 0,m=keys.length;i> 6] |= (1L << index); onNodeAdded(index); } protected void clear(int index) { + size--; present[index >> 6] &= ~(1L << index); onNodeRemoved(index); } protected boolean isSet(int index) { return (present[index >> 6] & (1L << index)) != 0; } - private static > K[] getKeyUniverse(Class keyType) { + protected static > K[] getKeyUniverse(Class keyType) { return keyType.getEnumConstants(); } diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template index f0192ee5..7a0f9921 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template @@ -59,6 +59,136 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA links = new long[keys.length]; } +#if !VALUE_OBJECT + /** + * Helper constructor that allow to create a EnumMap from boxed values (it will unbox them) + * @param keys the keys that should be put into the EnumMap + * @param values the values that should be put into the EnumMap. + * @throws IllegalStateException if the keys and values do not match in lenght + */ + public LINKED_ENUM_MAP(T[] keys, CLASS_VALUE_TYPE[] values) { + if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed"); + if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size"); + keyType = keys[0].getDeclaringClass(); + this.keys = getKeyUniverse(keyType); + this.values = NEW_VALUE_ARRAY(keys.length); + present = new long[((keys.length - 1) >> 6) + 1]; + links = new long[keys.length]; + putAll(keys, values); + } + +#endif + /** + * Helper constructor that allow to create a EnumMap 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_ENUM_MAP(T[] keys, VALUE_TYPE[] values) { + if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed"); + if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size"); + keyType = keys[0].getDeclaringClass(); + this.keys = getKeyUniverse(keyType); + this.values = NEW_VALUE_ARRAY(keys.length); + present = new long[((keys.length - 1) >> 6) + 1]; + links = new long[keys.length]; + putAll(keys, values); + } + + /** + * A Helper constructor that allows to create a EnumMap with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ + public LINKED_ENUM_MAP(Map map) { + if(map instanceof LINKED_ENUM_MAP) { + LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE)map; + keyType = enumMap.keyType; + keys = enumMap.keys; + values = enumMap.values.clone(); + present = enumMap.present.clone(); + links = enumMap.links.clone(); + size = enumMap.size; + } + if(map instanceof ENUM_MAP) { + ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map; + keyType = enumMap.keyType; + keys = enumMap.keys; + values = enumMap.values.clone(); + present = enumMap.present.clone(); + links = new long[keys.length]; + for(int i = 0,m=keys.length;i> 6) + 1]; + links = new long[keys.length]; + putAll(map); + } + } + + /** + * A Type Specific Helper function that allows to create a new EnumMap with exactly the same values as the provided map. + * @param map the values that should be present in the map + */ + public LINKED_ENUM_MAP(MAP KEY_VALUE_GENERIC_TYPE map) { + if(map instanceof LINKED_ENUM_MAP) { + LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE)map; + keyType = enumMap.keyType; + keys = enumMap.keys; + values = enumMap.values.clone(); + present = enumMap.present.clone(); + links = enumMap.links.clone(); + size = enumMap.size; + } + if(map instanceof ENUM_MAP) { + ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map; + keyType = enumMap.keyType; + keys = enumMap.keys; + values = enumMap.values.clone(); + present = enumMap.present.clone(); + links = new long[keys.length]; + for(int i = 0,m=keys.length;i> 6) + 1]; + links = new long[keys.length]; + putAll(map); + } + } + @Override public VALUE_TYPE putAndMoveToFirst(T key, VALUE_TYPE value) { int index = key.ordinal(); 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 996e885d..e3ff132f 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 @@ -4,10 +4,15 @@ import java.util.Map; #if VALUE_OBJECT && !TYPE_OBJECT import java.util.Objects; #endif +#if !TYPE_BOOLEAN +import java.util.Collection; +import java.util.Arrays; +#endif import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; + #if TYPE_OBJECT import java.util.Comparator; #endif @@ -27,7 +32,14 @@ import speiger.src.collections.PACKAGE.maps.impl.hash.HASH_MAP; import speiger.src.collections.PACKAGE.maps.impl.immutable.IMMUTABLE_HASH_MAP; import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP; import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP; +import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP; +#if TYPE_OBJECT +import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP; +import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP; +#endif +import speiger.src.collections.objects.collections.ObjectIterable; import speiger.src.collections.PACKAGE.utils.STRATEGY; +import speiger.src.collections.PACKAGE.utils.maps.MAPS; #endif import speiger.src.collections.PACKAGE.sets.SET; #if !SAME_TYPE @@ -38,6 +50,10 @@ import speiger.src.collections.objects.collections.ObjectIterator; #if !TYPE_OBJECT import speiger.src.collections.objects.sets.ObjectSet; #endif +#if !TYPE_BOOLEAN +import speiger.src.collections.utils.HashUtil; +import speiger.src.collections.utils.SanityChecks; +#endif /** * A Type Specific Map that reduces memory overhead due to boxing/unboxing of Primitives @@ -47,6 +63,16 @@ import speiger.src.collections.objects.sets.ObjectSet; */ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map, FUNCTION KEY_VALUE_GENERIC_TYPE { +#if !TYPE_BOOLEAN + /** + * Helper Class that allows to create Maps without requiring a to type out the entire implementation or know it. + * @return a MapBuilder + */ + public static MapBuilder builder() { + return MapBuilder.INSTANCE; + } + +#endif /** * Method to see what the default return value is. * @return default return value @@ -100,6 +126,31 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map ENTRY_SET(); +#if !TYPE_BOOLEAN + /** + * Creates a Wrapped Map that is Synchronized + * @return a new Map that is synchronized + * @see MAPS#synchronize + */ + public default MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); } + + /** + * Creates a Wrapped Map that is Synchronized + * @param mutex is the controller of the synchronization block + * @return a new Map Wrapper that is synchronized + * @see MAPS#synchronize + */ + public default MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); } + + /** + * Creates a Wrapped Map that is unmodifiable + * @return a new Map Wrapper that is unmodifiable + * @see MAPS#unmodifiable + */ + public default MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); } + +#endif #if !TYPE_OBJECT || !VALUE_OBJECT @Override @Primitive @@ -478,521 +553,984 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map map) { + return new HASH_MAPKV_BRACES(map); + } + + /** + * Helper function to unify code + * @Type(T) + * @ValueType(V) + * @return a LinkedOpenHashMap + */ + public GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE linkedMap() { + return new LINKED_HASH_MAPKV_BRACES(); + } + + /** + * Helper function to unify code + * @param size the minimum capacity of the Map + * @Type(T) + * @ValueType(V) + * @return a LinkedOpenHashMap with a mimimum capacity + */ + public GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE linkedMap(int size) { + return new LINKED_HASH_MAPKV_BRACES(size); + } + + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a LinkedOpenHashMap thats contains the injected values + */ + public GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE linkedMap(KEY_TYPE[] keys, VALUE_TYPE[] values) { + return new LINKED_HASH_MAPKV_BRACES(keys, values); + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a LinkedOpenHashMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE linkedMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { + return new LINKED_HASH_MAPKV_BRACES(keys, values); + } + +#endif + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @return a LinkedOpenHashMap thats copies the contents of the provided map + */ + public GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE linkedMap(MAP KEY_VALUE_GENERIC_TYPE map) { + return new LINKED_HASH_MAPKV_BRACES(map); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @return a LinkedOpenHashMap thats copies the contents of the provided map + * @note the map will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE linkedMap(Map map) { + return new IMMUTABLE_HASH_MAPKV_BRACES(map); + } + + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a ImmutableOpenHashMap thats contains the injected values + */ + public GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE immutable(KEY_TYPE[] keys, VALUE_TYPE[] values) { + return new IMMUTABLE_HASH_MAPKV_BRACES(keys, values); + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a ImmutableOpenHashMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE immutable(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { + return new IMMUTABLE_HASH_MAPKV_BRACES(keys, values); + } + +#endif + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @return a ImmutableOpenHashMap thats copies the contents of the provided map + */ + public GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE immutable(MAP KEY_VALUE_GENERIC_TYPE map) { + return new IMMUTABLE_HASH_MAPKV_BRACES(map); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @return a ImmutableOpenHashMap thats copies the contents of the provided map + * @note the map will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE immutable(Map map) { + return new IMMUTABLE_HASH_MAPKV_BRACES(map); + } + +#if TYPE_OBJECT + /** + * Helper function to unify code + * @param keyType the EnumClass that should be used + * @Type(T) + * @ValueType(V) + * @return a Empty EnumMap + */ + public GENERIC_KEY_ENUM_VALUE_BRACES ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap(Class keyType) { + return new ENUM_MAPKV_BRACES(keyType); + } + +#if !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @throws IllegalArgumentException if the keys are in length 0 + * @return a EnumMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_ENUM_VALUE_BRACES ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { + return new ENUM_MAPKV_BRACES(keys, values); + } + +#endif + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @throws IllegalArgumentException if the keys are in length 0 + * @return a EnumMap thats contains the injected values + */ + public GENERIC_KEY_ENUM_VALUE_BRACES ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap(KEY_TYPE[] keys, VALUE_TYPE[] values) { + return new ENUM_MAPKV_BRACES(keys, values); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @return a EnumMap thats copies the contents of the provided map + * @throws IllegalArgumentException if the map is Empty and is not a EnumMap + * @note the map will be unboxed + */ + public GENERIC_KEY_ENUM_VALUE_BRACES ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap(Map map) { + return new ENUM_MAPKV_BRACES(map); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @throws IllegalArgumentException if the map is Empty and is not a EnumMap + * @return a EnumMap thats copies the contents of the provided map + */ + public GENERIC_KEY_ENUM_VALUE_BRACES ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap(MAP KEY_VALUE_GENERIC_TYPE map) { + return new ENUM_MAPKV_BRACES(map); + } + + /** + * Helper function to unify code + * @param keyType the EnumClass that should be used + * @Type(T) + * @ValueType(V) + * @return a Empty LinkedEnumMap + */ + public GENERIC_KEY_ENUM_VALUE_BRACES LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE linkedEnumMap(Class keyType) { + return new LINKED_ENUM_MAPKV_BRACES(keyType); + } + +#if !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @throws IllegalArgumentException if the keys are in length 0 + * @return a LinkedEnumMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_ENUM_VALUE_BRACES LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE linkedEnumMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { + return new LINKED_ENUM_MAPKV_BRACES(keys, values); + } + +#endif + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @throws IllegalArgumentException if the keys are in length 0 + * @return a LinkedEnumMap thats contains the injected values + */ + public GENERIC_KEY_ENUM_VALUE_BRACES LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE linkedEnumMap(KEY_TYPE[] keys, VALUE_TYPE[] values) { + return new LINKED_ENUM_MAPKV_BRACES(keys, values); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @return a LinkedEnumMap thats copies the contents of the provided map + * @throws IllegalArgumentException if the map is Empty and is not a EnumMap + * @note the map will be unboxed + */ + public GENERIC_KEY_ENUM_VALUE_BRACES LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE linkedEnumMap(Map map) { + return new LINKED_ENUM_MAPKV_BRACES(map); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @throws IllegalArgumentException if the map is Empty and is not a EnumMap + * @return a LinkedEnumMap thats copies the contents of the provided map + */ + public GENERIC_KEY_ENUM_VALUE_BRACES LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE linkedEnumMap(MAP KEY_VALUE_GENERIC_TYPE map) { + return new LINKED_ENUM_MAPKV_BRACES(map); + } +#endif + /** + * Helper function to unify code + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @return a CustomOpenHashMap + */ + public GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customMap(STRATEGY KEY_GENERIC_TYPE strategy) { + return new CUSTOM_HASH_MAPKV_BRACES(strategy); + } + + /** + * Helper function to unify code + * @param size the minimum capacity of the Map + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @return a CustomOpenHashMap with a mimimum capacity + */ + public GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customMap(int size, STRATEGY KEY_GENERIC_TYPE strategy) { + return new CUSTOM_HASH_MAPKV_BRACES(size, strategy); + } + + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a CustomOpenHashMap thats contains the injected values + */ + public GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customMap(KEY_TYPE[] keys, VALUE_TYPE[] values, STRATEGY KEY_GENERIC_TYPE strategy) { + return new CUSTOM_HASH_MAPKV_BRACES(keys, values, strategy); + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a CustomOpenHashMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, STRATEGY KEY_GENERIC_TYPE strategy) { + return new CUSTOM_HASH_MAPKV_BRACES(keys, values, strategy); + } + +#endif + /** + * Helper function to unify code + * @param map that should be cloned + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @return a CustomOpenHashMap thats copies the contents of the provided map + */ + public GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customMap(MAP KEY_VALUE_GENERIC_TYPE map, STRATEGY KEY_GENERIC_TYPE strategy) { + return new CUSTOM_HASH_MAPKV_BRACES(map, strategy); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @return a CustomOpenHashMap thats copies the contents of the provided map + * @note the map will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customMap(Map map, STRATEGY KEY_GENERIC_TYPE strategy) { + return new CUSTOM_HASH_MAPKV_BRACES(map, strategy); + } + + /** + * Helper function to unify code + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @return a CustomLinkedOpenHashMap + */ + public GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customLinkedMap(STRATEGY KEY_GENERIC_TYPE strategy) { + return new LINKED_CUSTOM_HASH_MAPKV_BRACES(strategy); + } + + /** + * Helper function to unify code + * @param size the minimum capacity of the Map + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @return a CustomLinkedOpenHashMap with a mimimum capacity + */ + public GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customLinkedMap(int size, STRATEGY KEY_GENERIC_TYPE strategy) { + return new LINKED_CUSTOM_HASH_MAPKV_BRACES(size, strategy); + } + + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a CustomLinkedOpenHashMap thats contains the injected values + */ + public GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customLinkedMap(KEY_TYPE[] keys, VALUE_TYPE[] values, STRATEGY KEY_GENERIC_TYPE strategy) { + return new LINKED_CUSTOM_HASH_MAPKV_BRACES(keys, values, strategy); + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a CustomLinkedOpenHashMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customLinkedMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, STRATEGY KEY_GENERIC_TYPE strategy) { + return new LINKED_CUSTOM_HASH_MAPKV_BRACES(keys, values, strategy); + } + +#endif + /** + * Helper function to unify code + * @param map that should be cloned + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @return a CustomLinkedOpenHashMap thats copies the contents of the provided map + */ + public GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customLinkedMap(MAP KEY_VALUE_GENERIC_TYPE map, STRATEGY KEY_GENERIC_TYPE strategy) { + return new LINKED_CUSTOM_HASH_MAPKV_BRACES(map, strategy); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @param strategy the Hash Controller + * @Type(T) + * @ValueType(V) + * @return a CustomLinkedOpenHashMap thats copies the contents of the provided map + * @note the map will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customLinkedMap(Map map, STRATEGY KEY_GENERIC_TYPE strategy) { + return new LINKED_CUSTOM_HASH_MAPKV_BRACES(map, strategy); + } + + /** + * Helper function to unify code + * @Type(T) + * @ValueType(V) + * @return a OpenHashMap + */ + public GENERIC_KEY_VALUE_BRACES ARRAY_MAP KEY_VALUE_GENERIC_TYPE arrayMap() { + return new ARRAY_MAPKV_BRACES(); + } + + /** + * Helper function to unify code + * @param size the minimum capacity of the Map + * @Type(T) + * @ValueType(V) + * @return a OpenHashMap with a mimimum capacity + */ + public GENERIC_KEY_VALUE_BRACES ARRAY_MAP KEY_VALUE_GENERIC_TYPE arrayMap(int size) { + return new ARRAY_MAPKV_BRACES(size); + } + + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a OpenHashMap thats contains the injected values + */ + public GENERIC_KEY_VALUE_BRACES ARRAY_MAP KEY_VALUE_GENERIC_TYPE arrayMap(KEY_TYPE[] keys, VALUE_TYPE[] values) { + return new ARRAY_MAPKV_BRACES(keys, values); + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a OpenHashMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES ARRAY_MAP KEY_VALUE_GENERIC_TYPE arrayMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { + return new ARRAY_MAPKV_BRACES(keys, values); + } + +#endif + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @return a OpenHashMap thats copies the contents of the provided map + */ + public GENERIC_KEY_VALUE_BRACES ARRAY_MAP KEY_VALUE_GENERIC_TYPE arrayMap(MAP KEY_VALUE_GENERIC_TYPE map) { + return new ARRAY_MAPKV_BRACES(map); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @Type(T) + * @ValueType(V) + * @return a OpenHashMap thats copies the contents of the provided map + * @note the map will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES ARRAY_MAP KEY_VALUE_GENERIC_TYPE arrayMap(Map map) { + return new ARRAY_MAPKV_BRACES(map); + } + + + /** + * Helper function to unify code + * @Type(T) + * @ValueType(V) + * @return a RBTreeMap + */ + public GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE rbTreeMap() { + return new RB_TREE_MAPKV_BRACES(); + } + + /** + * Helper function to unify code + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @return a RBTreeMap + */ + public GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE rbTreeMap(COMPARATOR KEY_GENERIC_TYPE comp) { + return new RB_TREE_MAPKV_BRACES(comp); + } + + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a RBTreeMap thats contains the injected values + */ + public GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE rbTreeMap(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { + return new RB_TREE_MAPKV_BRACES(keys, values, comp); + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a RBTreeMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE rbTreeMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { + return new RB_TREE_MAPKV_BRACES(keys, values, comp); + } + +#endif + /** + * Helper function to unify code + * @param map that should be cloned + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @return a RBTreeMap thats copies the contents of the provided map + */ + public GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE rbTreeMap(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) { + return new RB_TREE_MAPKV_BRACES(map, comp); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @return a RBTreeMap thats copies the contents of the provided map + * @note the map will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE rbTreeMap(Map map, COMPARATOR KEY_GENERIC_TYPE comp) { + return new RB_TREE_MAPKV_BRACES(map, comp); + } + + /** + * Helper function to unify code + * @Type(T) + * @ValueType(V) + * @return a AVLTreeMap + */ + public GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap() { + return new AVL_TREE_MAPKV_BRACES(); + } + + /** + * Helper function to unify code + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @return a AVLTreeMap + */ + public GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(COMPARATOR KEY_GENERIC_TYPE comp) { + return new AVL_TREE_MAPKV_BRACES(comp); + } + + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a AVLTreeMap thats contains the injected values + */ + public GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { + return new AVL_TREE_MAPKV_BRACES(keys, values, comp); + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper function to unify code + * @param keys the keys that should be inserted + * @param values the values that should be inserted + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @throws IllegalStateException if the keys and values do not match in length + * @return a AVLTreeMap thats contains the injected values + * @note the keys and values will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { + return new AVL_TREE_MAPKV_BRACES(keys, values, comp); + } + +#endif + /** + * Helper function to unify code + * @param map that should be cloned + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @return a AVLTreeMap thats copies the contents of the provided map + */ + public GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) { + return new AVL_TREE_MAPKV_BRACES(map, comp); + } + + /** + * Helper function to unify code + * @param map that should be cloned + * @param comp the Sorter of the TreeMap + * @Type(T) + * @ValueType(V) + * @return a AVLTreeMap thats copies the contents of the provided map + * @note the map will be unboxed + */ + public GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(Map map, COMPARATOR KEY_GENERIC_TYPE comp) { + return new AVL_TREE_MAPKV_BRACES(map, comp); + } } /** - * Helper function to unify code - * @param size the minimum capacity of the Map - * @Type(T) - * @ValueType(V) - * @return a OpenHashMap with a mimimum capacity - */ - public static GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE createMap(int size) { - return new HASH_MAPKV_BRACES(size); + * Builder Cache for allowing to buildMaps + * @Type(T) + * @ValueType(V) + */ + public static class BuilderCache KEY_VALUE_GENERIC_TYPE + { + KEY_TYPE[] keys; + VALUE_TYPE[] values; + int size; + + /** + * Default Constructor + */ + public BuilderCache() { + this(HashUtil.DEFAULT_MIN_CAPACITY); + } + + /** + * Constructor providing a Minimum Capcity + * @param initialSize the requested start capacity + */ + public BuilderCache(int initialSize) { + keys = NEW_KEY_ARRAY(initialSize); + values = NEW_VALUE_ARRAY(initialSize); + } + + private void ensureSize(int newSize) { + if(keys.length >= newSize) return; + newSize = (int)Math.max(Math.min((long)keys.length + (keys.length >> 1), SanityChecks.MAX_ARRAY_SIZE), newSize); + keys = Arrays.copyOf(keys, newSize); + values = Arrays.copyOf(values, newSize); + } + + /** + * Helper function to add a Entry into the Map + * @param key the key that should be added + * @param value the value that should be added + * @return self + */ + public BuilderCache KEY_VALUE_GENERIC_TYPE put(KEY_TYPE key, VALUE_TYPE value) { + ensureSize(size+1); + keys[size] = key; + values[size] = value; + size++; + return this; + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** + * Helper function to add a Entry into the Map + * @param key the key that should be added + * @param value the value that should be added + * @return self + */ + public BuilderCache KEY_VALUE_GENERIC_TYPE put(CLASS_TYPE key, CLASS_VALUE_TYPE value) { + return put(OBJ_TO_KEY(key), OBJ_TO_VALUE(value)); + } + +#endif + /** + * Helper function to add a Entry into the Map + * @param entry the Entry that should be added + * @return self + */ + public BuilderCache KEY_VALUE_GENERIC_TYPE put(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { + return put(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } + + /** + * Helper function to add a Map to the Map + * @param map that should be added + * @return self + */ + public BuilderCache KEY_VALUE_GENERIC_TYPE putAll(MAP KEY_VALUE_GENERIC_TYPE map) { + return putAll(MAPS.fastIterable(map)); + } + + /** + * Helper function to add a Map to the Map + * @param map that should be added + * @return self + */ + public BuilderCache KEY_VALUE_GENERIC_TYPE putAll(Map map) { + for(Map.Entry entry : map.entrySet()) + put(entry.getKey(), entry.getValue()); + return this; + } + + /** + * Helper function to add a Collection of Entries to the Map + * @param c that should be added + * @return self + */ + public BuilderCache KEY_VALUE_GENERIC_TYPE putAll(ObjectIterable c) { + if(c instanceof Collection) + ensureSize(size+((Collection)c).size()); + + for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : c) + put(entry); + + return this; + } + + private E putElements(E e){ + e.putAll(keys, values, 0, size); + return e; + } + + /** + * Builds the Keys & Values into a Hash Map + * @return a HASH_MAP + */ + public HASH_MAP KEY_VALUE_GENERIC_TYPE map() { + return putElements(new HASH_MAPKV_BRACES(size)); + } + + /** + * Builds the Keys & Values into a Linked Hash Map + * @return a LINKED_HASH_MAP + */ + public LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE linkedMap() { + return putElements(new LINKED_HASH_MAPKV_BRACES(size)); + } + + /** + * Builds the Keys & Values into a Immutable Hash Map + * @return a IMMUTABLE_HASH_MAP + */ + public IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE immutable() { + return new IMMUTABLE_HASH_MAPKV_BRACES(Arrays.copyOf(keys, size), Arrays.copyOf(values, size)); + } + + /** + * Builds the Keys & Values into a Custom Hash Map + * @param strategy the that controls the keys & values + * @return a CUSTOM_HASH_MAP + */ + public CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customMap(STRATEGY KEY_GENERIC_TYPE strategy) { + return putElements(new CUSTOM_HASH_MAPKV_BRACES(size, strategy)); + } + + /** + * Builds the Keys & Values into a Linked Custom Hash Map + * @param strategy the that controls the keys & values + * @return a LINKED_CUSTOM_HASH_MAP + */ + public LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE customLinkedMap(STRATEGY KEY_GENERIC_TYPE strategy) { + return putElements(new LINKED_CUSTOM_HASH_MAPKV_BRACES(size, strategy)); + } + + /** + * Builds the Keys & Values into a Array Map + * @return a ARRAY_MAP + */ + public ARRAY_MAP KEY_VALUE_GENERIC_TYPE arrayMap() { + return new ARRAY_MAPKV_BRACES(keys, values, size); + } + + /** + * Builds the Keys & Values into a RedBlack TreeMap + * @return a RB_TREE_MAP + */ + public RB_TREE_MAP KEY_VALUE_GENERIC_TYPE rbTreeMap() { + return putElements(new RB_TREE_MAPKV_BRACES()); + } + + /** + * Builds the Keys & Values into a RedBlack TreeMap + * @param comp the Comparator that sorts the Tree + * @return a RB_TREE_MAP + */ + public RB_TREE_MAP KEY_VALUE_GENERIC_TYPE rbTreeMap(COMPARATOR KEY_GENERIC_TYPE comp) { + return putElements(new RB_TREE_MAPKV_BRACES(comp)); + } + + /** + * Builds the Keys & Values into a AVL TreeMap + * @return a AVL_TREE_MAP + */ + public AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap() { + return putElements(new AVL_TREE_MAPKV_BRACES()); + } + + /** + * Builds the Keys & Values into a AVL TreeMap + * @param comp the Comparator that sorts the Tree + * @return a AVL_TREE_MAP + */ + public AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE avlTreeMap(COMPARATOR KEY_GENERIC_TYPE comp) { + return putElements(new AVL_TREE_MAPKV_BRACES(comp)); + } } - - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a OpenHashMap thats contains the injected values - */ - public static GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE createMap(KEY_TYPE[] keys, VALUE_TYPE[] values) { - return new HASH_MAPKV_BRACES(keys, values); - } - - #if !TYPE_OBJECT || !VALUE_OBJECT - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a OpenHashMap thats contains the injected values - * @note the keys and values will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE createMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { - return new HASH_MAPKV_BRACES(keys, values); - } - - #endif - /** - * Helper function to unify code - * @param map that should be cloned - * @Type(T) - * @ValueType(V) - * @return a OpenHashMap thats copies the contents of the provided map - */ - public static GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE createMap(MAP KEY_VALUE_GENERIC_TYPE map) { - return new HASH_MAPKV_BRACES(map); - } - - /** - * Helper function to unify code - * @param map that should be cloned - * @Type(T) - * @ValueType(V) - * @return a OpenHashMap thats copies the contents of the provided map - * @note the map will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE createMap(Map map) { - return new HASH_MAPKV_BRACES(map); - } - - /** - * Helper function to unify code - * @Type(T) - * @ValueType(V) - * @return a LinkedOpenHashMap - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE createLinkedMap() { - return new LINKED_HASH_MAPKV_BRACES(); - } - - /** - * Helper function to unify code - * @param size the minimum capacity of the Map - * @Type(T) - * @ValueType(V) - * @return a LinkedOpenHashMap with a mimimum capacity - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE createLinkedMap(int size) { - return new LINKED_HASH_MAPKV_BRACES(size); - } - - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a LinkedOpenHashMap thats contains the injected values - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE createLinkedMap(KEY_TYPE[] keys, VALUE_TYPE[] values) { - return new LINKED_HASH_MAPKV_BRACES(keys, values); - } - - #if !TYPE_OBJECT || !VALUE_OBJECT - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a LinkedOpenHashMap thats contains the injected values - * @note the keys and values will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE createLinkedMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { - return new LINKED_HASH_MAPKV_BRACES(keys, values); - } - - #endif - /** - * Helper function to unify code - * @param map that should be cloned - * @Type(T) - * @ValueType(V) - * @return a LinkedOpenHashMap thats copies the contents of the provided map - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE createLinkedMap(MAP KEY_VALUE_GENERIC_TYPE map) { - return new LINKED_HASH_MAPKV_BRACES(map); - } - - /** - * Helper function to unify code - * @param map that should be cloned - * @Type(T) - * @ValueType(V) - * @return a LinkedOpenHashMap thats copies the contents of the provided map - * @note the map will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE createLinkedMap(Map map) { - return new IMMUTABLE_HASH_MAPKV_BRACES(map); - } - - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a ImmutableOpenHashMap thats contains the injected values - */ - public static GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE createImmutable(KEY_TYPE[] keys, VALUE_TYPE[] values) { - return new IMMUTABLE_HASH_MAPKV_BRACES(keys, values); - } - - #if !TYPE_OBJECT || !VALUE_OBJECT - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a ImmutableOpenHashMap thats contains the injected values - * @note the keys and values will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE createImmutable(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) { - return new IMMUTABLE_HASH_MAPKV_BRACES(keys, values); - } - - #endif - /** - * Helper function to unify code - * @param map that should be cloned - * @Type(T) - * @ValueType(V) - * @return a ImmutableOpenHashMap thats copies the contents of the provided map - */ - public static GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE createImmutable(MAP KEY_VALUE_GENERIC_TYPE map) { - return new IMMUTABLE_HASH_MAPKV_BRACES(map); - } - - /** - * Helper function to unify code - * @param map that should be cloned - * @Type(T) - * @ValueType(V) - * @return a ImmutableOpenHashMap thats copies the contents of the provided map - * @note the map will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE createImmutable(Map map) { - return new IMMUTABLE_HASH_MAPKV_BRACES(map); - } - - /** - * Helper function to unify code - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @return a CustomOpenHashMap - */ - public static GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomMap(STRATEGY KEY_GENERIC_TYPE strategy) { - return new CUSTOM_HASH_MAPKV_BRACES(strategy); - } - - /** - * Helper function to unify code - * @param size the minimum capacity of the Map - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @return a CustomOpenHashMap with a mimimum capacity - */ - public static GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomMap(int size, STRATEGY KEY_GENERIC_TYPE strategy) { - return new CUSTOM_HASH_MAPKV_BRACES(size, strategy); - } - - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a CustomOpenHashMap thats contains the injected values - */ - public static GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomMap(KEY_TYPE[] keys, VALUE_TYPE[] values, STRATEGY KEY_GENERIC_TYPE strategy) { - return new CUSTOM_HASH_MAPKV_BRACES(keys, values, strategy); - } - - #if !TYPE_OBJECT || !VALUE_OBJECT - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a CustomOpenHashMap thats contains the injected values - * @note the keys and values will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, STRATEGY KEY_GENERIC_TYPE strategy) { - return new CUSTOM_HASH_MAPKV_BRACES(keys, values, strategy); - } - - #endif - /** - * Helper function to unify code - * @param map that should be cloned - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @return a CustomOpenHashMap thats copies the contents of the provided map - */ - public static GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomMap(MAP KEY_VALUE_GENERIC_TYPE map, STRATEGY KEY_GENERIC_TYPE strategy) { - return new CUSTOM_HASH_MAPKV_BRACES(map, strategy); - } - - /** - * Helper function to unify code - * @param map that should be cloned - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @return a CustomOpenHashMap thats copies the contents of the provided map - * @note the map will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomMap(Map map, STRATEGY KEY_GENERIC_TYPE strategy) { - return new CUSTOM_HASH_MAPKV_BRACES(map, strategy); - } - - /** - * Helper function to unify code - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @return a CustomLinkedOpenHashMap - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomLinkedMap(STRATEGY KEY_GENERIC_TYPE strategy) { - return new LINKED_CUSTOM_HASH_MAPKV_BRACES(strategy); - } - - /** - * Helper function to unify code - * @param size the minimum capacity of the Map - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @return a CustomLinkedOpenHashMap with a mimimum capacity - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomLinkedMap(int size, STRATEGY KEY_GENERIC_TYPE strategy) { - return new LINKED_CUSTOM_HASH_MAPKV_BRACES(size, strategy); - } - - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a CustomLinkedOpenHashMap thats contains the injected values - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomLinkedMap(KEY_TYPE[] keys, VALUE_TYPE[] values, STRATEGY KEY_GENERIC_TYPE strategy) { - return new LINKED_CUSTOM_HASH_MAPKV_BRACES(keys, values, strategy); - } - - #if !TYPE_OBJECT || !VALUE_OBJECT - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a CustomLinkedOpenHashMap thats contains the injected values - * @note the keys and values will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomLinkedMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, STRATEGY KEY_GENERIC_TYPE strategy) { - return new LINKED_CUSTOM_HASH_MAPKV_BRACES(keys, values, strategy); - } - - #endif - /** - * Helper function to unify code - * @param map that should be cloned - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @return a CustomLinkedOpenHashMap thats copies the contents of the provided map - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomLinkedMap(MAP KEY_VALUE_GENERIC_TYPE map, STRATEGY KEY_GENERIC_TYPE strategy) { - return new LINKED_CUSTOM_HASH_MAPKV_BRACES(map, strategy); - } - - /** - * Helper function to unify code - * @param map that should be cloned - * @param strategy the Hash Controller - * @Type(T) - * @ValueType(V) - * @return a CustomLinkedOpenHashMap thats copies the contents of the provided map - * @note the map will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE createCustomLinkedMap(Map map, STRATEGY KEY_GENERIC_TYPE strategy) { - return new LINKED_CUSTOM_HASH_MAPKV_BRACES(map, strategy); - } - - /** - * Helper function to unify code - * @Type(T) - * @ValueType(V) - * @return a RBTreeMap - */ - public static GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE createRBTreeMap() { - return new RB_TREE_MAPKV_BRACES(); - } - - /** - * Helper function to unify code - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @return a RBTreeMap - */ - public static GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE createRBTreeMap(COMPARATOR KEY_GENERIC_TYPE comp) { - return new RB_TREE_MAPKV_BRACES(comp); - } - - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a RBTreeMap thats contains the injected values - */ - public static GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE createRBTreeMap(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { - return new RB_TREE_MAPKV_BRACES(keys, values, comp); - } - - #if !TYPE_OBJECT || !VALUE_OBJECT - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a RBTreeMap thats contains the injected values - * @note the keys and values will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE createRBTreeMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { - return new RB_TREE_MAPKV_BRACES(keys, values, comp); - } - - #endif - /** - * Helper function to unify code - * @param map that should be cloned - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @return a RBTreeMap thats copies the contents of the provided map - */ - public static GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE createRBTreeMap(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) { - return new RB_TREE_MAPKV_BRACES(map, comp); - } - - /** - * Helper function to unify code - * @param map that should be cloned - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @return a RBTreeMap thats copies the contents of the provided map - * @note the map will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES RB_TREE_MAP KEY_VALUE_GENERIC_TYPE createRBTreeMap(Map map, COMPARATOR KEY_GENERIC_TYPE comp) { - return new RB_TREE_MAPKV_BRACES(map, comp); - } - - /** - * Helper function to unify code - * @Type(T) - * @ValueType(V) - * @return a AVLTreeMap - */ - public static GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE createAVLTreeMap() { - return new AVL_TREE_MAPKV_BRACES(); - } - - /** - * Helper function to unify code - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @return a AVLTreeMap - */ - public static GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE createAVLTreeMap(COMPARATOR KEY_GENERIC_TYPE comp) { - return new AVL_TREE_MAPKV_BRACES(comp); - } - - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a AVLTreeMap thats contains the injected values - */ - public static GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE createAVLTreeMap(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { - return new AVL_TREE_MAPKV_BRACES(keys, values, comp); - } - - #if !TYPE_OBJECT || !VALUE_OBJECT - /** - * Helper function to unify code - * @param keys the keys that should be inserted - * @param values the values that should be inserted - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @throws IllegalStateException if the keys and values do not match in length - * @return a AVLTreeMap thats contains the injected values - * @note the keys and values will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE createAVLTreeMap(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) { - return new AVL_TREE_MAPKV_BRACES(keys, values, comp); - } - - #endif - /** - * Helper function to unify code - * @param map that should be cloned - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @return a AVLTreeMap thats copies the contents of the provided map - */ - public static GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE createAVLTreeMap(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) { - return new AVL_TREE_MAPKV_BRACES(map, comp); - } - - /** - * Helper function to unify code - * @param map that should be cloned - * @param comp the Sorter of the TreeMap - * @Type(T) - * @ValueType(V) - * @return a AVLTreeMap thats copies the contents of the provided map - * @note the map will be unboxed - */ - public static GENERIC_KEY_VALUE_BRACES AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE createAVLTreeMap(Map map, COMPARATOR KEY_GENERIC_TYPE comp) { - return new AVL_TREE_MAPKV_BRACES(map, comp); - } - #endif } \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/NavigableMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/NavigableMap.template index 3154468a..5e6bfb14 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/NavigableMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/NavigableMap.template @@ -2,6 +2,7 @@ package speiger.src.collections.PACKAGE.maps.interfaces; import java.util.NavigableMap; import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET; +import speiger.src.collections.PACKAGE.utils.maps.MAPS; /** * A Type Specific Navigable Map interface with a couple helper methods @@ -34,6 +35,28 @@ public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VAL @Override public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry(); + /** + * Creates a Wrapped NavigableMap that is Synchronized + * @return a new NavigableMap that is synchronized + * @see MAPS#synchronize + */ + public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); } + + /** + * Creates a Wrapped NavigableMap that is Synchronized + * @param mutex is the controller of the synchronization block + * @return a new NavigableMap Wrapper that is synchronized + * @see MAPS#synchronize + */ + public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); } + + /** + * Creates a Wrapped NavigableMap that is unmodifiable + * @return a new NavigableMap Wrapper that is unmodifiable + * @see MAPS#unmodifiable + */ + public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); } + #if !TYPE_OBJECT /** * A Type Specific SubMap method to reduce boxing/unboxing diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template index 72c070f6..56e07f97 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template @@ -10,6 +10,7 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION; import speiger.src.collections.PACKAGE.functions.COMPARATOR; #endif import speiger.src.collections.PACKAGE.sets.SET; +import speiger.src.collections.PACKAGE.utils.maps.MAPS; import speiger.src.collections.objects.sets.ObjectSortedSet; import speiger.src.collections.objects.collections.ObjectBidirectionalIterator; @@ -83,6 +84,28 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input); +#if TYPE_OBJECT + /** + * A Helper function that simplifies the process of creating a new Array. + * @param action the array creation function + * @return an array containing all of the elements in this collection + * @see Collection#toArray(Object[]) + */ + default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction action) { + return TO_ARRAY(action.get(size())); + } +#endif } \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/NavigableSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/NavigableSet.template index 185a5aeb..eae0579f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/NavigableSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/NavigableSet.template @@ -4,6 +4,7 @@ import java.util.NavigableSet; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; +import speiger.src.collections.PACKAGE.utils.SETS; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; /** @@ -118,6 +119,30 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet @Override public NAVIGABLE_SET KEY_GENERIC_TYPE copy(); +#if !TYPE_BOOLEAN + /** + * Creates a Wrapped NavigableSet that is Synchronized + * @return a new NavigableSet that is synchronized + * @see SETS#synchronize + */ + public default NAVIGABLE_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); } + + /** + * Creates a Wrapped NavigableSet that is Synchronized + * @param mutex is the controller of the synchronization block + * @return a new NavigableSet Wrapper that is synchronized + * @see SETS#synchronize + */ + public default NAVIGABLE_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); } + + /** + * Creates a Wrapped NavigableSet that is unmodifiable + * @return a new NavigableSet Wrapper that is unmodifiable + * @see SETS#unmodifiable + */ + public default NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); } + +#endif /** * A Type Specific Type Splititerator to reduce boxing/unboxing * @return type specific splititerator diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/Set.template b/src/builder/resources/speiger/assets/collections/templates/sets/Set.template index 80b37ebe..b3fed68a 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/Set.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/Set.template @@ -5,8 +5,12 @@ import java.util.Set; import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; +#if !TYPE_BOOLEAN +import speiger.src.collections.PACKAGE.utils.SETS; +#endif import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; + /** * A Type Specific Set class to reduce boxing/unboxing * @Type(T) @@ -49,6 +53,31 @@ public interface SET KEY_GENERIC_TYPE extends Set, COLLECTION KEY_GE public default boolean remove(Object o) { return COLLECTION.super.remove(o); } + +#endif +#if !TYPE_BOOLEAN + /** + * Creates a Wrapped Set that is Synchronized + * @return a new Set that is synchronized + * @see SETS#synchronize + */ + public default SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); } + + /** + * Creates a Wrapped Set that is Synchronized + * @param mutex is the controller of the synchronization block + * @return a new Set Wrapper that is synchronized + * @see SETS#synchronize + */ + public default SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); } + + /** + * Creates a Wrapped Set that is unmodifiable + * @return a new Set Wrapper that is unmodifiable + * @see SETS#unmodifiable + */ + public default SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); } + #endif /** * A Type Specific Type Splititerator to reduce boxing/unboxing diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template index 152ee7b6..ea4b683a 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template @@ -9,6 +9,7 @@ import java.util.Comparator; #else import speiger.src.collections.PACKAGE.functions.COMPARATOR; #endif +import speiger.src.collections.PACKAGE.utils.SETS; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; /** @@ -73,6 +74,30 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte */ public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement); +#if !TYPE_BOOLEAN + /** + * Creates a Wrapped SortedSet that is Synchronized + * @return a new SortedSet that is synchronized + * @see SETS#synchronize + */ + public default SORTED_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); } + + /** + * Creates a Wrapped SortedSet that is Synchronized + * @param mutex is the controller of the synchronization block + * @return a new SortedSet Wrapper that is synchronized + * @see SETS#synchronize + */ + public default SORTED_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); } + + /** + * Creates a Wrapped SortedSet that is unmodifiable + * @return a new SortedSet Wrapper that is unmodifiable + * @see SETS#unmodifiable + */ + public default SORTED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); } + +#endif /** * A Type Specific Type Splititerator to reduce boxing/unboxing * @return type specific splititerator diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template b/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template index 9b4173b1..2045a766 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template @@ -134,7 +134,7 @@ public class COLLECTIONS } @Override - public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public COLLECTION KEY_GENERIC_TYPE copy() { synchronized(mutex) { return c.copy(); } } @Override @Primitive @@ -254,7 +254,7 @@ public class COLLECTIONS @Override public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(c.iterator()); } @Override - public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public COLLECTION KEY_GENERIC_TYPE copy() { return c.copy(); } @Override @Deprecated public boolean remove(Object o) { throw new UnsupportedOperationException(); } diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Lists.template b/src/builder/resources/speiger/assets/collections/templates/utils/Lists.template index a8f4eeaa..d5346624 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Lists.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Lists.template @@ -388,14 +388,14 @@ public class LISTS @Override public LIST KEY_GENERIC_TYPE subList(int from, int to) { - return synchronize(l.subList(from, to)); + return LISTS.synchronize(l.subList(from, to)); } @Override public void size(int size) { synchronized(mutex) { l.size(size); } } @Override - public LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public LIST KEY_GENERIC_TYPE copy() { synchronized(mutex) { return l.copy(); } } } private static class UnmodifiableRandomList KEY_GENERIC_TYPE extends UnmodifiableList KEY_GENERIC_TYPE implements RandomAccess @@ -510,14 +510,14 @@ public class LISTS @Override public LIST KEY_GENERIC_TYPE subList(int from, int to) { - return unmodifiable(l.subList(from, to)); + return LISTS.unmodifiable(l.subList(from, to)); } @Override public void size(int size) { throw new UnsupportedOperationException(); } @Override - public LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public LIST KEY_GENERIC_TYPE copy() { return l.copy(); } } private static class EmptyList KEY_GENERIC_TYPE extends COLLECTIONS.EmptyCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template b/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template index 25b20cb7..61f7d325 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template @@ -117,7 +117,7 @@ public class PRIORITY_QUEUES @Override public GENERIC_SPECIAL_KEY_BRACES KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } } @Override - public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return queue.copy(); } } @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } } @Override @@ -164,6 +164,6 @@ public class PRIORITY_QUEUES @Override public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } } @Override - public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return dequeue.copy(); } } } } diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template b/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template index 2f545981..057bad01 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template @@ -254,28 +254,28 @@ public class SETS public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); } + public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return SETS.unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return unmodifiable(n.headSet(toElement, inclusive)); } + public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return SETS.unmodifiable(n.headSet(toElement, inclusive)); } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return unmodifiable(n.tailSet(fromElement, inclusive)); } + public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return SETS.unmodifiable(n.tailSet(fromElement, inclusive)); } @Override public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { return ITERATORS.unmodifiable(n.descendingIterator()); } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return unmodifiable(n.descendingSet()); } + public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return SETS.unmodifiable(n.descendingSet()); } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(n.subSet(fromElement, toElement)); } + public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(n.subSet(fromElement, toElement)); } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(n.headSet(toElement)); } + public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(n.headSet(toElement)); } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(n.tailSet(fromElement)); } + public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); } } private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE @@ -309,16 +309,16 @@ public class SETS public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); } @Override - public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); } @Override - public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(s.subSet(fromElement, toElement)); } + public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); } @Override - public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(s.headSet(toElement)); } + public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); } @Override - public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(s.tailSet(fromElement)); } + public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); } @Override public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); } @@ -348,7 +348,7 @@ public class SETS } @Override - public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public SET KEY_GENERIC_TYPE copy() { return s.copy(); } #if !TYPE_OBJECT @Override @@ -427,31 +427,31 @@ public class SETS #endif @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return n.copy(); } } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } } + public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return SETS.synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return synchronize(n.headSet(toElement, inclusive), mutex); } } + public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return SETS.synchronize(n.headSet(toElement, inclusive), mutex); } } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return synchronize(n.tailSet(fromElement, inclusive), mutex); } } + public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return SETS.synchronize(n.tailSet(fromElement, inclusive), mutex); } } @Override public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { synchronized(mutex) { return n.descendingIterator(); } } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return synchronize(n.descendingSet(), mutex); } } + public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return SETS.synchronize(n.descendingSet(), mutex); } } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(n.subSet(fromElement, toElement), mutex); } } + public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(n.subSet(fromElement, toElement), mutex); } } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronize(n.headSet(toElement), mutex); } } + public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(n.headSet(toElement), mutex); } } @Override - public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronize(n.tailSet(fromElement), mutex); } } + public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(n.tailSet(fromElement), mutex); } } } private static class SynchronizedSortedTrimSet KEY_GENERIC_TYPE extends SynchronizedSortedSet KEY_GENERIC_TYPE implements ITrimmable @@ -511,16 +511,16 @@ public class SETS public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } } @Override - public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } } @Override - public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.subSet(fromElement, toElement), mutex); } } + public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } } @Override - public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.headSet(toElement), mutex); } } + public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } } @Override - public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronize(s.tailSet(fromElement), mutex); } } + public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } } @Override public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } } @@ -558,26 +558,20 @@ public class SETS private static class SynchronizedSet KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE { -#if !TYPE_OBJECT SET KEY_GENERIC_TYPE s; -#endif SynchronizedSet(SET KEY_GENERIC_TYPE c) { super(c); -#if !TYPE_OBJECT s = c; -#endif } SynchronizedSet(SET KEY_GENERIC_TYPE c, Object mutex) { super(c, mutex); -#if !TYPE_OBJECT s = c; -#endif } @Override - public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + public SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } } #if !TYPE_OBJECT @Override diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template b/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template index 81b5f0e7..ccbd4901 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template @@ -368,31 +368,31 @@ public class MAPS } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return synchronize(map.descendingMap()); } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return MAPS.synchronize(map.descendingMap()); } @Override public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { return SETS.unmodifiable(map.navigableKeySet()); } @Override public NAVIGABLE_SET KEY_GENERIC_TYPE descendingKeySet() { return SETS.unmodifiable(map.descendingKeySet()); } @Override - public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return unmodifiable(map.firstEntry()); } + public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return MAPS.unmodifiable(map.firstEntry()); } @Override - public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return unmodifiable(map.lastEntry()); } + public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return MAPS.unmodifiable(map.lastEntry()); } @Override public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { throw new UnsupportedOperationException(); } @Override public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { throw new UnsupportedOperationException(); } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { return unmodifiable(map.subMap(fromKey, fromInclusive, toKey, toInclusive)); } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { return MAPS.unmodifiable(map.subMap(fromKey, fromInclusive, toKey, toInclusive)); } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { return unmodifiable(map.headMap(toKey, inclusive)); } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { return MAPS.unmodifiable(map.headMap(toKey, inclusive)); } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { return unmodifiable(map.tailMap(fromKey, inclusive)); } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { return MAPS.unmodifiable(map.tailMap(fromKey, inclusive)); } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return unmodifiable(map.subMap(fromKey, toKey)); } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return unmodifiable(map.headMap(toKey)); } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return MAPS.unmodifiable(map.headMap(toKey)); } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return unmodifiable(map.tailMap(fromKey)); } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); } #if !TYPE_OBJECT @Override public void setDefaultMaxValue(KEY_TYPE e) { throw new UnsupportedOperationException(); } @@ -412,13 +412,13 @@ public class MAPS @Override public KEY_TYPE ceilingKey(KEY_TYPE key) { return map.ceilingKey(key); } @Override - public MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(KEY_TYPE key) { return unmodifiable(map.lowerEntry(key)); } + public MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.lowerEntry(key)); } @Override - public MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(KEY_TYPE key) { return unmodifiable(map.higherEntry(key)); } + public MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.higherEntry(key)); } @Override - public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { return unmodifiable(map.floorEntry(key)); } + public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.floorEntry(key)); } @Override - public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return unmodifiable(map.ceilingEntry(key)); } + public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.ceilingEntry(key)); } @Override public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } } @@ -451,11 +451,11 @@ public class MAPS @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); } @Override - public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return unmodifiable(map.subMap(fromKey, toKey)); } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); } @Override - public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return unmodifiable(map.headMap(toKey)); } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return MAPS.unmodifiable(map.headMap(toKey)); } @Override - public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return unmodifiable(map.tailMap(fromKey)); } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); } @Override public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); } @Override @@ -548,7 +548,7 @@ public class MAPS @Override public void forEach(Consumer action) { - s.forEach(T -> action.accept(unmodifiable(T))); + s.forEach(T -> action.accept(MAPS.unmodifiable(T))); } @Override @@ -558,7 +558,7 @@ public class MAPS @Override public boolean hasNext() { return iter.hasNext(); } @Override - public MAP.Entry KEY_VALUE_GENERIC_TYPE next() { return unmodifiable(iter.next()); } + public MAP.Entry KEY_VALUE_GENERIC_TYPE next() { return MAPS.unmodifiable(iter.next()); } }; } @@ -583,7 +583,7 @@ public class MAPS } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { synchronized(mutex) { return synchronize(map.descendingMap(), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { synchronized(mutex) { return MAPS.synchronize(map.descendingMap(), mutex); } } @Override public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { synchronized(mutex) { return SETS.synchronize(map.navigableKeySet(), mutex); } } @Override @@ -597,17 +597,17 @@ public class MAPS @Override public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { synchronized(mutex) { return map.pollLastEntry(); } } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.headMap(toKey, inclusive), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey, inclusive), mutex); } } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.tailMap(fromKey, inclusive), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey, inclusive), mutex); } } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } } @Override - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } } @Override public KEY_TYPE lowerKey(KEY_TYPE key) { synchronized(mutex) { return map.lowerKey(key); } } @Override @@ -629,22 +629,22 @@ public class MAPS #if !TYPE_OBJECT @Override @Deprecated - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } } @Override @Deprecated - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.headMap(toKey, inclusive), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey, inclusive), mutex); } } @Override @Deprecated - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.tailMap(fromKey, inclusive), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey, inclusive), mutex); } } @Override @Deprecated - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } } @Override @Deprecated - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } } @Override @Deprecated - public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } } + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } } @Override public void setDefaultMaxValue(KEY_TYPE e) { synchronized(mutex) { map.setDefaultMaxValue(e); } } @Override @@ -713,11 +713,11 @@ public class MAPS @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { synchronized(mutex) { return map.comparator(); } } @Override - public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } } @Override - public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } } @Override - public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } } @Override public KEY_TYPE FIRST_ENTRY_KEY() { synchronized(mutex) { return map.FIRST_ENTRY_KEY(); } } @Override @@ -741,13 +741,13 @@ public class MAPS public CLASS_TYPE lastKey() { synchronized(mutex) { return map.lastKey(); } } @Override @Deprecated - public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } } @Override @Deprecated - public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } } @Override @Deprecated - public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } } + public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } } #endif }