Package com.globalmentor.collections
Class Sets
- java.lang.Object
-
- com.globalmentor.collections.Sets
-
public class Sets extends java.lang.Object
Utilities to be used with sets.- Author:
- Garret Wilson
-
-
Constructor Summary
Constructors Constructor Description Sets()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> void
checkArgumentsEqual(java.util.Set<E> set1, java.util.Set<E> set2)
Checks that two sets are equal.static <E> java.util.Set<E>
immutableSetOf(E... elements)
Creates a read-only set containing the given elements.static <E> java.util.Set<E>
immutableSetOf(java.lang.Iterable<? extends E> iterable, E... elements)
Creates a read-only set containing the elements of the provided iterable along with the given elements.static <E> java.util.Set<E>
immutableSetOf(java.util.Collection<? extends E> collection, E... elements)
Creates a read-only set containing the elements of the provided collection along with the given elements.
-
-
-
Method Detail
-
immutableSetOf
public static <E> java.util.Set<E> immutableSetOf(E... elements)
Creates a read-only set containing the given elements.- Type Parameters:
E
- The type of element contained in the set.- Parameters:
elements
- The elements to be contained in the set.- Returns:
- The immutable version of the set.
- Throws:
java.lang.NullPointerException
- if the given array of elements isnull
.
-
immutableSetOf
public static <E> java.util.Set<E> immutableSetOf(java.lang.Iterable<? extends E> iterable, E... elements)
Creates a read-only set containing the elements of the provided iterable along with the given elements.- Type Parameters:
E
- The type of element contained in the set.- Parameters:
iterable
- The existing iterable to augment.elements
- The elements to be contained in the set.- Returns:
- The immutable version of the set.
- Throws:
java.lang.NullPointerException
- if the given iterable and/or array of elements isnull
.
-
immutableSetOf
public static <E> java.util.Set<E> immutableSetOf(java.util.Collection<? extends E> collection, E... elements)
Creates a read-only set containing the elements of the provided collection along with the given elements.- Type Parameters:
E
- The type of element contained in the set.- Parameters:
collection
- The existing collection to augment.elements
- The elements to be contained in the set.- Returns:
- The immutable version of the set.
- Throws:
java.lang.NullPointerException
- if the given collection and/or array of elements isnull
.
-
checkArgumentsEqual
public static <E> void checkArgumentsEqual(java.util.Set<E> set1, java.util.Set<E> set2)
Checks that two sets are equal.This method performs logic equivalent to
Set.equals(Object)
, except that a descriptive exception is thrown on inequality. This is particularly useful for debugging.- Type Parameters:
E
- The type of the items contained in the set.- Parameters:
set1
- The first set to compare.set2
- The second test to compare.- Throws:
java.lang.IllegalArgumentException
- if the sets are not equal.
-
-