Class ECollections

java.lang.Object
org.eclipse.emf.common.util.ECollections

public class ECollections extends Object
Support for empty and unmodifiable ELists.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final EList<?>
    An unmodifiable empty list with an efficient reusable iterator.
    static final EMap<?,?>
    An unmodifiable empty map with an efficient reusable iterator.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> EList<T>
    asEList(List<T> list)
    Returns an EList view of the specified list.
    static <T> EList<T>
    asEList(T... elements)
    Returns a mutable, fixed-size, random access EList backed by the given array.
    static <K, V> EMap<K,V>
    asEMap(Map<K,V> map)
    Returns a mutable EMap view of the specified map.
    static <T> EList<T>
    Returns an empty unmodifiable list.
    static <K, V> EMap<K,V>
    Returns an empty unmodifiable map.
    static int
    indexOf(List<?> list, Object o, int fromIndex)
    Searches for the first occurrence of the given argument in list starting from a specified index.
    static <T> T
    move(List<T> list, int targetIndex, int sourceIndex)
    Moves the object from the old position to the new position.
    static <T> void
    move(List<T> list, int newPosition, T object)
    Moves the object to the new position, if is in the list.
    static <T> BasicEList<T>
    Creates an empty mutable BasicEList.
    static <T> BasicEList<T>
    newBasicEList(Iterable<? extends T> iterable)
    Creates a mutable BasicEList containing the given elements.
    static <T> BasicEList<T>
    newBasicEList(Iterator<? extends T> iterator)
    Creates a mutable BasicEList containing the given elements.
    static <T> BasicEList<T>
    newBasicEList(T... elements)
    Creates a mutable BasicEList containing the given elements.
    static <T> BasicEList<T>
    Creates an empty mutable BasicEList with the given capacity.
    static <T> BasicEList<T>
    newBasicEListWithExpectedSize(int estimatedSize)
    Creates an empty mutable BasicEList with a capacity large enough to hold a bit more than the estimated number of elements.
    static void
    reverse(EList<?> list)
    Reverses the order of the elements in the specified EList.
    static <T> void
    setEList(EList<T> eList, List<? extends T> prototypeList)
    Sets the eList's contents and order to be exactly that of the prototype list.
    static <T> EList<T>
    Returns an immutable list containing just the one object.
    static <K, V> EMap<K,V>
    singletonEMap(K key, V value)
    Returns an immutable map containing just the one key/value mapping.
    static void
    sort(EList<?> list)
    Sorts the specified list.
    static <T> void
    sort(EList<T> list, Comparator<? super T> comparator)
    Sorts the specified list based on the order defined by the specified comparator.
    static <T> InterningSet<T>
    Returns a synchronized, i.e., thread-safe view of the interning set.
    static <T> EList<T>
    toEList(Iterable<? extends T> iterable)
    Returns a list containing the elements of the given iterable.
    static <T> EList<T>
    toEList(Iterator<? extends T> iterator)
    Returns a mutable list containing the elements of the given iterator.
    static <T> EList<T>
    unmodifiableEList(List<? extends T> list)
    Returns an unmodifiable view of the list.
    static <T> EList<T>
    unmodifiableEList(EList<? extends T> list)
    Returns an unmodifiable view of the list.
    static <K, V> EMap<K,V>
    unmodifiableEMap(EMap<? extends K,? extends V> map)
    Returns an unmodifiable view of the map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY_ELIST

      public static final EList<?> EMPTY_ELIST
      An unmodifiable empty list with an efficient reusable iterator.
    • EMPTY_EMAP

      public static final EMap<?,?> EMPTY_EMAP
      An unmodifiable empty map with an efficient reusable iterator.
  • Method Details

    • move

      public static <T> void move(List<T> list, int newPosition, T object)
      Moves the object to the new position, if is in the list.
      Parameters:
      newPosition - the position of the object after the move.
      object - the object to move.
    • move

      public static <T> T move(List<T> list, int targetIndex, int sourceIndex)
      Moves the object from the old position to the new position.
      Parameters:
      targetIndex - the position of the object after the move.
      sourceIndex - the position of the object before the move.
      Returns:
      the moved object
    • reverse

      public static void reverse(EList<?> list)
      Reverses the order of the elements in the specified EList.
    • indexOf

      public static int indexOf(List<?> list, Object o, int fromIndex)
      Searches for the first occurrence of the given argument in list starting from a specified index. The equality is tested using the operator == and the equals method.
      Parameters:
      o - an object (can be null)
      fromIndex -
      Returns:
      the index of the first occurrence of the argument in this list (where index>=fromIndex); returns -1 if the object is not found.
      Since:
      2.1.0
    • sort

      public static void sort(EList<?> list)
      Sorts the specified list. Use this method instead of Collections.sort(java.util.List) to avoid errors when sorting unique lists.
      Since:
      2.1.0
    • sort

      public static <T> void sort(EList<T> list, Comparator<? super T> comparator)
      Sorts the specified list based on the order defined by the specified comparator. Use this method instead of Collections.sort(java.util.List, java.util.Comparator) to avoid errors when sorting unique lists.
      Since:
      2.1.0
    • setEList

      public static <T> void setEList(EList<T> eList, List<? extends T> prototypeList)
      Sets the eList's contents and order to be exactly that of the prototype list. This implementation minimizes the number of notifications the operation will produce. Objects already in the list will be moved, missing objects will be added, and extra objects will be removed. If eList's contents and order are already exactly that of the prototype list, no change will be made.
      Parameters:
      eList - the list to set.
      prototypeList - the list representing the desired content and order.
    • unmodifiableEList

      public static <T> EList<T> unmodifiableEList(EList<? extends T> list)
      Returns an unmodifiable view of the list.
      Returns:
      an unmodifiable view of the list.
    • unmodifiableEMap

      public static <K, V> EMap<K,V> unmodifiableEMap(EMap<? extends K,? extends V> map)
      Returns an unmodifiable view of the map.
      Returns:
      an unmodifiable view of the map.
    • emptyEList

      public static <T> EList<T> emptyEList()
      Returns an empty unmodifiable list.
      Returns:
      an empty unmodifiable list.
    • emptyEMap

      public static <K, V> EMap<K,V> emptyEMap()
      Returns an empty unmodifiable map.
      Returns:
      an empty unmodifiable map.
    • singletonEList

      public static <T> EList<T> singletonEList(T o)
      Returns an immutable list containing just the one object.
      Returns:
      an immutable list containing just the one object.
      Since:
      2.7
    • singletonEMap

      public static <K, V> EMap<K,V> singletonEMap(K key, V value)
      Returns an immutable map containing just the one key/value mapping.
      Returns:
      an immutable map containing just the one key/value mapping.
      Since:
      2.7
    • toEList

      public static <T> EList<T> toEList(Iterator<? extends T> iterator)
      Returns a mutable list containing the elements of the given iterator.
      Returns:
      a mutable list containing the same elements as the given iterator.
      Since:
      2.9
    • toEList

      public static <T> EList<T> toEList(Iterable<? extends T> iterable)
      Returns a list containing the elements of the given iterable. If the iterable is of type EList, that list itself is returned. If the iterable is of type List, a view of that list is returned; all changes to view are reflected in the underlying list and all changes to the underlying list are reflected in the view. In all other cases, the result is a copy of the iterable.
      Returns:
      a list containing the same elements as the given iterable.
      Since:
      2.9
    • asEMap

      public static <K, V> EMap<K,V> asEMap(Map<K,V> map)
      Returns a mutable EMap view of the specified map. EList.move(int, int), EList.move(int, Object), List.add(int, Object), and List.addAll(int, Collection), i.e., the methods that expect to control the exact order of entries in the map's entry set, are not supported and throw UnsupportedOperationException. All other changes to the EMap write through to the underlying map.
      Parameters:
      map - the map to which the EMap delegates.
      Returns:
      an EMap view of the specified map.
      Since:
      2.9
    • asEList

      public static <T> EList<T> asEList(List<T> list)
      Returns an EList view of the specified list. All changes to the EList write through to the underlying list.
      Parameters:
      list - the list to which the EList delegates.
      Returns:
      an EList view of the specified list.
      Since:
      2.9
    • asEList

      @SafeVarargs public static <T> EList<T> asEList(T... elements)
      Returns a mutable, fixed-size, random access EList backed by the given array. Changes to the list, i.e., set and move, write through to the array. All other list modifying operations throw UnsupportedOperationException. This is analogous to Arrays.asList(Object...) with the advantage that you can move objects; hence you can sort without using List.add(int, Object) and List.remove(int).
      Parameters:
      elements - the array to which the EList delegates.
      Returns:
      an EList view of the specified array.
      Since:
      2.9
    • unmodifiableEList

      public static <T> EList<T> unmodifiableEList(List<? extends T> list)
      Returns an unmodifiable view of the list.
      Returns:
      an unmodifiable view of the list.
      Since:
      2.9
    • newBasicEList

      public static <T> BasicEList<T> newBasicEList()
      Creates an empty mutable BasicEList.
      Returns:
      an empty mutable BasicEList.
      Since:
      2.9
    • newBasicEListWithCapacity

      public static <T> BasicEList<T> newBasicEListWithCapacity(int capacity)
      Creates an empty mutable BasicEList with the given capacity.
      Returns:
      an empty mutable BasicEList.
      Since:
      2.9
    • newBasicEListWithExpectedSize

      public static <T> BasicEList<T> newBasicEListWithExpectedSize(int estimatedSize)
      Creates an empty mutable BasicEList with a capacity large enough to hold a bit more than the estimated number of elements. If you know the exact size, use newBasicEListWithCapacity(int) instead.
      Returns:
      an empty mutable BasicEList.
      Since:
      2.9
    • newBasicEList

      @SafeVarargs public static <T> BasicEList<T> newBasicEList(T... elements)
      Creates a mutable BasicEList containing the given elements.
      Returns:
      a mutable BasicEList containing the given elements.
      Since:
      2.9
    • newBasicEList

      public static <T> BasicEList<T> newBasicEList(Iterator<? extends T> iterator)
      Creates a mutable BasicEList containing the given elements.
      Returns:
      a mutable BasicEList containing the given elements.
      Since:
      2.9
    • newBasicEList

      public static <T> BasicEList<T> newBasicEList(Iterable<? extends T> iterable)
      Creates a mutable BasicEList containing the given elements.
      Returns:
      a mutable BasicEList containing the given elements.
      Since:
      2.9
    • synchronizedInterningSet

      public static <T> InterningSet<T> synchronizedInterningSet(InterningSet<T> set)
      Returns a synchronized, i.e., thread-safe view of the interning set. The result is serializeable if the argument is serializeable.
      Parameters:
      set - the interning set to which this interning set delegates.
      Returns:
      a synchronized view of the interning set.
      Since:
      2.9