Interface Set<E>

  • All Known Subinterfaces:
    OrderedSet<E>

    public interface Set<E>
    Provides an interface for a set whose elements have type E.

    Set Invariant: A finite set of non-null elements of type E is maintained.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean contains​(E e)
      Reports whether a given element belongs to this set.

      void include​(E e)
      Adds an input element to this set, throwing an ElementFoundException if this element already belongs to it.

      void remove​(E e)
      Removes an input element to this set, throwing a NoSuchElementException if this element does not belong to it.
    • Method Detail

      • contains

        boolean contains​(E e)
                  throws java.lang.NullPointerException
        Reports whether a given element belongs to this set.

        Parameters:
        e - the element to be searched for
        Returns:
        true if this element is found; false otherwise

        Precondition:

        1. The Set Invariant is satisfied.
        2. A value e with type E has been given as input.
        Postcondition:

        1. If the given element e is null then a NullPointerException is thrown.
        2. Otherwise (that is, if the given element is not null), if the given element e belongs to this set then “true” is returned; “false” is returned otherwise.
        Throws:
        java.lang.NullPointerException - if the given element is null
      • include

        void include​(E e)
              throws java.lang.NullPointerException,
                     ElementFoundException
        Adds an input element to this set, throwing an ElementFoundException if this element already belongs to it.

        Parameters:
        e - the element to be added to this set
        Throws:
        java.lang.NullPointerException - if the given element is null
        ElementFoundException - if this element is not null but is already in the set

        Precondition:

        1. The Set Invariant is satisfied.
        2. A value e with type E has been given as input.
        Postcondition:

        1. The Set Invariant is satisfied.
        2. If the input element is null then a NullPointerException is thrown.
        3. If the input element is not null and it is not already an element of this set, then this element is added to it.
        4. If the input element is not null and it is already am element of this set then an ElementFoundException is thrown (and this set is not changed).
      • remove

        void remove​(E e)
             throws java.lang.NullPointerException,
                    java.util.NoSuchElementException
        Removes an input element to this set, throwing a NoSuchElementException if this element does not belong to it.

        Parameters:
        e - the element to be removed from this set
        Throws:
        java.lang.NullPointerException - if the given element is null
        java.util.NoSuchElementException - if this element was not in this set

        Precondition:

        1. The Set Invariant is satisfied.
        2. A value e with type E has been given as input.
        Postcondition:

        1. If the input element is null then a NullPointerException is thrown.
        2. If the input element is not null and is an element of this set, then the input element is removed from this set.
        3. If the input element is not null and is not an element of this set then a NoSuchElementException is thrown (and this set is not changed).