|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.colorado.collections.BagWithReceipts
public class BagWithReceipts
This class is a homework assignment;
A BagWithReceipts is a collection of references to Objects.
Each time an Object is placed in the bag, an integer receipt is provided.
The receipt can later be used to retrieve the Object.
Int.MAX_VALUE elements, this bag no longer works
because of arithmetic overflow.
| Constructor Summary | |
|---|---|
BagWithReceipts()
Initialize an empty BagWithReceipts. |
|
| Method Summary | |
|---|---|
int |
add(java.lang.Object element)
Put a reference to an object into this bag. |
java.lang.Object |
clone()
Generate a copy of this BagWithReceipts. |
int |
countOccurrences(java.lang.Object target)
Accessor method to count the number of occurrences of a particular element in this BagWithReceipts. |
Lister |
iterator()
Create an Iterator containing the elements of this bag. |
int[] |
receipts()
Create an array containing all the receipts of elements of this bag. |
boolean |
remove_by_receipt(int receipt)
Remove an element with a specified receipt. |
boolean |
remove(java.lang.Object target)
Remove one copy of a specified element from this BagWithReceipts. |
java.lang.Object |
retrieve(int receipt)
Get a copy of the element with the specified receipt. |
int |
size()
Determine the number of elements in this bag. |
boolean |
using_receipt(int receipt)
Determine whether a specified receipt is being used. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BagWithReceipts()
BagWithReceipts.
- - none
| Method Detail |
|---|
public int add(java.lang.Object element)
element - the element to be added to this bag
java.lang.OutOfMemoryError - Indicates insufficient memory for adding a new element.public java.lang.Object clone()
BagWithReceipts.
clone in class java.lang.Object- - none
BagWithReceipts.
Subsequent changes to the copy will not affect
the original, nor vice versa. Note that the return value must be
type cast to an BagWithReceipts before it can be used.
java.lang.OutOfMemoryError - Indicates insufficient memory for creating the clone.public int countOccurrences(java.lang.Object target)
BagWithReceipts.
target - an element to be counted
target occurs
in this bag. If target is non-null, then the occurrences
are found using the target.equals method.public Lister iterator()
Iterator containing the elements of this bag.
- - none
Iterator containing the elements of
this bag.
Iterator
returns all of its elements, then the subsequent behavior of the
Iterator is unspecified.public int[] receipts()
- - none
public boolean remove(java.lang.Object target)
BagWithReceipts.
target - an element to remove from this BagWithReceipts
target was found in this BagWithReceipts,
then one copy of
target has been removed and the method returns true.
Otherwise this BagWithReceipts remains unchanged
and the method returns false.
Note that if target is non-null, then
target.equals is used to find
target in the bag.public boolean remove_by_receipt(int receipt)
receipt - the receipt of
an element to remove from this BagWithReceipts
receipt
then that element has been removed and the method returns true.
Otherwise this BagWithReceipts remains unchanged
and the method returns false.public java.lang.Object retrieve(int receipt)
receipt - the receipt of an element
using_receipt(receipt)
public int size()
- - none
public boolean using_receipt(int receipt)
receipt - a possible receipt of an element
receipt
then the method returns true. Otherwise the method returns false.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||