Class Sets

java.lang.Object
com.globalmentor.collections.Sets

public class Sets extends Object
Utilities to be used with sets.
Author:
Garret Wilson
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <E> void
    checkArgumentsEqual(Set<E> set1, Set<E> set2)
    Checks that two sets are equal.
    static <E> Set<E>
    immutableSetOf(E... elements)
    Creates a read-only set containing the given elements.
    static <E> Set<E>
    immutableSetOf(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> Set<E>
    immutableSetOf(Collection<? extends E> collection, E... elements)
    Creates a read-only set containing the elements of the provided collection along with the given elements.

    Methods inherited from class java.lang.Object

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

    • Sets

      public Sets()
  • Method Details

    • immutableSetOf

      public static <E> 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:
      NullPointerException - if the given array of elements is null.
    • immutableSetOf

      public static <E> Set<E> immutableSetOf(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:
      NullPointerException - if the given iterable and/or array of elements is null.
    • immutableSetOf

      public static <E> Set<E> immutableSetOf(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:
      NullPointerException - if the given collection and/or array of elements is null.
    • checkArgumentsEqual

      public static <E> void checkArgumentsEqual(Set<E> set1, 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:
      IllegalArgumentException - if the sets are not equal.