Class CollectionLiterals

java.lang.Object
org.eclipse.xtext.xbase.lib.CollectionLiterals

@GwtCompatible public class CollectionLiterals extends Object
This is an extension library for collections.
Author:
Sebastian Zarnekow - Initial contribution and API
  • Constructor Details

    • CollectionLiterals

      public CollectionLiterals()
  • Method Details

    • emptyList

      @Pure public static <T> List<T> emptyList()
      Returns the empty, immutable list.
      Returns:
      an empty, immutable list.
      See Also:
    • emptySet

      @Pure public static <T> Set<T> emptySet()
      Returns the empty, immutable set.
      Returns:
      an empty, immutable set.
      See Also:
    • emptyMap

      @Pure public static <K, V> Map<K,V> emptyMap()
      Returns the empty, immutable map.
      Returns:
      an empty, immutable map.
      See Also:
    • newImmutableList

      @Pure @SafeVarargs public static <T> List<T> newImmutableList(T... elements)
      Returns an immutable list containing the given elements, in order.
      Parameters:
      elements - the elements that should be contained in the list. May not be null or contain any null values.
      Returns:
      an immutable list containing the given elements.
      Throws:
      NullPointerException - if elements or any of items in elements is null
    • newImmutableSet

      @Pure @SafeVarargs public static <T> Set<T> newImmutableSet(T... elements)
      Returns an immutable set containing the given elements. Repeated occurrences of an element (according to Object.equals(java.lang.Object)) after the first are ignored
      Parameters:
      elements - the elements that should be contained in the set. May not be null or contain any null values.
      Returns:
      an immutable set containing the given elements.
      Throws:
      NullPointerException - if elements or any of items in elements is null
    • newImmutableMap

      @Pure @SafeVarargs public static <K, V> Map<K,V> newImmutableMap(Pair<? extends K,? extends V>... entries)
      Returns an immutable map containing the given entries. Repeated occurrences of a keys will cause an IllegalArgumentException.
      Parameters:
      entries - the entries that should be contained in the map. May not be null and may not contain any null keys or values.
      Returns:
      an immutable map containing the given entries.
      Throws:
      NullPointerException - if entries or any key or value in entries is null
      IllegalArgumentException - if duplicate keys are contained in entries.
    • newArrayList

      @Pure public static <T> ArrayList<T> newArrayList()
      Creates an empty mutable ArrayList instance.
      Returns:
      a new ArrayList
      Since:
      2.13
    • newArrayList

      @SafeVarargs @Pure public static <T> ArrayList<T> newArrayList(T... initial)
      Creates a mutable ArrayList instance containing the given initial elements.
      Parameters:
      initial - the initial elements that the list should contain, in order. May not be null but may contain null values.
      Returns:
      a new ArrayList containing those elements
    • newLinkedList

      @Pure public static <T> LinkedList<T> newLinkedList()
      Creates an empty mutable LinkedList instance.
      Returns:
      a new LinkedList
      Since:
      2.13
    • newLinkedList

      @SafeVarargs @Pure public static <T> LinkedList<T> newLinkedList(T... initial)
      Creates a mutable LinkedList instance containing the given initial elements.
      Parameters:
      initial - the initial elements that the list should contain, in order. May not be null but may contain null values.
      Returns:
      a new LinkedList containing those elements
    • newHashSet

      @Pure public static <T> HashSet<T> newHashSet()
      Creates an empty mutable HashSet instance.
      Returns:
      a new HashSet
      Since:
      2.13
    • newHashSet

      @SafeVarargs @Pure public static <T> HashSet<T> newHashSet(T... initial)
      Creates a mutable HashSet instance containing the given initial elements.
      Parameters:
      initial - the initial elements that the set should contain, in order. May not be null but may contain null values.
      Returns:
      a new HashSet containing those elements
    • newLinkedHashSet

      @Pure public static <T> LinkedHashSet<T> newLinkedHashSet()
      Creates an empty mutable LinkedHashSet instance.
      Returns:
      a new LinkedHashSet
      Since:
      2.13
    • newLinkedHashSet

      @SafeVarargs @Pure public static <T> LinkedHashSet<T> newLinkedHashSet(T... initial)
      Creates a mutable LinkedHashSet instance containing the given initial elements.
      Parameters:
      initial - the initial elements that the set should contain, in order. May not be null but may contain null values.
      Returns:
      a new LinkedHashSet containing those elements
    • newTreeSet

      @Pure public static <T> TreeSet<T> newTreeSet(Comparator<? super T> comparator)
      Creates an empty mutable TreeSet instance.
      Parameters:
      comparator - the comparator that should be used. May be null which indicates that the natural ordering of the items should be used.
      Returns:
      a new TreeSet
      Since:
      2.13
    • newTreeSet

      @SafeVarargs @Pure public static <T> TreeSet<T> newTreeSet(Comparator<? super T> comparator, T... initial)
      Creates a mutable TreeSet instance containing the given initial elements.
      Parameters:
      initial - the initial elements that the set should contain, in order. May not be null but may contain null values.
      comparator - the comparator that should be used. May be null which indicates that the natural ordering of the items should be used.
      Returns:
      a new TreeSet containing those elements
    • newHashMap

      @Pure public static <K, V> HashMap<K,V> newHashMap()
      Creates an empty mutable HashMap instance.
      Returns:
      a new HashMap
      Since:
      2.13
    • newHashMap

      @SafeVarargs @Pure public static <K, V> HashMap<K,V> newHashMap(Pair<? extends K,? extends V>... initial)
      Creates a mutable HashMap instance containing the given initial entries. Repeated occurrences of a keys will cause an IllegalArgumentException.
      Parameters:
      initial - the entries that should be contained in the map. May not be null but may contain null keys or values.
      Returns:
      a new HashMap containing those elements
      Throws:
      IllegalArgumentException - if duplicate keys are contained the initial entries.
    • newLinkedHashMap

      @Pure public static <K, V> LinkedHashMap<K,V> newLinkedHashMap()
      Creates an empty mutable LinkedHashMap instance.
      Returns:
      a new LinkedHashMap
      Since:
      2.13
    • newLinkedHashMap

      @SafeVarargs @Pure public static <K, V> LinkedHashMap<K,V> newLinkedHashMap(Pair<? extends K,? extends V>... initial)
      Creates a mutable LinkedHashMap instance containing the given initial entries. Repeated occurrences of a keys will cause an IllegalArgumentException.
      Parameters:
      initial - the entries that should be contained in the map. May not be null but may contain null keys or values.
      Returns:
      a new LinkedHashMap containing those elements
      Throws:
      IllegalArgumentException - if duplicate keys are contained the initial entries.
    • newTreeMap

      @Pure public static <K, V> TreeMap<K,V> newTreeMap(Comparator<? super K> comparator)
      Creates an empty mutable TreeMap instance.
      Parameters:
      comparator - the comparator that should be used. May be null which indicates that the natural ordering of the keys should be used.
      Returns:
      a new TreeMap
      Since:
      2.13
    • newTreeMap

      @SafeVarargs @Pure public static <K, V> TreeMap<K,V> newTreeMap(Comparator<? super K> comparator, Pair<? extends K,? extends V>... initial)
      Creates a mutable TreeMap instance containing the given initial entries. Repeated occurrences of a keys will cause an IllegalArgumentException.
      Parameters:
      initial - the entries that should be contained in the map. May not be null but may contain null keys or values.
      comparator - the comparator that should be used. May be null which indicates that the natural ordering of the keys should be used.
      Returns:
      a new TreeMap containing those elements
      Throws:
      IllegalArgumentException - if duplicate keys are contained the initial entries.