Finished first loop of JavaDoc generation.
-Fixed: A couple bugs that were found during javadoc generation. Next loop of javadoc comes later right now i want to add splititerators and streams
This commit is contained in:
+129
@@ -18,27 +18,62 @@ import speiger.src.collections.utils.HashUtil;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
* A Type Specific HashSet 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)
|
||||
*/
|
||||
public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ITrimmable
|
||||
{
|
||||
/** The Backing keys array */
|
||||
protected transient KEY_TYPE[] keys;
|
||||
/** If a null value is present */
|
||||
protected transient boolean containsNull;
|
||||
/** Minimum array size the HashSet 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;
|
||||
|
||||
/** Amount of Elements stored in the HashSet */
|
||||
protected int size;
|
||||
/** How full the Array is 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_SET(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 HashSet 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_SET(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 HashSet 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_SET(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");
|
||||
@@ -50,48 +85,124 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a set from unboxed values
|
||||
* @param array the elements that should be put into the set
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public CUSTOM_HASH_SET(KEY_TYPE[] array, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(array, 0, array.length, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a set from unboxed values
|
||||
* @param array the elements that should be put into the set
|
||||
* @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_SET(KEY_TYPE[] array, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(array, 0, array.length, loadFactor, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a set from unboxed values
|
||||
* @param array the elements that should be put into the set
|
||||
* @param offset the starting index within the array that should be used
|
||||
* @param length the amount of elements used from the array
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if offset and length causes to step outside of the arrays range
|
||||
*/
|
||||
public CUSTOM_HASH_SET(KEY_TYPE[] array, int offset, int length, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(array, offset, length, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a set from unboxed values
|
||||
* @param array the elements that should be put into the set
|
||||
* @param offset the starting index within the array that should be used
|
||||
* @param length the amount of elements used from the array
|
||||
* @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
|
||||
* @throws IllegalStateException if offset and length causes to step outside of the arrays range
|
||||
*/
|
||||
public CUSTOM_HASH_SET(KEY_TYPE[] array, int offset, int length, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(length < 0 ? 0 : length, strategy);
|
||||
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
||||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
|
||||
* @param collection the set the elements should be added to the Set
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
@Deprecated
|
||||
public CUSTOM_HASH_SET(Collection<? extends CLASS_TYPE> collection, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(collection, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
|
||||
* @param collection the set the elements should be added to the Set
|
||||
* @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
|
||||
*/
|
||||
@Deprecated
|
||||
public CUSTOM_HASH_SET(Collection<? extends CLASS_TYPE> collection, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(collection.size(), loadFactor, strategy);
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
|
||||
* @param collection the set the elements should be added to the Set
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public CUSTOM_HASH_SET(COLLECTION KEY_GENERIC_TYPE collection, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(collection, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
|
||||
* @param collection the set the elements should be added to the Set
|
||||
* @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_SET(COLLECTION KEY_GENERIC_TYPE collection, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(collection.size(), strategy);
|
||||
addAll(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a set from a iterator of an unknown size
|
||||
* @param iterator the elements that should be added to the set
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public CUSTOM_HASH_SET(Iterator<CLASS_TYPE> iterator, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(iterator, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a set from a iterator of an unknown size
|
||||
* @param iterator the elements that should be added to the set
|
||||
* @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_SET(Iterator<CLASS_TYPE> iterator, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
#if !TYPE_OBJECT
|
||||
this(ITERATORS.wrap(iterator), loadFactor, strategy);
|
||||
@@ -102,16 +213,34 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Helper constructor that allows to create a set from a iterator of an unknown size
|
||||
* @param iterator the elements that should be added to the set
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public CUSTOM_HASH_SET(ITERATOR KEY_GENERIC_TYPE iterator, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(iterator, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a set from a iterator of an unknown size
|
||||
* @param iterator the elements that should be added to the set
|
||||
* @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_SET(ITERATOR KEY_GENERIC_TYPE iterator, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(HashUtil.DEFAULT_MIN_CAPACITY, loadFactor, strategy);
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper getter function to get the current strategy
|
||||
* @return the current strategy
|
||||
*/
|
||||
public STRATEGY KEY_SUPER_GENERIC_TYPE getStrategy() {
|
||||
return strategy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user