Class MCollection


  • public class MCollection
    extends Object
    • Field Detail

      • EMPTY_LIST

        public static final List<?> EMPTY_LIST
    • Constructor Detail

      • MCollection

        public MCollection()
    • Method Detail

      • contains

        public static boolean contains​(Object[] array,
                                       Object item)
        Returns true of array is not null and the value of item is included in the array. It compares with the equals() method of the array item. Also a item value of null will be compared.
        Parameters:
        array -
        item -
        Returns:
        true if contains the item
      • copyArray

        public static <T> void copyArray​(T[] array,
                                         Collection<T> list)
        Fills a list at the end with the values of an array, ignoring null values.
        Parameters:
        array -
        list -
      • removeDuplicates

        public static <T> void removeDuplicates​(List<T> list)
        remove duplicated entries
        Parameters:
        list -
      • removeDuplicates

        public static <T> void removeDuplicates​(List<T> list,
                                                Comparator<T> comparator)
        remove duplicated entries, Attention exponential runtime behavior !!! Running from beginning to the end, the first element will be left, following removed.
        Parameters:
        list -
        comparator -
      • append

        @SafeVarargs
        public static <T> T[] append​(T[] array,
                                     T... newElements)
      • insert

        @SafeVarargs
        public static <T> T[] insert​(T[] array,
                                     int index,
                                     T... newElements)
      • remove

        public static <T> T[] remove​(T[] array,
                                     int offset,
                                     int len)
      • order

        public static int[] order​(int[] array,
                                  boolean unique)
      • order

        public static long[] order​(long[] array,
                                   boolean unique)
      • fillIntArray

        public static int[] fillIntArray​(int from,
                                         int to)
      • toList

        public static <T> List<T> toList​(T... array)
      • toTreeSet

        public static <T> TreeSet<T> toTreeSet​(T[] items)
      • toHashSet

        public static <T> HashSet<T> toHashSet​(T[] items)
      • addAll

        public static <T> void addAll​(List<T> list,
                                      T[] items)
      • addAll

        public static <T> void addAll​(Set<T> list,
                                      T[] items)
      • getEmptyList

        public static <T extends List<?>> T getEmptyList()
      • toReadOnlyList

        public static <T> List<T> toReadOnlyList​(List<? extends T> in)
      • toList

        public static <T> List<T> toList​(Collection<? extends T> set)
      • toSet

        public static <T> Set<T> toSet​(Collection<? extends T> list)
      • contains

        public static boolean contains​(String list,
                                       char separator,
                                       String item)
        Returns true if the given item is part of the list. The list itself is a char separated list of items. White spaces are not allowed! The search is case sensitive.
        Parameters:
        list - The list of items
        separator - The separator between the list items
        item - The searched item
        Returns:
        true if the item is part of the list
      • append

        public static String append​(String list,
                                    char separator,
                                    String item)
        Append the item to the end of the list using the separator. If list is empty the item will be the first element.
        Parameters:
        list - The list of items
        separator - The item separator
        item - New item to append
        Returns:
        The new list
      • set

        public static String set​(String list,
                                 char separator,
                                 String item)
        Append the item to the end of the list using the separator if not already exists. If list is empty the item will be the first element.
        Parameters:
        list - The list of items
        separator - The item separator
        item - New item to append
        Returns:
        The new list
      • remove

        public static String remove​(String list,
                                    char separator,
                                    String item)
        Remove the given item from the list once.
        Parameters:
        list - List of items
        separator - Separator between the items
        item - The item to remove
        Returns:
        New list with removed item
      • sorted

        public static <K,​V> Map<K,​V> sorted​(Map<K,​V> in)
        Returns a new instance of Map with sorted keys.
        Parameters:
        in -
        Returns:
        a new sorted map
      • sorted

        public static <K> List<K> sorted​(List<K> in)
        If sort is possible (instance of Comparable) the function will create a new instance of list, copy and sort all the entries from the source into the new list and returns the created list. If the list could not be sorted the original list object will be returned.
        Parameters:
        in -
        Returns:
        A new sorted list
      • sorted

        public static <K,​V> Map<K,​V> sorted​(Map<K,​V> in,
                                                        Comparator<K> comp)
      • sorted

        public static <K> List<K> sorted​(List<K> in,
                                         Comparator<K> comp)
        The function will create a new instance of list, copy and sort all the entries from the source into the new list and returns the created list.
        Parameters:
        in -
        comp -
        Returns:
        A new sorted list
      • updateEach

        public static <T> void updateEach​(T[] array,
                                          Function<T,​T> manipulator)
        Process for each entry in the array. Return the new value for each entry.
        Parameters:
        array -
        manipulator -
      • forEach

        public static <T> void forEach​(T[] array,
                                       Consumer<T> consumer)
        Execute the consumer for each entry of the array.
        Parameters:
        array -
        consumer -
      • isEmpty

        public static boolean isEmpty​(Collection<?> col)
      • isEmpty

        public static boolean isEmpty​(Map<?,​?> map)
      • isSet

        public static boolean isSet​(Collection<?> col)
      • isSet

        public static boolean isSet​(Map<?,​?> map)
      • isEmpty

        public static boolean isEmpty​(Object[] array)
      • isSet

        public static boolean isSet​(Object[] array)
      • isAllNull

        public static boolean isAllNull​(Object[] array)
      • toLowerCaseKeys

        public static Map<String,​Object> toLowerCaseKeys​(Map<String,​Object> parameters)
        Create a new map and convert all string keys to lower case.
        Parameters:
        parameters -
        Returns:
        map with lower case keys
      • equals

        public static boolean equals​(Object[] nr1,
                                     Object[] nr2)
      • equals

        public static boolean equals​(byte[] nr1,
                                     byte[] nr2)
      • equals

        public static boolean equals​(int[] nr1,
                                     int[] nr2)
      • equals

        public static boolean equals​(double[] nr1,
                                     double[] nr2)
      • equals

        public static boolean equals​(char[] nr1,
                                     char[] nr2)
      • cropArray

        public static <T> T[] cropArray​(T[] from,
                                        int start,
                                        int stop)
        Cut a part from an array and create a new array with the values.
        Parameters:
        from -
        start -
        stop -
        Returns:
        new cropped array
      • extendArray

        public static <T> T[] extendArray​(T[] from,
                                          int left,
                                          int right)
        Parameters:
        from -
        left -
        right -
        Returns:
        new extended array
      • search

        public static <T> T search​(Iterable<T> iter,
                                   Predicate<? super T> filter)
        Search for an entry and return it use the filter to find it. Will return the first entry or null.
        Parameters:
        iter - The list or iterable object
        filter - The filter to find the entry
        Returns:
        The entry or null