Constructor and Description |
---|
MyMultiset()
Crea un multiset vuoto.
|
Modifier and Type | Method and Description |
---|---|
void |
add(E element)
Adds a single occurrence of the specified element to this multiset.
|
int |
add(E element,
int occurrences)
Adds a number of occurrences of an element to this multiset.
|
void |
clear()
Removes all of the elements from this multiset.
|
boolean |
contains(java.lang.Object element)
Determines whether this multiset contains the specified element.
|
int |
count(java.lang.Object element)
Returns the number of occurrences of an element in this multiset.
|
java.util.Set<E> |
elementSet()
Returns the set of distinct elements contained in this multiset.
|
boolean |
equals(java.lang.Object obj)
Compares the specified object with this multiset for equality.
|
int |
hashCode()
Returns the hash code for this multiset.
|
boolean |
isEmpty()
Returns true if this multiset contains no elements.
|
java.util.Iterator<E> |
iterator()
Returns an iterator for the multiset.
|
boolean |
remove(java.lang.Object element)
Removes a single occurrence of the specified element from this
multiset, if present.
|
int |
remove(java.lang.Object element,
int occurrences)
Removes a number of occurrences of the specified element from this
multiset.
|
int |
setCount(E element,
int count)
Adds or removes the necessary occurrences of an element such that the
element attains the desired count.
|
int |
size()
Returns the total number of elements in this multiset counting all the
occurrences.
|
public int size()
Multiset
[1,2,3,1,4].size()
must return five by
counting the two occurrences of 1
.public int count(java.lang.Object element)
Multiset
public int add(E element, int occurrences)
Multiset
public void add(E element)
Multiset
public int remove(java.lang.Object element, int occurrences)
Multiset
remove
in interface Multiset<E>
element
- the element to conditionally remove occurrences ofoccurrences
- the number of occurrences of the element to
remove. May be zero, in which case no change will
be made.public boolean remove(java.lang.Object element)
Multiset
public int setCount(E element, int count)
Multiset
public java.util.Set<E> elementSet()
Multiset
elementSet
in interface Multiset<E>
public java.util.Iterator<E> iterator()
Multiset
public boolean contains(java.lang.Object element)
Multiset
public void clear()
Multiset
public boolean isEmpty()
Multiset
public int hashCode()
Multiset
public boolean equals(java.lang.Object obj)
Multiset
true
if the given object is also a multiset and contains equal
elements with equal counts, regardless of order.