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