public class

CollectionUtil

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.collect.CollectionUtil

Class Overview

Convenience methods for Java Collection collections, in particular, List lists.

Summary

Public Constructors
CollectionUtil()
Public Methods
static <T> Collection<T> addNonNulls(Collection<T> dst, T... elts)
static <T> Collection<T> addNonNulls(Collection<T> dst, Collection<? extends T> src)
static <T, K extends Comparable<K>> T binarySearch(List<T> list, K key, IExtractor<T, K> extractor)
Perform a binary search in an ordered list.
static <T, K extends Comparable<K>> int binarySearchEx(List<? extends T> list, K key, IExtractor<T, ? extends K> extractor, Comparator<K> cc)
Perform a binary search in an ordered list.
static <T> boolean compare(Collection<? extends T> c1, Collection<? extends T> c2, boolean sorted)
static <T> boolean compareByReference(Collection<? extends T> c1, Collection<? extends T> c2, boolean sorted)
static boolean contains(Collection<?> c, Object v)
Safely check if an object is present within a collection.
static boolean containsNonNull(Iterable<?> c)
Determine if the given iterable contains one or more non-null elements.
static boolean containsNull(Iterable<?> c)
Determine if the given iterable contains one or more null elements.
static <T> boolean containsReference(Collection<? extends T> c, T o)
Determine if the collection contains the object reference (differs from contains(Object) by checking reference equality == instead of equals(Object) equality)
static <T> int count(Collection<T> coll, T item)
Count elements using equals(Object).
static <T> Iterable<T> doubleCollectionIterable(Collection<T> coll1, Collection<T> coll2)
Create a generator that will iterate over two collections, starting with the first one, then the second one.
static <T> boolean hasIntersection(Collection<? extends T> c1, Collection<? extends T> c2)
static <T> int identityCount(Collection<T> coll, T item)
Count elements using ==.
static <T> Set<T> intersect(Collection<? extends T> c1, Collection<? extends T> c2)
Return the intersection of 2 collections (order of collection parameters does not matter).
static <T> List<T> intersection(List<? extends T> c1, List<? extends T> c2)
This method is deprecated. Use intersect(Collection, Collection)
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public CollectionUtil ()

Public Methods

public static Collection<T> addNonNulls (Collection<T> dst, T... elts)

public static Collection<T> addNonNulls (Collection<T> dst, Collection<? extends T> src)

public static T binarySearch (List<T> list, K key, IExtractor<T, K> extractor)

Perform a binary search in an ordered list.

Parameters
list a list of ordered items
key the ordering key for the items.
extractor key extractor
Returns
  • the element, null if not found

public static int binarySearchEx (List<? extends T> list, K key, IExtractor<T, ? extends K> extractor, Comparator<K> cc)

Perform a binary search in an ordered list.

Parameters
list a list of ordered items
key the ordering key for the items.
extractor key extractor
Returns
  • the zero+ index of the found element; else, the negative insertion index of the ghost element

public static boolean compare (Collection<? extends T> c1, Collection<? extends T> c2, boolean sorted)

public static boolean compareByReference (Collection<? extends T> c1, Collection<? extends T> c2, boolean sorted)

public static boolean contains (Collection<?> c, Object v)

Safely check if an object is present within a collection.

Parameters
c collection, potentially null
v object, potentially null
Returns
  • true IFF the object is contained in the collection

public static boolean containsNonNull (Iterable<?> c)

Determine if the given iterable contains one or more non-null elements.

public static boolean containsNull (Iterable<?> c)

Determine if the given iterable contains one or more null elements.

public static boolean containsReference (Collection<? extends T> c, T o)

Determine if the collection contains the object reference (differs from contains(Object) by checking reference equality == instead of equals(Object) equality)

Parameters
c collection to loop into
o element whose presence in this collection is to be tested
Returns
  • true if the collection contains the specified element

public static int count (Collection<T> coll, T item)

Count elements using equals(Object).

public static Iterable<T> doubleCollectionIterable (Collection<T> coll1, Collection<T> coll2)

Create a generator that will iterate over two collections, starting with the first one, then the second one.

This method is convenient to iterate over two collections without having to create an intermediate list holding the elements.

Parameters
coll1 first collection
coll2 second collection
Returns
  • an iterable

public static boolean hasIntersection (Collection<? extends T> c1, Collection<? extends T> c2)

public static int identityCount (Collection<T> coll, T item)

Count elements using ==.

public static Set<T> intersect (Collection<? extends T> c1, Collection<? extends T> c2)

Return the intersection of 2 collections (order of collection parameters does not matter).

Parameters
c1 first collection
c2 second collection
Returns
  • a set of intersection

public static List<T> intersection (List<? extends T> c1, List<? extends T> c2)

This method is deprecated.
Use intersect(Collection, Collection)

Return the intersection of 2 lists. May contain duplicated elements.