Class UnionCollectionView<E>

Type Parameters:
E - type
All Implemented Interfaces:
Iterable<E>, Collection<E>

public final class UnionCollectionView<E> extends AbstractUnmodifiableCollection<E>
UnionCollectionView class
Author:
Mathias Hofer
  • Constructor Details

    • UnionCollectionView

      public UnionCollectionView(Collection<? extends E> c1, Collection<? extends E> c2)
      Constructs a new UnionCollectionView that represents the union of the two specified collections.
      Parameters:
      c1 - the first collection to be included in the union view; must not be null
      c2 - the second collection to be included in the union view; must not be null
      Throws:
      NullPointerException - if either c1 or c2 is null
  • Method Details

    • of

      public static <E> Collection<E> of(Collection<? extends E> c, E elem)
      Creates a new UnionCollectionView that represents the union of a collection and a single element.

      This method provides a convenient way to create a union view when you have a collection and want to add a single additional element to it without modifying the original collection.

      Type Parameters:
      E - the type of elements in the collection
      Parameters:
      c - the collection to be included in the union view; must not be null
      elem - the single element to be included in the union view; must not be null
      Returns:
      a Collection<E> representing the union of c and elem
      Throws:
      NullPointerException - if either c or elem is null
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in class AbstractCollection<E>
    • size

      public int size()
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in class AbstractCollection<E>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
      Overrides:
      isEmpty in class AbstractCollection<E>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<E>
      Overrides:
      contains in class AbstractCollection<E>