Class RMListUtils

java.lang.Object
com.inductiveautomation.rm.base.RMListUtils

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

    Constructors
    Constructor
    Description
     
  • Method Summary

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

    • RMListUtils

      public RMListUtils()
  • Method Details

    • size

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

      @Nullable public static <T> T get(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(List<T> aList)
      Returns the last object in the given list.
    • contains

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

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

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

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

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

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

      public static <T> List<T> addUniqueId(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> List<T> addAllUnique(List<T> aList, List<T> theObjects)
      Adds all object from second list to first list (creates first list if missing).
    • addAllUniqueId

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

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

      public static <T> List<T> addAllUnique(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> List<T> addAllUniqueId(List<T> aList, T... theObjects)
      Adds all object from second list to first list (creates first list if missing).
    • remove

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

      public static void remove(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(List<T> aList)
      Removes the last object from given list.
    • removeId

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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