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 TypeMethodDescriptionboolean
Adds a new element to this multiset.void
clear()
Removes all elements from the multiset.boolean
Determines if the multiset contains the specified element.int
getOccurrencesOf
(T element) Counts the number of times the specified element appears in the multiset.boolean
isEmpty()
Determines if there are any elements in the multiset.remove()
Removes one unspecified element from the multiset, if possible.boolean
Removes one occurrence of the specified element from the multiset, if possible.int
size()
Gets the number of elements in the multiset.
-
Method Details
-
add
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
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
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
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.
-