Class CollectionUtils

java.lang.Object
org.elasticsearch.common.util.CollectionUtils

public class CollectionUtils extends Object
Collections-related utility methods.
  • Constructor Details

    • CollectionUtils

      public CollectionUtils()
  • Method Details

    • isEmpty

      public static boolean isEmpty(Object[] array)
      Checks if the given array contains any elements.
      Parameters:
      array - The array to check
      Returns:
      false if the array contains an element, true if not or the array is null.
    • rotate

      public static <T> List<T> rotate(List<T> list, int distance)
      Return a rotated view of the given list with the given distance.
    • sortAndDedup

      public static void sortAndDedup(com.carrotsearch.hppc.ObjectArrayList<byte[]> array)
    • sort

      public static void sort(com.carrotsearch.hppc.ObjectArrayList<byte[]> array)
    • toArray

      public static int[] toArray(Collection<Integer> ints)
    • ensureNoSelfReferences

      public static void ensureNoSelfReferences(Object value, String messageHint)
      Deeply inspects a Map, Iterable, or Object array looking for references back to itself.
      Parameters:
      value - The object to evaluate looking for self references
      messageHint - A string to be included in the exception message if the call fails, to provide more context to the handler of the exception
      Throws:
      IllegalArgumentException - if a self-reference is found
    • copyMap

      public static <R,​ T> Map<R,​T> copyMap(Map<R,​T> map)
      Returns an unmodifiable copy of the given map.
      Parameters:
      map - Map to copy
      Returns:
      unmodifiable copy of the map
    • sort

      public static void sort(org.apache.lucene.util.BytesRefArray bytes, int[] indices)
    • sortAndDedup

      public static int sortAndDedup(org.apache.lucene.util.BytesRefArray bytes, int[] indices)
    • iterableAsArrayList

      public static <E> ArrayList<E> iterableAsArrayList(Iterable<? extends E> elements)
    • arrayAsArrayList

      @SafeVarargs public static <E> ArrayList<E> arrayAsArrayList(E... elements)
    • asArrayList

      @SafeVarargs public static <E> ArrayList<E> asArrayList(E first, E... other)
    • asArrayList

      @SafeVarargs public static <E> ArrayList<E> asArrayList(E first, E second, E... other)
    • appendToCopy

      public static <E> List<E> appendToCopy(Collection<E> collection, E element)
      Creates a copy of the given collection with the given element appended.
      Parameters:
      collection - collection to copy
      element - element to append
    • newSingletonArrayList

      public static <E> ArrayList<E> newSingletonArrayList(E element)
    • eagerPartition

      public static <E> List<List<E>> eagerPartition(List<E> list, int size)
    • concatLists

      public static <E> List<E> concatLists(List<E> listA, List<E> listB)