Fixes and new updates.
- Added: Collectors to lists/queues/sets - Fixed: Bugs in linked hash sets. - Fixed: Bugs in unit tests.
This commit is contained in:
@@ -12,6 +12,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
@@ -214,6 +220,42 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a AVLTreeSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, AVL_TREE_SET<T>, AVL_TREE_SET<T>> toSet() {
|
||||
return Collector.of(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a AVLTreeSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> AVL_TREE_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::merge);
|
||||
}
|
||||
|
||||
private AVL_TREE_SET<T> merge(AVL_TREE_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a AVLTreeSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static AVL_TREE_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(AVL_TREE_SET::new, AVL_TREE_SET::add, AVL_TREE_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; }
|
||||
|
||||
@@ -10,6 +10,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
import java.util.Set;
|
||||
#if JDK_FUNCTION
|
||||
@@ -74,7 +80,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
* @param array the array that should be used for set.
|
||||
*/
|
||||
public ARRAY_SET(KEY_TYPE[] array) {
|
||||
this(array, array.length);
|
||||
this(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +94,18 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
addAll(array, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructur using initial Array
|
||||
* @param array the array that should be used for set.
|
||||
* @param offset the starting offset of where the array should be copied from
|
||||
* @param length the amount of elements present within the array
|
||||
* @throws NegativeArraySizeException if the length is negative
|
||||
*/
|
||||
public ARRAY_SET(KEY_TYPE[] array, int offset, int length) {
|
||||
this(length);
|
||||
addAll(array, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Set with exactly the same values as the provided collection.
|
||||
* @param c the elements that should be added to the set.
|
||||
@@ -131,6 +149,42 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = s.iterator();iter.hasNext();data[size++] = iter.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a ArraySet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, ARRAY_SET<T>, ARRAY_SET<T>> toList() {
|
||||
return Collector.of(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a ArraySet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> ARRAY_SET KEY_GENERIC_TYPE toList(Stream<T> stream) {
|
||||
return stream.collect(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::merge);
|
||||
}
|
||||
|
||||
private ARRAY_SET<T> merge(ARRAY_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a ArraySet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static ARRAY_SET toList(JAVA_STREAM stream) {
|
||||
return stream.collect(ARRAY_SET::new, ARRAY_SET::add, ARRAY_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
int index = findIndex(o);
|
||||
|
||||
+42
@@ -11,6 +11,12 @@ import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
@@ -240,6 +246,42 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a LinkedCustomHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, LINKED_CUSTOM_HASH_SET<T>, LINKED_CUSTOM_HASH_SET<T>> toLinkedSet(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return Collector.of(() -> new LINKED_CUSTOM_HASH_SET<>(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a LinkedCustomHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE toLinkedSet(Stream<T> stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new LINKED_CUSTOM_HASH_SET<>(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private LINKED_CUSTOM_HASH_SET<T> merge(LINKED_CUSTOM_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a LinkedCustomHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static LINKED_CUSTOM_HASH_SET toList(JAVA_STREAM stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new LINKED_CUSTOM_HASH_SET(strategy), LINKED_CUSTOM_HASH_SET::add, LINKED_CUSTOM_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
|
||||
+42
@@ -7,6 +7,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
@@ -211,6 +217,42 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a LinkedHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, LINKED_HASH_SET<T>, LINKED_HASH_SET<T>> toLinkedSet() {
|
||||
return Collector.of(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a LinkedHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> LINKED_HASH_SET KEY_GENERIC_TYPE toLinkedSet(Stream<T> stream) {
|
||||
return stream.collect(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private LINKED_HASH_SET<T> merge(LINKED_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a LinkedHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static LINKED_HASH_SET toLinkedSet(JAVA_STREAM stream) {
|
||||
return stream.collect(LINKED_HASH_SET::new, LINKED_HASH_SET::add, LINKED_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE o) {
|
||||
|
||||
+42
@@ -8,6 +8,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
@@ -257,6 +263,42 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a CustomHashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, CUSTOM_HASH_SET<T>, CUSTOM_HASH_SET<T>> toSet(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return Collector.of(() -> new CUSTOM_HASH_SET<>(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a CustomHashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> CUSTOM_HASH_SET KEY_GENERIC_TYPE toSet(Stream<T> stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new CUSTOM_HASH_SET<>(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::merge);
|
||||
}
|
||||
|
||||
private CUSTOM_HASH_SET<T> merge(CUSTOM_HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a CustomHashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static CUSTOM_HASH_SET toSet(JAVA_STREAM stream, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
return stream.collect(() -> new CUSTOM_HASH_SET(strategy), CUSTOM_HASH_SET::add, CUSTOM_HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Helper getter function to get the current strategy
|
||||
|
||||
@@ -8,6 +8,12 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
@@ -224,6 +230,42 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a HashSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, HASH_SET<T>, HASH_SET<T>> toSet() {
|
||||
return Collector.of(HASH_SET::new, HASH_SET::add, HASH_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a HashSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> HASH_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(HASH_SET::new, HASH_SET::add, HASH_SET::merge);
|
||||
}
|
||||
|
||||
private HASH_SET<T> merge(HASH_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a HashSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static HASH_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(HASH_SET::new, HASH_SET::add, HASH_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
|
||||
@@ -4,6 +4,12 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
#if JDK_TYPE
|
||||
import java.util.OPTIONAL;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
#else
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collector;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
@@ -214,6 +220,42 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
while(iterator.hasNext()) add(iterator.NEXT());
|
||||
}
|
||||
|
||||
#if JDK_TYPE && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Creates a Collector for a RBTreeSet
|
||||
* @Type(T)
|
||||
* @return a collector
|
||||
*/
|
||||
public static <T> Collector<T, RB_TREE_SET<T>, RB_TREE_SET<T>> toSet() {
|
||||
return Collector.of(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a Stream to a RBTreeSet
|
||||
* @Type(T)
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static <T> RB_TREE_SET KEY_GENERIC_TYPE toSet(Stream<T> stream) {
|
||||
return stream.collect(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::merge);
|
||||
}
|
||||
|
||||
private RB_TREE_SET<T> merge(RB_TREE_SET<T> a) {
|
||||
addAll(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Collects a Stream to a RBTreeSet
|
||||
* @return a set with the contents of the Stream
|
||||
*/
|
||||
public static RB_TREE_SET toSet(JAVA_STREAM stream) {
|
||||
return stream.collect(RB_TREE_SET::new, RB_TREE_SET::add, RB_TREE_SET::addAll);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { defaultMaxNotFound = value; }
|
||||
|
||||
Reference in New Issue
Block a user