Class RMListUtils


  • public class RMListUtils
    extends java.lang.Object
    Utility methods for use with Java.util.List.
    • Constructor Summary

      Constructors 
      Constructor Description
      RMListUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.List<T> add​(java.util.List<T> aList, T anObj)
      Adds an object to the given list and returns list (creates list if missing).
      static <T> java.util.List<T> addAllUnique​(java.util.List<T> aList, int anIndex, T... theObjects)
      Adds all object from second list to first list (creates first list if missing).
      static <T> java.util.List<T> addAllUnique​(java.util.List<T> aList, java.util.List<T> theObjects)
      Adds all object from second list to first list (creates first list if missing).
      static <T> java.util.List<T> addAllUnique​(java.util.List<T> aList, T... theObjects)
      Adds all object from second list to first list (creates first list if missing).
      static <T> java.util.List<T> addAllUniqueId​(java.util.List<T> aList, java.util.List<T> theObjects)
      Adds all object from second list to first list (creates first list if missing).
      static <T> java.util.List<T> addAllUniqueId​(java.util.List<T> aList, T... theObjects)
      Adds all object from second list to first list (creates first list if missing).
      static <T> java.util.List<T> addUnique​(java.util.List<T> aList, T anObj)
      Adds an object to the given list if object is absent (creates list if missing).
      static <T> java.util.List<T> addUniqueId​(java.util.List<T> aList, T anObj)
      Adds an object to the given list if identical object is missing (creates list if missing).
      static <T> int binarySearch​(java.util.List<? extends java.lang.Comparable<? super T>> aList, T aKey)
      Returns the result of binary search, but always returns insert index.
      static <T> java.util.List<T> clone​(java.util.List<T> aList)
      Returns a copy of the given list.
      static <T> java.util.List<T> cloneDeep​(java.util.List<T> aList)
      Returns a copy of the given list with copies of all its items (recursively).
      static boolean contains​(java.util.List aList, java.lang.Object anObj)
      Returns whether list contains given object (accepts null list).
      static boolean containsId​(java.util.List aList, java.lang.Object anObj)
      Returns whether list contains identical given object (accepts null list).
      static int countAtLevel​(java.util.List aList, int aLevel)
      Returns the number of objects at a given level in the given list hierarchy.
      static boolean equalsId​(java.util.List aList1, java.util.List aList2)
      Returns whether lists have same objects in them.
      static void filter​(java.util.List aList, java.lang.String aKeyChain)
      Filters a given list in place with the given key chain string.
      static <T> T get​(java.util.List<T> aList, int anIndex)
      Returns the object at the given index (returns null object for null list or invalid index).
      static java.util.List getFilteredList​(java.util.List aList, java.lang.String aKeyChain)
      Returns a filtered list (copy with given key chain string.
      static java.lang.Object getFirstLeaf​(java.util.List aList)
      Returns the first non-list object in the given list hierarchy, recursing if a list is found.
      static int[] getIndexesId​(java.util.List aList, java.util.List aSubList)
      Returns an array of indexes for given list and given objects in list.
      static <T> T getLast​(java.util.List<T> aList)
      Returns the last object in the given list.
      static <T> T getMatch​(java.util.Collection<T> aCollection, java.lang.String aKeyChain, java.lang.Object aValue)
      Returns the matching object for this given key value.
      static <T> java.util.List<T> getMatches​(java.util.Collection<T> aCollection, java.lang.String aKeyChain, java.lang.Object aValue)
      Returns the matching object for this given key value.
      static int getMatchIndex​(java.util.List aList, java.lang.String aKeyChain, java.lang.Object aValue)
      Returns the matching index for this given key value.
      static int indexOfId​(java.util.List aList, java.lang.Object anObj)
      Returns index of identical given object in given list.
      static java.lang.String joinStrings​(java.util.List aList, java.lang.String aString)
      Returns a string by concatenating strings in given list separated by given string.
      static void move​(java.util.List aList, int anIndex1, int anIndex2)
      Moves the object at index 1 to index 2.
      static void moveToFront​(java.util.List aList, int anIndex)
      Moves the object at the given index to the front of the list.
      static void moveToFront​(java.util.List aList, java.lang.Object anObj)
      Move the given object to the front of the list.
      static <T> java.util.List<T> newArrayList​(int aCapacity, T anObj)
      Creates a new array list with given object and capacity.
      static <T> java.util.List<T> newArrayList​(int aCapacity, T... theObjects)
      Creates a new array list with given objects and capacity.
      static <T> java.util.List<T> newArrayList​(T anObj)
      Creates a new array list with given object.
      static <T> java.util.List<T> newArrayList​(T... theObjects)
      Creates a new array list with given objects.
      static <T> java.util.List<T> newList​(T... objects)
      Creates a new list containing the objects in the object array.
      static <T> java.util.Vector<T> newVector​(T... objects)
      Creates a new vector for the given array of objects.
      static java.util.List objectsAtLevel​(java.util.List aList, int aLevel)
      Returns the objects at a given level in the given list hierarchy.
      static boolean objectsHaveSameClass​(java.util.List l)
      Returns whether objects in list all have same class.
      static void remove​(java.util.List aList, int start, int end)
      Removes range of objects from given list (from start to end, not including end).
      static boolean remove​(java.util.List aList, java.lang.Object anObj)
      Removes given object from given list (accepts null list).
      static int removeId​(java.util.List aList, java.lang.Object anObj)
      Removes the object identical to the given object from list.
      static <T> T removeLast​(java.util.List<T> aList)
      Removes the last object from given list.
      static java.util.List reverse​(java.util.List aList)
      Reverses the items in the given list.
      static int size​(java.util.List aList)
      Returns the size of a list (accepts null list).
      static <T> T[] toArray​(java.util.List<T> aList, java.lang.Class aClass)
      Returns an array of object of given class.
      static <T> java.util.List<T> toList​(java.lang.Iterable<T> anIterable)
      Converts an iterable to list.
      static <T> java.util.List<T> toList​(java.util.Enumeration<T> anEnumeration)
      Converts an enumeration to a list.
      static void xor​(java.util.List l1, java.util.List l2)
      Adds object from list 2 to list 1, unless they are already present (then removes them).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RMListUtils

        public RMListUtils()
    • Method Detail

      • size

        public static int size​(java.util.List aList)
        Returns the size of a list (accepts null list).
      • get

        @Nullable
        public static <T> T get​(java.util.List<T> aList,
                                int anIndex)
        Returns the object at the given index (returns null object for null list or invalid index).
      • getLast

        public static <T> T getLast​(java.util.List<T> aList)
        Returns the last object in the given list.
      • contains

        public static boolean contains​(java.util.List aList,
                                       java.lang.Object anObj)
        Returns whether list contains given object (accepts null list).
      • containsId

        public static boolean containsId​(java.util.List aList,
                                         java.lang.Object anObj)
        Returns whether list contains identical given object (accepts null list).
      • indexOfId

        public static int indexOfId​(java.util.List aList,
                                    java.lang.Object anObj)
        Returns index of identical given object in given list.
      • getIndexesId

        public static int[] getIndexesId​(java.util.List aList,
                                         java.util.List aSubList)
        Returns an array of indexes for given list and given objects in list.
      • add

        public static <T> java.util.List<T> add​(java.util.List<T> aList,
                                                T anObj)
        Adds an object to the given list and returns list (creates list if missing).
      • addUnique

        public static <T> java.util.List<T> addUnique​(java.util.List<T> aList,
                                                      T anObj)
        Adds an object to the given list if object is absent (creates list if missing).
      • addUniqueId

        public static <T> java.util.List<T> addUniqueId​(java.util.List<T> aList,
                                                        T anObj)
        Adds an object to the given list if identical object is missing (creates list if missing).
      • addAllUnique

        public static <T> java.util.List<T> addAllUnique​(java.util.List<T> aList,
                                                         java.util.List<T> theObjects)
        Adds all object from second list to first list (creates first list if missing).
      • addAllUniqueId

        public static <T> java.util.List<T> addAllUniqueId​(java.util.List<T> aList,
                                                           java.util.List<T> theObjects)
        Adds all object from second list to first list (creates first list if missing).
      • addAllUnique

        public static <T> java.util.List<T> addAllUnique​(java.util.List<T> aList,
                                                         T... theObjects)
        Adds all object from second list to first list (creates first list if missing).
      • addAllUnique

        public static <T> java.util.List<T> addAllUnique​(java.util.List<T> aList,
                                                         int anIndex,
                                                         T... theObjects)
        Adds all object from second list to first list (creates first list if missing).
      • addAllUniqueId

        public static <T> java.util.List<T> addAllUniqueId​(java.util.List<T> aList,
                                                           T... theObjects)
        Adds all object from second list to first list (creates first list if missing).
      • remove

        public static boolean remove​(java.util.List aList,
                                     java.lang.Object anObj)
        Removes given object from given list (accepts null list).
      • remove

        public static void remove​(java.util.List aList,
                                  int start,
                                  int end)
        Removes range of objects from given list (from start to end, not including end).
      • removeLast

        public static <T> T removeLast​(java.util.List<T> aList)
        Removes the last object from given list.
      • removeId

        public static int removeId​(java.util.List aList,
                                   java.lang.Object anObj)
        Removes the object identical to the given object from list.
      • binarySearch

        public static <T> int binarySearch​(java.util.List<? extends java.lang.Comparable<? super T>> aList,
                                           T aKey)
        Returns the result of binary search, but always returns insert index.
      • move

        public static void move​(java.util.List aList,
                                int anIndex1,
                                int anIndex2)
        Moves the object at index 1 to index 2.
      • reverse

        public static java.util.List reverse​(java.util.List aList)
        Reverses the items in the given list.
      • getFirstLeaf

        public static java.lang.Object getFirstLeaf​(java.util.List aList)
        Returns the first non-list object in the given list hierarchy, recursing if a list is found.
      • objectsAtLevel

        public static java.util.List objectsAtLevel​(java.util.List aList,
                                                    int aLevel)
        Returns the objects at a given level in the given list hierarchy.
      • countAtLevel

        public static int countAtLevel​(java.util.List aList,
                                       int aLevel)
        Returns the number of objects at a given level in the given list hierarchy.
      • joinStrings

        public static java.lang.String joinStrings​(java.util.List aList,
                                                   java.lang.String aString)
        Returns a string by concatenating strings in given list separated by given string.
      • toArray

        public static <T> T[] toArray​(java.util.List<T> aList,
                                      java.lang.Class aClass)
        Returns an array of object of given class.
      • newArrayList

        public static <T> java.util.List<T> newArrayList​(T anObj)
        Creates a new array list with given object.
      • newArrayList

        public static <T> java.util.List<T> newArrayList​(int aCapacity,
                                                         T anObj)
        Creates a new array list with given object and capacity.
      • newArrayList

        public static <T> java.util.List<T> newArrayList​(T... theObjects)
        Creates a new array list with given objects.
      • newArrayList

        public static <T> java.util.List<T> newArrayList​(int aCapacity,
                                                         T... theObjects)
        Creates a new array list with given objects and capacity.
      • newList

        public static <T> java.util.List<T> newList​(T... objects)
        Creates a new list containing the objects in the object array.
      • newVector

        public static <T> java.util.Vector<T> newVector​(T... objects)
        Creates a new vector for the given array of objects.
      • toList

        public static <T> java.util.List<T> toList​(java.lang.Iterable<T> anIterable)
        Converts an iterable to list.
      • toList

        public static <T> java.util.List<T> toList​(java.util.Enumeration<T> anEnumeration)
        Converts an enumeration to a list.
      • xor

        public static void xor​(java.util.List l1,
                               java.util.List l2)
        Adds object from list 2 to list 1, unless they are already present (then removes them).
      • getMatch

        public static <T> T getMatch​(java.util.Collection<T> aCollection,
                                     java.lang.String aKeyChain,
                                     java.lang.Object aValue)
        Returns the matching object for this given key value.
      • getMatches

        public static <T> java.util.List<T> getMatches​(java.util.Collection<T> aCollection,
                                                       java.lang.String aKeyChain,
                                                       java.lang.Object aValue)
        Returns the matching object for this given key value.
      • getMatchIndex

        public static int getMatchIndex​(java.util.List aList,
                                        java.lang.String aKeyChain,
                                        java.lang.Object aValue)
        Returns the matching index for this given key value.
      • filter

        public static void filter​(java.util.List aList,
                                  java.lang.String aKeyChain)
        Filters a given list in place with the given key chain string.
      • getFilteredList

        public static java.util.List getFilteredList​(java.util.List aList,
                                                     java.lang.String aKeyChain)
        Returns a filtered list (copy with given key chain string.
      • objectsHaveSameClass

        public static boolean objectsHaveSameClass​(java.util.List l)
        Returns whether objects in list all have same class.
      • moveToFront

        public static void moveToFront​(java.util.List aList,
                                       int anIndex)
        Moves the object at the given index to the front of the list.
      • moveToFront

        public static void moveToFront​(java.util.List aList,
                                       java.lang.Object anObj)
        Move the given object to the front of the list.
      • equalsId

        public static boolean equalsId​(java.util.List aList1,
                                       java.util.List aList2)
        Returns whether lists have same objects in them.
      • clone

        @Nullable
        public static <T> java.util.List<T> clone​(java.util.List<T> aList)
        Returns a copy of the given list.
      • cloneDeep

        @Nullable
        public static <T> java.util.List<T> cloneDeep​(java.util.List<T> aList)
        Returns a copy of the given list with copies of all its items (recursively).