public final class Bag<T> extends java.lang.Object implements BagInterface<T>
Constructor and Description |
---|
Bag() |
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 number of entries currently 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, if possible.
|
T[] |
toArray()
Retrieves all entries that are in this bag.
|
public boolean isEmpty()
isEmpty
in interface BagInterface<T>
public int getCurrentSize()
getCurrentSize
in interface BagInterface<T>
public boolean add(T newEntry)
add
in interface BagInterface<T>
newEntry
- The object to be added as a new entrypublic T[] toArray()
toArray
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.