Package one.microstream.collections.old
Class OldCollections
- java.lang.Object
-
- one.microstream.collections.old.OldCollections
-
public final class OldCollections extends Object
Some utility functionality for the old, misdesigned, bugged JDK collections that is so obvious but still missing in the JDK that even got implemented here despite having a vastly superior collections framework.
-
-
Constructor Summary
Constructors Constructor Description OldCollections()
-
Method Summary
Modifier and Type Method Description static <C extends Collection<? super E>,E>
CaddArray(C collection, E... elements)
static <C extends Collection<T>,T>
CaddBatch(C c, Iterable<T> elements)
static <C extends Collection<T>,T>
Cappend(C collectionToEnhance, Predicate<? super T> selectionPredicate, Iterable<T> collectionToAppend)
static <C extends Collection<T>,T>
Cappend(C collectionToEnhance, Predicate<? super T> selectionPredicate, Iterator<T> iterator)
static <C extends Collection<T>,T>
Cappend(C collectionToEnhance, Predicate<? super T> selectionPredicate, T[] arrayToAppend)
static StringBuilder
appendArray(StringBuilder sb, Object... elements)
static StringBuilder
appendArraySeperated(StringBuilder sb, char elementSeperator, Object... elements)
static StringBuilder
appendArraySeperated(StringBuilder sb, String elementSeperator, Object... elements)
static StringBuilder
appendIterable(StringBuilder sb, Iterable<?> iterable)
static StringBuilder
appendIterableSeperated(StringBuilder sb, char elementSeperator, Iterable<?> iterable)
static StringBuilder
appendIterableSeperated(StringBuilder sb, String elementSeperator, Iterable<?> iterable)
static <T> ArrayList<T>
ArrayList(int initialCapacity, Iterable<T> elements)
static <E> ArrayList<E>
ArrayList(E... elements)
static <E> ArrayList<E>
ArrayList(XGettingCollection<? extends E> xCollection)
Convenience method fornew ArrayList<E>(xCollection)
.static <T,L extends List<T> & RandomAccess>
booleancontainsSearched(L list, Predicate<? super T> predicate)
static <T,L extends List<T> & RandomAccess>
intcount(L list, Predicate<? super T> predicate)
static <C extends Collection<T>,T>
Cfilter(C sourceCollection, Predicate<? super T> selectionPredicate, C target)
static <T> ArrayList<T>
filter(ArrayList<T> arrayList, Predicate<? super T> selectionPredicate)
static <T,L extends List<T> & RandomAccess>
Lfilter(L list, Predicate<? super T> selectionPredicate, L targetList)
static <E> LinkedList<E>
LinkedList(E... elements)
static <E> LinkedList<E>
LinkedList(XGettingCollection<? extends E> xCollection)
static <K,V,T extends Map<K,V>,S extends Map<? extends K,? extends V>>
TmergeInto(T target, S... maps)
static <K,V>
HashMap<K,V>OldHashMap(KeyValue<? extends K,? extends V>... keyValueTuples)
static <T> HashSet<T>
OldHashSet(T... elements)
static <K,V>
LinkedHashMap<K,V>OldLinkedHashMap(XGettingMap<K,V> map)
static void
populateCollection(Collection<Object> instance, Object[] elements)
static void
populateCollectionFromHelperArray(Collection<?> instance, Object elementsHelper)
static void
populateMap(Map<Object,Object> instance, Object[] elements)
static void
populateMapFromHelperArray(Map<?,?> instance, Object elementsHelper)
static <C extends Collection<T>,T>
Creduce(C collection, Predicate<? super T> reductionPredicate)
Reducescollection
by all elements that meetreductionPredicate
.
Note that NO new collection instance is created but the collection itself is reduced.static <T> ArrayList<T>
reduce(ArrayList<T> arrayList, Predicate<? super T> reductionPredicate)
static <T,L extends List<T> & RandomAccess>
Tsearch(L list, Predicate<? super T> predicate)
static StringBuilder
stringBuilder(Object... elements)
static StringBuilder
stringBuilderSeperated(char elementSeperator, Object... elements)
static StringBuilder
stringBuilderSeperated(String elementSeperator, Object... elements)
static <T> T[]
toArray(Collection<? extends T> collection, Class<T> elementType)
Alias for the annoyingcollection.toArray((T[])Array.newInstance(elementType, collection.size()))
-
-
-
Method Detail
-
addBatch
public static final <C extends Collection<T>,T> C addBatch(C c, Iterable<T> elements)
-
addArray
@SafeVarargs public static final <C extends Collection<? super E>,E> C addArray(C collection, E... elements)
-
ArrayList
@SafeVarargs public static final <E> ArrayList<E> ArrayList(E... elements)
-
ArrayList
public static final <T> ArrayList<T> ArrayList(int initialCapacity, Iterable<T> elements)
-
LinkedList
@SafeVarargs public static final <E> LinkedList<E> LinkedList(E... elements)
-
LinkedList
public static final <E> LinkedList<E> LinkedList(XGettingCollection<? extends E> xCollection)
-
mergeInto
@SafeVarargs public static <K,V,T extends Map<K,V>,S extends Map<? extends K,? extends V>> T mergeInto(T target, S... maps)
-
count
public static final <T,L extends List<T> & RandomAccess> int count(L list, Predicate<? super T> predicate)
-
search
public static final <T,L extends List<T> & RandomAccess> T search(L list, Predicate<? super T> predicate)
-
containsSearched
public static final <T,L extends List<T> & RandomAccess> boolean containsSearched(L list, Predicate<? super T> predicate)
-
append
public static <C extends Collection<T>,T> C append(C collectionToEnhance, Predicate<? super T> selectionPredicate, T[] arrayToAppend)
-
append
public static <C extends Collection<T>,T> C append(C collectionToEnhance, Predicate<? super T> selectionPredicate, Iterator<T> iterator)
-
append
public static <C extends Collection<T>,T> C append(C collectionToEnhance, Predicate<? super T> selectionPredicate, Iterable<T> collectionToAppend)
-
filter
public static <T> ArrayList<T> filter(ArrayList<T> arrayList, Predicate<? super T> selectionPredicate)
-
filter
public static <T,L extends List<T> & RandomAccess> L filter(L list, Predicate<? super T> selectionPredicate, L targetList)
-
filter
public static <C extends Collection<T>,T> C filter(C sourceCollection, Predicate<? super T> selectionPredicate, C target)
-
reduce
public static <T> ArrayList<T> reduce(ArrayList<T> arrayList, Predicate<? super T> reductionPredicate)
-
reduce
public static <C extends Collection<T>,T> C reduce(C collection, Predicate<? super T> reductionPredicate)
Reducescollection
by all elements that meetreductionPredicate
.
Note that NO new collection instance is created but the collection itself is reduced.- Type Parameters:
T
-- Parameters:
collection
- the collection to be reducedreductionPredicate
- the predicate determining which elements shall be removed- Returns:
collection
itself
-
appendIterableSeperated
public static final StringBuilder appendIterableSeperated(StringBuilder sb, String elementSeperator, Iterable<?> iterable)
-
appendIterableSeperated
public static final StringBuilder appendIterableSeperated(StringBuilder sb, char elementSeperator, Iterable<?> iterable)
-
appendIterable
public static final StringBuilder appendIterable(StringBuilder sb, Iterable<?> iterable)
-
appendArraySeperated
public static final StringBuilder appendArraySeperated(StringBuilder sb, String elementSeperator, Object... elements)
-
appendArraySeperated
public static final StringBuilder appendArraySeperated(StringBuilder sb, char elementSeperator, Object... elements)
-
appendArray
public static final StringBuilder appendArray(StringBuilder sb, Object... elements)
-
stringBuilderSeperated
public static final StringBuilder stringBuilderSeperated(String elementSeperator, Object... elements)
-
stringBuilderSeperated
public static final StringBuilder stringBuilderSeperated(char elementSeperator, Object... elements)
-
stringBuilder
public static final StringBuilder stringBuilder(Object... elements)
-
toArray
public static final <T> T[] toArray(Collection<? extends T> collection, Class<T> elementType)
Alias for the annoyingcollection.toArray((T[])Array.newInstance(elementType, collection.size()))
- Type Parameters:
T
- the element type parameter of the list- Parameters:
collection
- the collection whose elements shall be copied to an arrayelementType
- the type of the elements contained incollection
.- Returns:
- a new array object of type
containing all elements of collection
.
-
OldHashSet
@SafeVarargs public static <T> HashSet<T> OldHashSet(T... elements)
-
OldHashMap
@SafeVarargs public static <K,V> HashMap<K,V> OldHashMap(KeyValue<? extends K,? extends V>... keyValueTuples)
-
OldLinkedHashMap
public static final <K,V> LinkedHashMap<K,V> OldLinkedHashMap(XGettingMap<K,V> map)
-
ArrayList
public static final <E> ArrayList<E> ArrayList(XGettingCollection<? extends E> xCollection)
Convenience method fornew ArrayList<E>(xCollection)
.- Type Parameters:
E
- the collection element type.- Parameters:
xCollection
- the extended collection implementation whore content shall be copied a newArrayList
instance.- Returns:
- a new
ArrayList
instance containing all elements of the passedXGettingCollection
.
-
populateMapFromHelperArray
public static final void populateMapFromHelperArray(Map<?,?> instance, Object elementsHelper)
-
populateCollectionFromHelperArray
public static final void populateCollectionFromHelperArray(Collection<?> instance, Object elementsHelper)
-
populateCollection
public static final void populateCollection(Collection<Object> instance, Object[] elements)
-
-