Class ArrayListUtil


  • public final class ArrayListUtil
    extends java.lang.Object
    Utility functions for working with ArrayLists.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ArrayListUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> void fastUnorderedRemove​(java.util.ArrayList<T> list, int index)
      Removes element at index, but instead of copying all elements to the left, moves into the same slot the last element.
      static <T> void fastUnorderedRemove​(java.util.ArrayList<T> list, int index, int lastIndex)
      Removes element at index, but instead of copying all elements to the left, moves into the same slot the last element.
      static <T> boolean fastUnorderedRemove​(java.util.ArrayList<T> list, T e)
      Removes element but instead of copying all elements to the left, moves into the same slot the last element.
      • Methods inherited from class java.lang.Object

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

      • ArrayListUtil

        private ArrayListUtil()
    • Method Detail

      • fastUnorderedRemove

        public static <T> void fastUnorderedRemove​(java.util.ArrayList<T> list,
                                                   int index)
        Removes element at index, but instead of copying all elements to the left, moves into the same slot the last element. This avoids the copy costs, but spoils the list order. If index is the last element it is just removed.
        Type Parameters:
        T - element type.
        Parameters:
        list - to be modified.
        index - to be removed.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is out of bounds.
      • fastUnorderedRemove

        public static <T> void fastUnorderedRemove​(java.util.ArrayList<T> list,
                                                   int index,
                                                   int lastIndex)
        Removes element at index, but instead of copying all elements to the left, moves into the same slot the last element. This avoids the copy costs, but spoils the list order. If index is the last element it is just removed.
        Type Parameters:
        T - element type.
        Parameters:
        list - to be modified.
        index - to be removed.
        lastIndex - last element index in the list to be swapped into the removed index.
        Throws:
        java.lang.IndexOutOfBoundsException - if index or lastIndex are out of bounds.
      • fastUnorderedRemove

        public static <T> boolean fastUnorderedRemove​(java.util.ArrayList<T> list,
                                                      T e)
        Removes element but instead of copying all elements to the left, moves into the same slot the last element. This avoids the copy costs, but spoils the list order. If element is the last element then it is just removed.
        Type Parameters:
        T - element type.
        Parameters:
        list - to be modified.
        e - to be removed.
        Returns:
        true if found and removed, false otherwise.