1: import java.util.Iterator;
3: /**
4: * @param <T> the base type of this Bag
5: * @author Mark Young (A00000000)
6: */
7: public interface Bag<T> {
9: /**
10: * Remove an item from this Bag. The item to remove is at the discretion of
11: * the implementation.
12: *
13: * @return an arbitrary item removed from this Bag
14: */
15: public T remove();
17: /**
18: * Count how many times the given item appears in this Bag. That is, count
19: * each {@code e} such that {@code Objects.equals(anItem, e)}.
20: *
21: * @param anItem the item to count
22: * @return how many times that item appears in this Bag
23: */
24: public int count(T anItem);
25:
26: /*
27: * Some default implementations for methods. I don't know why Collection
28: * doesn't give these itself!
29: */
30:
31: public int size();
33: public boolean isEmpty();
35: public boolean add(String newEntry);
37: public boolean remove(Object anEntry);
39: public void clear();
41: public boolean contains(Object anEntry);
43: public String[] toArray();
45: public <T> T[] toArray(T[] starter);
47: public Iterator<T> iterator();
49: }