Class ArrayMultiset<T>

java.lang.Object
ArrayMultiset<T>
All Implemented Interfaces:
Multiset<T>

public class ArrayMultiset<T> extends Object implements Multiset<T>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    ArrayMultiset(int capacity)
     
  • 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.
    boolean
     
    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.
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • ArrayMultiset

      public ArrayMultiset(int capacity)
    • ArrayMultiset

      public ArrayMultiset()
  • Method Details

    • add

      public boolean add(T element)
      Description copied from interface: Multiset
      Adds a new element to this multiset.
      Specified by:
      add in interface Multiset<T>
      Parameters:
      element - element to be added to the multiset
      Returns:
      true if the element was successfully added and false otherwise.
    • remove

      public T remove()
      Description copied from interface: Multiset
      Removes one unspecified element from the multiset, if possible.
      Specified by:
      remove in interface Multiset<T>
      Returns:
      The removed element or null (when the multiset is empty)
    • remove

      public boolean remove(T element)
      Description copied from interface: Multiset
      Removes one occurrence of the specified element from the multiset, if possible.
      Specified by:
      remove in interface Multiset<T>
      Parameters:
      element - element to be removed from the multiset
      Returns:
      true if the element was successfully removed and false otherwise.
    • getOccurrencesOf

      public int getOccurrencesOf(T element)
      Description copied from interface: Multiset
      Counts the number of times the specified element appears in the multiset.
      Specified by:
      getOccurrencesOf in interface Multiset<T>
      Parameters:
      element - the element to be counted
      Returns:
      The number of times the element appears in the multiset.
    • contains

      public boolean contains(T element)
      Description copied from interface: Multiset
      Determines if the multiset contains the specified element.
      Specified by:
      contains in interface Multiset<T>
      Parameters:
      element - the element to find
      Returns:
      true if the element is in the multiset and false otherwise.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Multiset
      Determines if there are any elements in the multiset.
      Specified by:
      isEmpty in interface Multiset<T>
      Returns:
      true if there are no elements in the multiset and false otherwise.
    • isFull

      public boolean isFull()
    • size

      public int size()
      Description copied from interface: Multiset
      Gets the number of elements in the multiset.
      Specified by:
      size in interface Multiset<T>
      Returns:
      The number of elements in the multiset.
    • clear

      public void clear()
      Description copied from interface: Multiset
      Removes all elements from the multiset.
      Specified by:
      clear in interface Multiset<T>
    • toString

      public String toString()
      Overrides:
      toString in class Object