-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBagInterface.java
More file actions
67 lines (55 loc) · 2.54 KB
/
BagInterface.java
File metadata and controls
67 lines (55 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
An interface that describes the operations of a bag of objects.
@author Frank M. Carrano
@author Timothy M. Henry
@version 5.0
*/
public interface BagInterface<T>
{
/** Gets the current number of entries in this bag.
@return The integer number of entries currently in the bag. */
public int getCurrentSize();
/** Sees whether this bag is empty.
@return True if the bag is empty, or false if not. */
public boolean isEmpty();
/** Adds a new entry to this bag.
@param newEntry The object to be added as a new entry.
@return True if the addition is successful, or false if not. */
public boolean add(T newEntry);
/** Removes one unspecified entry from this bag, if possible.
@return Either the removed entry, if the removal.
was successful, or null. */
public T remove();
/** Removes one occurrence of a given entry from this bag, if possible.
@param anEntry The entry to be removed.
@return True if the removal was successful, or false if not. */
public boolean remove(T anEntry);
/** Removes all entries from this bag. */
public void clear();
/** Counts the number of times a given entry appears in this bag.
@param anEntry The entry to be counted.
@return The number of times anEntry appears in the bag. */
public int getFrequencyOf(T anEntry);
/** Tests whether this bag contains a given entry.
@param anEntry The entry to find.
@return True if the bag contains anEntry, or false if not. */
public boolean contains(T anEntry);
/** Retrieves all entries that are in this bag.
@return A newly allocated array of all the entries in the bag.
Note: If the bag is empty, the returned array is empty. */
public T[] toArray();
/** Combines contents of two bags into another bag.
@param bag2 Second bag.
@return combined, Combined bag of contenets from both bags. */
public BagInterface<T> union(BagInterface<T> bag2);
/** Combines only like contents of two bags into another bag.
@param bag2 Second bag.
@return combined, combined bag of like contents. */
public BagInterface<T> intersection(BagInterface<T> bag2);
/** Creates a collection of entries that would be left in one collection, after removing
* those that also occur in the second.
@param bag2 Second bag.
@return compare, new collection of entries after second bag contents are removed from first bag. */
public BagInterface<T> difference(BagInterface<T> bag2);
//public BagInterface<T> difference2(BagInterface<T> bag2);
} // end BagInterface