Class CellSet

All Implemented Interfaces:
CellCollection, Iterable<Cell<?>>, Collection<Cell<?>>, Set<Cell<?>>

public final class CellSet extends AbstractSet<Cell<?>> implements CellCollection
A collection of Cells having no more than one cell having a given name. The iteration order is not defined for a CellSet but may be specified by an API method returning an instance.

Null elements are not permitted in a CellSet.

See Also:
  • Constructor Details

    • CellSet

      public CellSet()
      Creates an new, mutable empty CellSet instance.
    • CellSet

      public CellSet(Iterable<Cell<?>> cells)
      Creates a new, mutable CellSet instance containing the Cells from the specified Iterable in the order returned by the iterator. If more than one cell with the same name is presented from the iterable, only the last like-named cell, as observed by the iterator, is kept.
      Parameters:
      cells - the Iterable over Cell instances from which a new CellSet is created
      Throws:
      NullPointerException - if cells is null or cells contains a null element
  • Method Details

    • of

      public static CellSet of(Cell<?>... cells)
      Creates a new, mutable CellSet instance containing the specified Cell instances. If more than one cell with the same name is present in the collection, only the last like-named cell is kept.
      Parameters:
      cells - the Cell instances for the new CellSet
      Returns:
      a new, mutable CellSet containing the specified cells
      Throws:
      NullPointerException - if cells contains a null
    • cell

      public Optional<Cell<?>> cell(String name)
      Description copied from interface: CellCollection
      Retrieve a cell by name. If this record contains a cell whose definition matches the supplied name then the cell is wrapped in an Optional and returned. If this record contains no matching cell then an empty Optional is returned.
      Specified by:
      cell in interface CellCollection
      Parameters:
      name - cell to retrieve
      Returns:
      An Optional with the cell or an empty Optional if the record contains no matching cell
    • add

      public boolean add(Cell<?> cell)
      Adds the specified Cell to this set if a cell having the same cell name is not already present.
      Specified by:
      add in interface Collection<Cell<?>>
      Specified by:
      add in interface Set<Cell<?>>
      Overrides:
      add in class AbstractCollection<Cell<?>>
      Parameters:
      cell - the new Cell to add to this set
      Returns:
      if this set did not already contain the specified cell
      Throws:
      NullPointerException - if cell is null
    • set

      public Cell<?> set(Cell<?> cell)
      Adds the specified Cell to this set if a cell having the same name is not already present or replaces the existing cell if a cell of the same name is already present.
      Parameters:
      cell - the new Cell to put into this set
      Returns:
      the previous Cell having the same name as cell, if any; null if a like-named cell is not present
      Throws:
      NullPointerException - if cell is null
    • contains

      public boolean contains(Object o)
      Returns true if this set contains the specified Cell or another cell having the same name.
      Specified by:
      contains in interface Collection<Cell<?>>
      Specified by:
      contains in interface Set<Cell<?>>
      Overrides:
      contains in class AbstractCollection<Cell<?>>
      Parameters:
      o -
      Returns:
      true if this set contains the specified cell
      Throws:
      NullPointerException - if o is null
      ClassCastException - if o is not a Cell
    • remove

      public boolean remove(Object o)
      Removes the specified Cell.
      Specified by:
      remove in interface Collection<Cell<?>>
      Specified by:
      remove in interface Set<Cell<?>>
      Overrides:
      remove in class AbstractCollection<Cell<?>>
      Parameters:
      o -
      Returns:
      true if this set contained the specified cell
      Throws:
      NullPointerException - if o is null
      ClassCastException - if o is not a Cell
    • remove

      public Optional<Cell<?>> remove(String name)
      Removes a Cell with the specified name.
      Parameters:
      name - name of cell to be removed
      Returns:
      an optional containing the removed cell
      Throws:
      NullPointerException - if name is null
    • remove

      public <T> Optional<Cell<T>> remove(CellDefinition<T> definition)
      Removes the Cell with this definition from this set if it is present.
      Type Parameters:
      T - the cell JDK type
      Parameters:
      definition - cell definition to remove
      Returns:
      an optional containing the removed cell
      Throws:
      NullPointerException - if definition is null
    • spliterator

      public Spliterator<Cell<?>> spliterator()
      Creates a Spliterator over the cells in this set. This Spliterator reports Spliterator.DISTINCT, Spliterator.NONNULL, and Spliterator.SIZED.
      Specified by:
      spliterator in interface Collection<Cell<?>>
      Specified by:
      spliterator in interface Iterable<Cell<?>>
      Specified by:
      spliterator in interface Set<Cell<?>>
      Returns:
      a Spliterator over the cells in this set
    • iterator

      public Iterator<Cell<?>> iterator()
      Returns an Iterator over the cells in this set. The cells are returned in no particular order.
      Specified by:
      iterator in interface Collection<Cell<?>>
      Specified by:
      iterator in interface Iterable<Cell<?>>
      Specified by:
      iterator in interface Set<Cell<?>>
      Specified by:
      iterator in class AbstractCollection<Cell<?>>
      Returns:
      an Iterator over the cells in this set
    • size

      public int size()
      Specified by:
      size in interface Collection<Cell<?>>
      Specified by:
      size in interface Set<Cell<?>>
      Specified by:
      size in class AbstractCollection<Cell<?>>
      Returns: