|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--IntBag
Stores a bounded collection of integers. Duplicates are allowed.
Field Summary | |
private int |
count
|
private int |
current
|
private int[] |
elements
|
static int |
MAX_SIZE
Maximum size of the set. |
Constructor Summary | |
IntBag()
Creates an empty collection. |
Method Summary | |
private int |
findPosition(int x)
Find the position of x in the first count elements of the array elements. |
int |
getNext()
Gets next integer from collection |
boolean |
hasNext()
Checks if collection has another element |
void |
insert(int x)
Insert the integer x into the collection. |
boolean |
isMember(int x)
Determine whether or not the integer x is in the collection. |
int |
numberOfOccurrences(int x)
Determines number of times integer x is found in the collection |
void |
remove(int x)
Remove the first found integer x from the collection. |
void |
removeAllOccurrences(int x)
Removes all occurences of integer x from the collection. |
private boolean |
removeOne(int x)
Removes integer x from collection |
int |
size()
Determine the size of the collection. |
void |
start()
Resets current to zero |
Methods inherited from class java.lang.Object |
|
Field Detail |
public static final int MAX_SIZE
private int[] elements
private int count
private int current
Constructor Detail |
public IntBag()
Method Detail |
public void insert(int x) throws FullExc
x
- the integer to be addedFullExc
- there are MAX_SIZE elements in the setpublic void remove(int x) throws NotFoundExc
x
- the integer to be removedNotFoundExc
- x is not in the collectionpublic void removeAllOccurrences(int x) throws NotFoundExc
x
- the integer to be removedNotFoundExc
- x is not in the collectionpublic boolean isMember(int x)
x
- the integer to be checkedpublic int size()
public int numberOfOccurrences(int x) throws NotFoundExc
x
- the integer to findNotFoundExc
- integer x not found in collectionpublic void start()
public boolean hasNext() throws UnstableIteratorExc
UnstableIteratorExc
- Iterator out of boundspublic int getNext() throws UnstableIteratorExc
UnstableIteratorExc
- Iterator out of boundsprivate int findPosition(int x)
private boolean removeOne(int x)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |