Interface Multiset<T>

All Known Implementing Classes:
ArrayMultiset

public interface Multiset<T>
An unordered collection that allows duplicates.
Version:
1.0
Author:
Jessica Masters
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(T element)
    Adds a new element to this multiset.
    void
    Removes all elements from the multiset.
    boolean
    contains(T element)
    Determines if the multiset contains the specified element.
    int
    Counts the number of times the specified element appears in the multiset.
    boolean
    Determines if there are any elements in the multiset.
    Removes one unspecified element from the multiset, if possible.
    boolean
    remove(T element)
    Removes one occurrence of the specified element from the multiset, if possible.
    int
    Gets the number of elements in the multiset.
  • Method Details

    • add

      boolean add(T element)
      Adds a new element to this multiset.
      Parameters:
      element - element to be added to the multiset
      Returns:
      true if the element was successfully added and false otherwise.
    • remove

      T remove()
      Removes one unspecified element from the multiset, if possible.
      Returns:
      The removed element or null (when the multiset is empty)
    • remove

      boolean remove(T element)
      Removes one occurrence of the specified element from the multiset, if possible.
      Parameters:
      element - element to be removed from the multiset
      Returns:
      true if the element was successfully removed and false otherwise.
    • getOccurrencesOf

      int getOccurrencesOf(T element)
      Counts the number of times the specified element appears in the multiset.
      Parameters:
      element - the element to be counted
      Returns:
      The number of times the element appears in the multiset.
    • contains

      boolean contains(T element)
      Determines if the multiset contains the specified element.
      Parameters:
      element - the element to find
      Returns:
      true if the element is in the multiset and false otherwise.
    • isEmpty

      boolean isEmpty()
      Determines if there are any elements in the multiset.
      Returns:
      true if there are no elements in the multiset and false otherwise.
    • size

      int size()
      Gets the number of elements in the multiset.
      Returns:
      The number of elements in the multiset.
    • clear

      void clear()
      Removes all elements from the multiset.