Class 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 Detail

      • OldCollections

        public OldCollections()
    • 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

        public static final <T> ArrayList<T> ArrayList​(int initialCapacity,
                                                       Iterable<T> elements)
      • 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,​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 <C extends Collection<T>,​T> C reduce​(C collection,
                                                                 Predicate<? super T> reductionPredicate)
        Reduces collection by all elements that meet reductionPredicate.
        Note that NO new collection instance is created but the collection itself is reduced.
        Type Parameters:
        T -
        Parameters:
        collection - the collection to be reduced
        reductionPredicate - the predicate determining which elements shall be removed
        Returns:
        collection itself
      • stringBuilderSeperated

        public static final StringBuilder stringBuilderSeperated​(String elementSeperator,
                                                                 Object... elements)
      • stringBuilderSeperated

        public static final StringBuilder stringBuilderSeperated​(char elementSeperator,
                                                                 Object... elements)
      • toArray

        public static final <T> T[] toArray​(Collection<? extends T> collection,
                                            Class<T> elementType)
        Alias for the annoying collection.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 array
        elementType - the type of the elements contained in collection.
        Returns:
        a new array object of type containing all elements of collection.
      • OldHashMap

        @SafeVarargs
        public static <K,​V> HashMap<K,​V> OldHashMap​(KeyValue<? extends K,​? extends V>... keyValueTuples)
      • ArrayList

        public static final <E> ArrayList<E> ArrayList​(XGettingCollection<? extends E> xCollection)
        Convenience method for new 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 passed XGettingCollection.
      • populateMapFromHelperArray

        public static final void populateMapFromHelperArray​(Map<?,​?> instance,
                                                            Object elementsHelper)
      • populateMap

        public static final void populateMap​(Map<Object,​Object> instance,
                                             Object[] elements)
      • populateCollectionFromHelperArray

        public static final void populateCollectionFromHelperArray​(Collection<?> instance,
                                                                   Object elementsHelper)
      • populateCollection

        public static final void populateCollection​(Collection<Object> instance,
                                                    Object[] elements)