Primitive-Collections/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/Map.template

1720 lines
62 KiB
Plaintext

package speiger.src.collections.PACKAGE.maps.interfaces;
import java.util.Map;
import java.util.Objects;
#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 VALUE_BOOLEAN && JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
#if TYPE_OBJECT
#if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE
import java.util.Comparator;
#endif
#endif
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
#if !VALUE_BOOLEAN || !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
#endif
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !TYPE_OBJECT && !TYPE_BOOLEAN && SORTED_MAP_FEATURE
#if AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif
#endif
#if !TYPE_BOOLEAN
#if LINKED_CUSTOM_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.customHash.LINKED_CUSTOM_HASH_MAP;
#endif
#if CUSTOM_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.customHash.CUSTOM_HASH_MAP;
#endif
#if LINKED_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP;
#endif
#if MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.hash.HASH_MAP;
#endif
#if IMMUTABLE_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.immutable.IMMUTABLE_HASH_MAP;
#endif
#if AVL_TREE_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP;
#endif
#if RB_TREE_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP;
#endif
#if ARRAY_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP;
#endif
#if CONCURRENT_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP;
#endif
#if TYPE_OBJECT
#if ENUM_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
#endif
#if LINKED_ENUM_MAP_FEATURE
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
#endif
#endif
import speiger.src.collections.objects.collections.ObjectIterable;
#if CUSTOM_MAP_FEATURE || LINKED_CUSTOM_MAP_FEATURE
import speiger.src.collections.PACKAGE.utils.STRATEGY;
#endif
#if MAPS_FEATURE
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
#endif
#endif
import speiger.src.collections.PACKAGE.sets.SET;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
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
* and some extra helper functions.
* @Type(T)
* @ValueType(V)
*/
public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_TYPE>, 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
*/
public VALUE_TYPE getDefaultReturnValue();
/**
* Method to define the default return value if a requested key isn't present
* @param v value that should be the default return value
* @return itself
*/
public MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v);
/**
* A Function that does a shallow clone of the Map itself.
* This function is more optimized then a copy constructor since the Map does not have to be unsorted/resorted.
* It can be compared to Cloneable but with less exception risk
* @return a Shallow Copy of the Map
* @note Wrappers and view Maps will not support this feature
*/
public MAP KEY_VALUE_GENERIC_TYPE copy();
/**
* Type Specific method to reduce boxing/unboxing of values
* @param key the key that should be inserted,
* @param value the value that should be inserted
* @return the last present value or default return value.
* @see Map#put(Object, Object)
*/
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value);
/**
* A Helper method that allows to put int a MAP.Entry into a map.
* @param entry then Entry that should be inserted.
* @return the last present value or default return value.
*/
public default VALUE_TYPE put(Entry KEY_VALUE_GENERIC_TYPE entry) {
return put(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
}
#if !TYPE_OBJECT || !VALUE_OBJECT
/**
* A Helper method that allows to put int a Map.Entry into a map.
* @param entry then Entry that should be inserted.
* @return the last present value or default return value.
*/
public default CLASS_VALUE_TYPE put(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) {
return put(entry.getKey(), entry.getValue());
}
#endif
/**
* Type Specific array method to bulk add elements into a map without creating a wrapper and increasing performances
* @param keys the keys that should be added
* @param values the values that should be added
* @see Map#putAll(Map)
* @throws IllegalStateException if the arrays are not the same size
*/
public default void putAll(KEY_TYPE[] keys, VALUE_TYPE[] values) {
if(keys.length != values.length) throw new IllegalStateException("Array sizes do not match");
putAll(keys, values, 0, keys.length);
}
/**
* Type Specific array method to bulk add elements into a map without creating a wrapper and increasing performances
* @param keys the keys that should be added
* @param values the values that should be added
* @param offset where the to start in the array
* @param size how many elements should be added
* @see Map#putAll(Map)
* @throws IllegalStateException if the arrays are not within the range
*/
public void putAll(KEY_TYPE[] keys, VALUE_TYPE[] values, int offset, int size);
#if !TYPE_OBJECT || !VALUE_OBJECT
/**
* Type Specific Object array method to bulk add elements into a map without creating a wrapper and increasing performances
* @param keys the keys that should be added
* @param values the values that should be added
* @see Map#putAll(Map)
* @throws IllegalStateException if the arrays are not the same size
*/
public default void putAll(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
if(keys.length != values.length) throw new IllegalStateException("Array sizes do not match");
putAll(keys, values, 0, keys.length);
}
/**
* Type Specific Object array method to bulk add elements into a map without creating a wrapper and increasing performances
* @param keys the keys that should be added
* @param values the values that should be added
* @param offset where the to start in the array
* @param size how many elements should be added
* @see Map#putAll(Map)
* @throws IllegalStateException if the arrays are not within the range
*/
public void putAll(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int offset, int size);
#endif
/**
* Type Specific method to reduce boxing/unboxing of values
* @param key the key that should be inserted,
* @param value the value that should be inserted
* @return the last present value or default return value.
* @see Map#putIfAbsent(Object, Object)
*/
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value);
/**
* Type-Specific bulk put method put elements into the map if not present.
* @param m elements that should be added if not present.
*/
public void putAllIfAbsent(MAP KEY_VALUE_GENERIC_TYPE m);
#if VALUE_PRIMITIVES
/**
* A Helper method to add a primitives together. If key is not present then this functions as a put.
* @param key the key that should be inserted,
* @param value the value that should be inserted / added
* @return the last present value or default return value.
*/
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value);
/**
* A Helper method to bulk add primitives together.
* @param m the values that should be added/inserted
*/
public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m);
/**
* A Helper method to subtract from primitive from each other. If the key is not present it will just return the defaultValue
* How the implementation works is that it will subtract from the current value (if not present it will do nothing) and fence it to the {@link #getDefaultReturnValue()}
* If the fence is reached the element will be automaticall removed
*
* @param key that should be subtract from
* @param value that should be subtract
* @return the last present or default return value
*/
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value);
#endif
/**
* Type Specific function for the bull putting of values
* @param m the elements that should be inserted
*/
public void putAll(MAP KEY_VALUE_GENERIC_TYPE m);
#if !TYPE_OBJECT
/**
* Type Specific method to reduce boxing/unboxing of values
* @param key element that is searched for
* @return if the key is present
*/
public boolean containsKey(KEY_TYPE key);
/**
* @see Map#containsKey(Object)
* @param key that is searched for.
* @return true if found
* @note in some implementations key does not have to be CLASS_TYPE but just have to support equals with CLASS_TYPE.
*/
@Override
public default boolean containsKey(Object key) {
return key instanceof CLASS_TYPE && containsKey(CLASS_TO_KEY(key));
}
#endif
#if !VALUE_OBJECT
/**
* Type Specific method to reduce boxing/unboxing of values
* @param value element that is searched for
* @return if the value is present
*/
public boolean containsValue(VALUE_TYPE value);
/**
* @see Map#containsValue(Object)
* @param value that is searched for.
* @return true if found
* @note in some implementations key does not have to be CLASS_VALUE but just have to support equals with CLASS_VALUE.
*/
@Override
public default boolean containsValue(Object value) {
return value instanceof CLASS_VALUE_TYPE && containsValue(CLASS_TO_VALUE(value));
}
#endif
/**
* Type Specific remove function to reduce boxing/unboxing
* @param key the element that should be removed
* @return the value that was removed or default return value
*/
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key);
/**
* @see Map#remove(Object)
* @param key the element that should be removed
* @return the value that was removed or default return value
* @note in some implementations key does not have to be CLASS_TYPE but just have to support equals with CLASS_TYPE.
*/
@Override
public default CLASS_VALUE_TYPE remove(Object key) {
#if TYPE_OBJECT
return VALUE_TO_OBJ(REMOVE_VALUE((CLASS_TYPE)key));
#else
return key instanceof CLASS_TYPE ? VALUE_TO_OBJ(REMOVE_VALUE(CLASS_TO_KEY(key))) : VALUE_TO_OBJ(getDefaultReturnValue());
#endif
}
#if !TYPE_OBJECT || !VALUE_OBJECT
/**
* Type Specific remove function to reduce boxing/unboxing
* @param key the element that should be removed
* @param value the expected value that should be found
* @return true if the key and value was found and removed
* @see Map#remove(Object, Object)
*/
public boolean remove(KEY_TYPE key, VALUE_TYPE value);
/**
* @see Map#remove(Object, Object)
* @param key the element that should be removed
* @param value the expected value that should be found
* @return true if the key and value was found and removed
*/
@Override
public default boolean remove(Object key, Object value) {
#if TYPE_OBJECT
return value instanceof CLASS_VALUE_TYPE && remove((KEY_TYPE)key, CLASS_TO_VALUE(value));
#else if VALUE_OBJECT
return key instanceof CLASS_TYPE && remove(CLASS_TO_KEY(key), (VALUE_TYPE)value);
#else
return key instanceof CLASS_TYPE && value instanceof CLASS_VALUE_TYPE && remove(CLASS_TO_KEY(key), CLASS_TO_VALUE(value));
#endif
}
#endif
/**
* Type-Specific Remove function with a default return value if wanted.
* @see Map#remove(Object, Object)
* @param key the element that should be removed
* @param defaultValue the value that should be returned if the entry doesn't exist
* @return the value that was removed or default value
*/
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue);
/**
* A Type Specific replace method to replace an existing value
* @param key the element that should be searched for
* @param oldValue the expected value to be replaced
* @param newValue the value to replace the oldValue with.
* @return true if the value got replaced
* @note this fails if the value is not present even if it matches the oldValue
*/
public boolean replace(KEY_TYPE key, VALUE_TYPE oldValue, VALUE_TYPE newValue);
/**
* A Type Specific replace method to reduce boxing/unboxing replace an existing value
* @param key the element that should be searched for
* @param value the value to replace with.
* @return the present value or default return value
* @note this fails if the value is not present
*/
public VALUE_TYPE replace(KEY_TYPE key, VALUE_TYPE value);
/**
* Type-Specific bulk replace method. Could be seen as putAllIfPresent
* @param m elements that should be replaced.
*/
public void REPLACE_VALUES(MAP KEY_VALUE_GENERIC_TYPE m);
/**
* A Type Specific mass replace method to reduce boxing/unboxing
* @param mappingFunction operation to replace all values
*/
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Type Specific compute method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value
* @return the result of the computation
*/
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value if not present
* @return the result of the computed value or present value
*/
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param valueProvider the value if not present
* @return the result of the computed value or present value
*/
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
/**
* A Type Specific compute method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value if present
* @return the result of the default return value or present value
* @note if not present then compute is not executed
*/
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
#if !VALUE_OBJECT
/**
* A Type Specific compute method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value
* @return the result of the computation
*/
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value if not present
* @return the result of the computed value or present value
*/
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param valueProvider the value if not present
* @return the result of the computed value or present value
*/
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
/**
* A Type Specific compute method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value if present
* @return the result of the default return value or present value
* @note if not present then compute is not executed
*/
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
#endif
/**
* A Type Specific merge method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be be searched for
* @param value the value that should be merged with
* @param mappingFunction the operator that should generate the new Value
* @return the result of the merge
* @note if the result matches the default return value then the key is removed from the map
*/
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Bulk method for merging Maps.
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param m the entries that should be bulk added
* @param mappingFunction the operator that should generate the new Value
* @note if the result matches the default return value then the key is removed from the map
*/
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction);
#if !TYPE_OBJECT || !VALUE_OBJECT
@Override
@Primitive
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
return replace(OBJ_TO_KEY(key), OBJ_TO_VALUE(oldValue), OBJ_TO_VALUE(newValue));
}
@Override
@Primitive
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
return VALUE_TO_OBJ(replace(OBJ_TO_KEY(key), OBJ_TO_VALUE(value)));
}
#endif
@Override
public default VALUE_TYPE APPLY(KEY_TYPE key) {
return GET_VALUE(key);
}
/**
* A Type Specific get method to reduce boxing/unboxing
* @param key the key that is searched for
* @return the searched value or default return value
*/
public VALUE_TYPE GET_VALUE(KEY_TYPE key);
#if !TYPE_OBJECT || !VALUE_OBJECT
/**
* A Type Specific getOrDefault method to reduce boxing/unboxing
* @param key the key that is searched for
* @param defaultValue the value that should be returned if the key is not present
* @return the searched value or defaultValue value
*/
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue);
@Override
@Primitive
public default CLASS_VALUE_TYPE get(Object key) {
#if TYPE_OBJECT
return VALUE_TO_OBJ(GET_VALUE((CLASS_TYPE)key));
#else
return VALUE_TO_OBJ(key instanceof CLASS_TYPE ? GET_VALUE(CLASS_TO_KEY(key)) : getDefaultReturnValue());
#endif
}
@Override
@Primitive
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
#if TYPE_OBJECT
CLASS_VALUE_TYPE value = VALUE_TO_OBJ(GET_VALUE((CLASS_TYPE)key));
#else
CLASS_VALUE_TYPE value = VALUE_TO_OBJ(key instanceof CLASS_TYPE ? GET_VALUE(CLASS_TO_KEY(key)) : getDefaultReturnValue());
#endif
return VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key) ? value : defaultValue;
}
#endif
@Override
@Primitive
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
Objects.requireNonNull(mappingFunction);
REPLACE_VALUES(mappingFunction instanceof UNARY_OPERATOR ? (UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE)mappingFunction : (K, V) -> OBJ_TO_VALUE(mappingFunction.apply(KEY_TO_OBJ(K), VALUE_TO_OBJ(V))));
}
@Override
@Primitive
public default CLASS_VALUE_TYPE compute(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
Objects.requireNonNull(mappingFunction);
return VALUE_TO_OBJ(COMPUTE(OBJ_TO_KEY(key), mappingFunction instanceof UNARY_OPERATOR ? (UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE)mappingFunction : (K, V) -> OBJ_TO_VALUE(mappingFunction.apply(KEY_TO_OBJ(K), VALUE_TO_OBJ(V)))));
}
@Override
@Primitive
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
Objects.requireNonNull(mappingFunction);
return VALUE_TO_OBJ(COMPUTE_IF_ABSENT(OBJ_TO_KEY(key), mappingFunction instanceof FUNCTION ? (FUNCTION KEY_VALUE_GENERIC_TYPE)mappingFunction : K -> OBJ_TO_VALUE(mappingFunction.apply(KEY_TO_OBJ(K)))));
}
@Override
@Primitive
public default CLASS_VALUE_TYPE computeIfPresent(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
Objects.requireNonNull(mappingFunction);
return VALUE_TO_OBJ(COMPUTE_IF_PRESENT(OBJ_TO_KEY(key), mappingFunction instanceof UNARY_OPERATOR ? (UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE)mappingFunction : (K, V) -> OBJ_TO_VALUE(mappingFunction.apply(KEY_TO_OBJ(K), VALUE_TO_OBJ(V)))));
}
@Override
@Primitive
public default CLASS_VALUE_TYPE merge(CLASS_TYPE key, CLASS_VALUE_TYPE value, BiFunction<? super CLASS_VALUE_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if VALUE_OBJECT
Objects.requireNonNull(value);
#endif
return VALUE_TO_OBJ(MERGE(OBJ_TO_KEY(key), OBJ_TO_VALUE(value), mappingFunction instanceof VALUE_UNARY_OPERATOR ? (VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE)mappingFunction : (K, V) -> OBJ_TO_VALUE(mappingFunction.apply(VALUE_TO_OBJ(K), VALUE_TO_OBJ(V)))));
}
/**
* Type Specific forEach method to reduce boxing/unboxing
* @param action processor of the values that are iterator over
*/
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action);
@Override
@Primitive
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
Objects.requireNonNull(action);
forEach(action instanceof BI_CONSUMER ? (BI_CONSUMER KEY_VALUE_GENERIC_TYPE)action : (K, V) -> action.accept(KEY_TO_OBJ(K), VALUE_TO_OBJ(V)));
}
@Override
public SET KEY_GENERIC_TYPE keySet();
@Override
public VALUE_COLLECTION VALUE_GENERIC_TYPE values();
@Override
@Primitive
public ObjectSet<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> entrySet();
/**
* Type Sensitive EntrySet to reduce boxing/unboxing and optionally Temp Object Allocation.
* @return a EntrySet of the collection
*/
public ObjectSet<Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
#if MAPS_FEATURE
/**
* 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
public default CLASS_VALUE_TYPE put(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
return VALUE_TO_OBJ(put(OBJ_TO_KEY(key), OBJ_TO_VALUE(value)));
}
@Override
@Primitive
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
return VALUE_TO_OBJ(put(OBJ_TO_KEY(key), OBJ_TO_VALUE(value)));
}
#endif
/**
* Fast Entry set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
* @Type(T)
* @ValueType(V)
*/
public interface FastEntrySet KEY_VALUE_GENERIC_TYPE extends ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>
{
/**
* Fast iterator that recycles the given Entry object to improve speed and reduce object allocation
* @return a Recycling ObjectIterator of the given set
*/
public ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
/**
* Fast for each that recycles the given Entry object to improve speed and reduce object allocation
* @param action the action that should be applied to each given entry
*/
public default void fastForEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
forEach(action);
}
}
/**
* Type Specific Map Entry that reduces boxing/unboxing
* @Type(T)
* @ValueType(V)
*/
public interface Entry KEY_VALUE_GENERIC_TYPE extends Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>
{
#if !TYPE_OBJECT
/**
* Type Specific getKey method that reduces boxing/unboxing
* @return the key of a given Entry
*/
public KEY_TYPE ENTRY_KEY();
public default CLASS_TYPE getKey() { return KEY_TO_OBJ(ENTRY_KEY()); }
#endif
#if !VALUE_OBJECT
/**
* Type Specific getValue method that reduces boxing/unboxing
* @return the value of a given Entry
*/
public VALUE_TYPE ENTRY_VALUE();
/**
* Type Specific setValue method that reduces boxing/unboxing
* @param value the new Value that should be placed in the given entry
* @return the old value of a given entry
* @throws UnsupportedOperationException if the Entry is immutable or not supported
*/
public VALUE_TYPE setValue(VALUE_TYPE value);
@Override
public default CLASS_VALUE_TYPE getValue() { return VALUE_TO_OBJ(ENTRY_VALUE()); }
@Override
public default CLASS_VALUE_TYPE setValue(CLASS_VALUE_TYPE value) { return VALUE_TO_OBJ(setValue(OBJ_TO_VALUE(value))); }
#endif
}
#if !TYPE_BOOLEAN
/**
* Helper class that reduces the method spam of the Map Class.
*/
public static final class MapBuilder
{
static final MapBuilder INSTANCE = new MapBuilder();
/**
* Starts a Map Builder that allows you to create maps as Constants a lot easier
* Keys and Values are stored as Array and then inserted using the putAllMethod when the mapType is choosen
* @Type(T)
* @ValueType(V)
* @return a MapBuilder
*/
public GENERIC_KEY_VALUE_BRACES BuilderCache KEY_VALUE_GENERIC_TYPE start() {
return new BuilderCache KEY_VALUE_GENERIC_TYPE();
}
/**
* Starts a Map Builder that allows you to create maps as Constants a lot easier
* Keys and Values are stored as Array and then inserted using the putAllMethod when the mapType is choosen
* @param size the expected minimum size of Elements in the Map, default is 16
* @Type(T)
* @ValueType(V)
* @return a MapBuilder
*/
public GENERIC_KEY_VALUE_BRACES BuilderCache KEY_VALUE_GENERIC_TYPE start(int size) {
return new BuilderCache KEY_VALUE_GENERIC_TYPE(size);
}
/**
* Starts a Map builder and puts in the Key and Value into it
* Keys and Values are stored as Array and then inserted using the putAllMethod when the mapType is choosen
* @param key the key that should be added
* @param value the value that should be added
* @Type(T)
* @ValueType(V)
* @return a MapBuilder with the key and value stored in it.
*/
public GENERIC_KEY_VALUE_BRACES BuilderCache KEY_VALUE_GENERIC_TYPE put(KEY_TYPE key, VALUE_TYPE value) {
return new BuilderCache KEY_VALUE_GENERIC_TYPE().put(key, value);
}
#if !TYPE_OBJECT || !VALUE_OBJECT
/**
* Starts a Map builder and puts in the Key and Value into it
* Keys and Values are stored as Array and then inserted using the putAllMethod when the mapType is choosen
* @param key the key that should be added
* @param value the value that should be added
* @Type(T)
* @ValueType(V)
* @return a MapBuilder with the key and value stored in it.
*/
public GENERIC_KEY_VALUE_BRACES BuilderCache KEY_VALUE_GENERIC_TYPE put(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
return new BuilderCache KEY_VALUE_GENERIC_TYPE().put(key, value);
}
#endif
#if MAP_FEATURE
/**
* Helper function to unify code
* @Type(T)
* @ValueType(V)
* @return a OpenHashMap
*/
public GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE map() {
return new HASH_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 HASH_MAP KEY_VALUE_GENERIC_TYPE map(int size) {
return new 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 OpenHashMap thats contains the injected values
*/
public GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE map(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 GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE map(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 GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE map(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 GENERIC_KEY_VALUE_BRACES HASH_MAP KEY_VALUE_GENERIC_TYPE map(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
return new HASH_MAPKV_BRACES(map);
}
#endif
#if LINKED_MAP_FEATURE
/**
* 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
return new IMMUTABLE_HASH_MAPKV_BRACES(map);
}
#endif
#if IMMUTABLE_MAP_FEATURE
/**
* 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
return new IMMUTABLE_HASH_MAPKV_BRACES(map);
}
#endif
#if TYPE_OBJECT
#if ENUM_MAP_FEATURE
/**
* 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<T> 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> 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);
}
#endif
#if LINKED_ENUM_MAP_FEATURE
/**
* 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<T> 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> 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
#endif
#if CUSTOM_MAP_FEATURE
/**
* 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, STRATEGY KEY_GENERIC_TYPE strategy) {
return new CUSTOM_HASH_MAPKV_BRACES(map, strategy);
}
#endif
#if LINKED_CUSTOM_MAP_FEATURE
/**
* 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, STRATEGY KEY_GENERIC_TYPE strategy) {
return new LINKED_CUSTOM_HASH_MAPKV_BRACES(map, strategy);
}
#endif
#if ARRAY_MAP_FEATURE
/**
* 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
return new ARRAY_MAPKV_BRACES(map);
}
#endif
#if RB_TREE_MAP_FEATURE
/**
* 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, COMPARATOR KEY_GENERIC_TYPE comp) {
return new RB_TREE_MAPKV_BRACES(map, comp);
}
#endif
#if AVL_TREE_MAP_FEATURE
/**
* 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, COMPARATOR KEY_GENERIC_TYPE comp) {
return new AVL_TREE_MAPKV_BRACES(map, comp);
}
#endif
}
/**
* 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) {
if(initialSize < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
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) {
#if MAPS_FEATURE
return putAll(MAPS.fastIterable(map));
#else
return putAll(map.ENTRY_SET());
#endif
}
/**
* 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<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
for(Map.Entry<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> 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<MAP.Entry KEY_VALUE_GENERIC_TYPE> c) {
if(c instanceof Collection)
ensureSize(size+((Collection<MAP.Entry KEY_VALUE_GENERIC_TYPE>)c).size());
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : c)
put(entry);
return this;
}
#if MAP_FEATURE || LINKED_MAP_FEATURE || CUSTOM_MAP_FEATURE || LINKED_CUSTOM_MAP_FEATURE || AVL_TREE_MAP_FEATURE || RB_TREE_MAP_FEATURE || CONCURRENT_MAP_FEATURE
private <E extends MAP KEY_VALUE_GENERIC_TYPE> E putElements(E e){
e.putAll(keys, values, 0, size);
return e;
}
#endif
#if MAP_FEATURE
/**
* Builds the Keys and Values into a Hash Map
* @return a HASH_MAP
*/
public HASH_MAP KEY_VALUE_GENERIC_TYPE map() {
return putElements(new HASH_MAPKV_BRACES(size));
}
#endif
#if LINKED_MAP_FEATURE
/**
* Builds the Keys and 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));
}
#endif
#if IMMUTABLE_MAP_FEATURE
/**
* Builds the Keys and 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));
}
#endif
#if CUSTOM_MAP_FEATURE
/**
* Builds the Keys and Values into a Custom Hash Map
* @param strategy the that controls the keys and 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));
}
#endif
#if LINKED_CUSTOM_MAP_FEATURE
/**
* Builds the Keys and Values into a Linked Custom Hash Map
* @param strategy the that controls the keys and 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));
}
#endif
#if CONCURRENT_MAP_FEATURE
/**
* Builds the Keys and Values into a Concurrent Hash Map
* @return a CONCURRENT_HASH_MAP
*/
public CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE concurrentMap() {
return putElements(new CONCURRENT_HASH_MAPKV_BRACES(size));
}
#endif
#if ARRAY_MAP_FEATURE
/**
* Builds the Keys and 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);
}
#endif
#if RB_TREE_MAP_FEATURE
/**
* Builds the Keys and 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 and 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));
}
#endif
#if AVL_TREE_MAP_FEATURE
/**
* Builds the Keys and 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 and 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));
}
#endif
}
#endif
}