public final class ArrayBag<T> extends java.lang.Object implements BagInterface<T>
| Constructor and Description |
|---|
ArrayBag()
Creates an empty bag whose initial capacity is 25.
|
ArrayBag(int desiredCapacity)
Creates an empty bag having a given initial capacity.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T newEntry)
Adds a new entry to this bag.
|
void |
clear()
Removes all entries from this bag.
|
boolean |
contains(T anEntry)
Tests whether this bag contains a given entry.
|
int |
getCurrentSize()
Gets the current number of entries in this bag.
|
int |
getFrequencyOf(T anEntry)
Counts the number of times a given entry appears in this bag.
|
boolean |
isEmpty()
Sees whether this bag is empty.
|
T |
remove()
Removes one unspecified entry from this bag, if possible.
|
boolean |
remove(T anEntry)
Removes one occurrence of a given entry from this bag.
|
T[] |
toArray()
Retrieves all entries that are in this bag.
|
java.lang.String |
toString()
Override the toString() method so that we get a more useful display of
the contents in the bag.
|
public ArrayBag()
public ArrayBag(int desiredCapacity)
desiredCapacity - The integer capacity desired.public boolean add(T newEntry)
add in interface BagInterface<T>newEntry - The object to be added as a new entry.public T[] toArray()
toArray in interface BagInterface<T>public boolean isEmpty()
isEmpty in interface BagInterface<T>public int getCurrentSize()
getCurrentSize in interface BagInterface<T>public int getFrequencyOf(T anEntry)
getFrequencyOf in interface BagInterface<T>anEntry - The entry to be counted.public boolean contains(T anEntry)
contains in interface BagInterface<T>anEntry - The entry to locate.public void clear()
clear in interface BagInterface<T>public T remove()
remove in interface BagInterface<T>public boolean remove(T anEntry)
remove in interface BagInterface<T>anEntry - The entry to be removed.public java.lang.String toString()
toString in class java.lang.Object