|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object MultiSet
public class MultiSet
Stores a number of objects without using extra space for duplicates, which are determined by equals(). No specific ordering of objects is guaranteed. Example use: store a probability distribution, use findKth to obtain a random number in that distribution.
Constructor Summary | |
---|---|
MultiSet()
Produces a new, empty MultiSet. |
Method Summary | |
---|---|
void |
add(java.lang.Object o)
Adds the specified object once to the data structure. |
void |
add(java.lang.Object o,
int times)
Adds an object several times to the data structure. |
java.lang.Object |
findKth(int k)
Gets an object stored in this MultiSet. |
int |
getMultiplicity(java.lang.Object o)
Returns the multiplicity stored of the object in question, some nonnegative integer. |
int |
numEntries()
Gets the number of distinct entries in this MultiSet. |
int |
size()
Gets the number of entries, including multiplicity, in this MultiSet. |
java.util.ArrayList |
values()
Gets a list of distinct objects stored in this MultiSet. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MultiSet()
Method Detail |
---|
public int getMultiplicity(java.lang.Object o)
o
- the object in question
public void add(java.lang.Object o)
o
- the object in questionpublic void add(java.lang.Object o, int times)
o
- the object in questiontimes
- a positive integer
java.lang.IllegalArgumentException
- if times is less than 1public int numEntries()
public java.lang.Object findKth(int k)
k
- the position of the object to return
public int size()
public java.util.ArrayList values()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |