Class CbCollections

java.lang.Object
com.couchbase.client.core.util.CbCollections

@Internal public class CbCollections extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> List<T>
    Returns a new unmodifiable list with the same contents as the given collection.
    static <T> Set<T>
    Returns a new unmodifiable set with the same contents as the given collection.
    static <T> List<T>
    filter(Iterable<T> input, Predicate<? super T> predicate)
    Convenience method equivalent to:
    static <T> List<T>
    filter(T[] input, Predicate<? super T> predicate)
    Convenience method equivalent to:
    static boolean
     
    static boolean
     
    static boolean
     
    static <E> List<E>
    listCopyOf(Iterable<? extends E> original)
    Returns an unmodifiable list containing all elements of the given iterable.
    static <E> List<E>
    listCopyOf(Collection<? extends E> original)
    Backport of List.copyOf.
    static <T> List<T>
    listOf(T... items)
    Returns an unmodifiable list containing the given items.
    static <K, V> Map<K,V>
    mapCopyOf(Map<? extends K,? extends V> original)
    Backport of Map.copyOf.
    static <K, V> Map<K,V>
    Returns an unmodifiable empty map.
    static <K, V> Map<K,V>
    mapOf(K key1, V value1)
    Returns an unmodifiable map containing the given key/value pairs.
    static <K, V> Map<K,V>
    mapOf(K key1, V value1, K key2, V value2)
    Returns an unmodifiable map containing the given key/value pairs.
    static <K, V> Map<K,V>
    mapOf(K key1, V value1, K key2, V value2, K key3, V value3)
    Returns an unmodifiable map containing the given key/value pairs.
    static <K, V> Map<K,V>
    mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
    Returns an unmodifiable map containing the given key/value pairs.
    static <K, V> Map<K,V>
    mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5)
    Returns an unmodifiable map containing the given key/value pairs.
    static <K extends Enum<K>, V>
    EnumMap<K,V>
    newEnumMap(Class<K> keyClass, Map<K,V> source)
     
    static <T extends Enum<T>>
    EnumSet<T>
    newEnumSet(Class<T> elementClass, Iterable<T> source)
    Like EnumSet.copyOf(java.util.EnumSet<E>), but does not explode when given an empty collection.
    static <E> Set<E>
    setCopyOf(Collection<? extends E> original)
    Backport of Set.copyOf.
    static <T> Set<T>
    setOf(T... items)
    Returns an unmodifiable set containing the given items.
    static <T1, T2> List<T2>
    transform(Iterable<T1> input, Function<? super T1,? extends T2> transformer)
    Convenience method equivalent to:
    static <T1, T2> List<T2>
    transform(Iterator<T1> input, Function<? super T1,? extends T2> transformer)
    Convenience method equivalent to:
    static <T1, T2> List<T2>
    transform(T1[] input, Function<? super T1,? extends T2> transformer)
    Convenience method equivalent to:
    static <K, V1, V2> Map<K,V2>
    transformValues(Map<K,V1> map, BiFunction<K,V1,V2> transformer)
     
    static <K, V1, V2> Map<K,V2>
    transformValues(Map<K,V1> map, Function<V1,V2> transformer)
     

    Methods inherited from class java.lang.Object

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

    • listCopyOf

      public static <E> List<E> listCopyOf(Collection<? extends E> original)
      Backport of List.copyOf.

      Returns an unmodifiable list containing all elements of the given collection. Subsequent changes to the original collection are not reflected in the returned list.

      Throws:
      NullPointerException - if original is null or contains any nulls
    • setCopyOf

      public static <E> Set<E> setCopyOf(Collection<? extends E> original)
      Backport of Set.copyOf.

      Returns an unmodifiable set containing all elements of the given collection. If the original contains duplicate items, an arbitrary element is preserved. Subsequent changes to the original collection are not reflected in the returned set.

      Throws:
      NullPointerException - if original is null or contains any nulls
    • mapCopyOf

      public static <K, V> Map<K,V> mapCopyOf(Map<? extends K,? extends V> original)
      Backport of Map.copyOf.

      Returns an unmodifiable map containing all entries of the given map. Subsequent changes to the original map are not reflected in the returned map.

      Throws:
      NullPointerException - if original is null or contains any null keys or values.
    • copyToUnmodifiableList

      public static <T> List<T> copyToUnmodifiableList(@Nullable Collection<T> c)
      Returns a new unmodifiable list with the same contents as the given collection. Subsequent changes to the original collection are not reflected in the returned list.
      Parameters:
      c - may be null, in which case an empty list is returned.
    • copyToUnmodifiableSet

      public static <T> Set<T> copyToUnmodifiableSet(@Nullable Collection<T> c)
      Returns a new unmodifiable set with the same contents as the given collection. Subsequent changes to the original collection are not reflected in the returned set.
      Parameters:
      c - may be null, in which case an empty set is returned.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable Collection<?> c)
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable Map<?,?> m)
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable String s)
    • setOf

      @SafeVarargs public static <T> Set<T> setOf(T... items)
      Returns an unmodifiable set containing the given items.
      Throws:
      NullPointerException - if any item is null
      InvalidArgumentException - if there are duplicate items
    • listOf

      @SafeVarargs public static <T> List<T> listOf(T... items)
      Returns an unmodifiable list containing the given items.
      Throws:
      NullPointerException - if any item is null
    • mapOf

      public static <K, V> Map<K,V> mapOf()
      Returns an unmodifiable empty map.
    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1)
      Returns an unmodifiable map containing the given key/value pairs.
      Throws:
      NullPointerException - if any key or value is null
      InvalidArgumentException - if there are duplicate keys
    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2)
      Returns an unmodifiable map containing the given key/value pairs.
      Throws:
      NullPointerException - if any key or value is null
      InvalidArgumentException - if there are duplicate keys
    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3)
      Returns an unmodifiable map containing the given key/value pairs.
      Throws:
      NullPointerException - if any key or value is null
      InvalidArgumentException - if there are duplicate keys
    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
      Returns an unmodifiable map containing the given key/value pairs.
      Throws:
      NullPointerException - if any key or value is null
      InvalidArgumentException - if there are duplicate keys
    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5)
      Returns an unmodifiable map containing the given key/value pairs.
      Throws:
      NullPointerException - if any key or value is null
      InvalidArgumentException - if there are duplicate keys
    • transform

      public static <T1, T2> List<T2> transform(Iterable<T1> input, Function<? super T1,? extends T2> transformer)
      Convenience method equivalent to:
       input.stream().map(transformer).collect(toList())
       
    • transform

      public static <T1, T2> List<T2> transform(Iterator<T1> input, Function<? super T1,? extends T2> transformer)
      Convenience method equivalent to:
       input.stream().map(transformer).collect(toList())
       
    • transform

      public static <T1, T2> List<T2> transform(T1[] input, Function<? super T1,? extends T2> transformer)
      Convenience method equivalent to:
       Arrays.stream(input).map(transformer).collect(toList())
       
    • filter

      public static <T> List<T> filter(Iterable<T> input, Predicate<? super T> predicate)
      Convenience method equivalent to:
       input.stream().filter(predicate).collect(toList())
       
    • filter

      public static <T> List<T> filter(T[] input, Predicate<? super T> predicate)
      Convenience method equivalent to:
       Arrays.stream(input).filter(predicate).collect(toList())
       
    • transformValues

      public static <K, V1, V2> Map<K,V2> transformValues(Map<K,V1> map, Function<V1,V2> transformer)
    • transformValues

      public static <K, V1, V2> Map<K,V2> transformValues(Map<K,V1> map, BiFunction<K,V1,V2> transformer)
    • listCopyOf

      public static <E> List<E> listCopyOf(Iterable<? extends E> original)
      Returns an unmodifiable list containing all elements of the given iterable. Subsequent changes to the original iterable are not reflected in the returned list.
      Throws:
      NullPointerException - if original is null or contains any nulls
    • newEnumSet

      public static <T extends Enum<T>> EnumSet<T> newEnumSet(Class<T> elementClass, Iterable<T> source)
      Like EnumSet.copyOf(java.util.EnumSet<E>), but does not explode when given an empty collection.
    • newEnumMap

      public static <K extends Enum<K>, V> EnumMap<K,V> newEnumMap(Class<K> keyClass, Map<K,V> source)