-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyCollectionInterface.java
More file actions
92 lines (74 loc) · 2.72 KB
/
MyCollectionInterface.java
File metadata and controls
92 lines (74 loc) · 2.72 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* An interface that describes all the operations to be implemented in a
* collection class. It uses generic object (T) and can be used to implement a
* collection class to store generic objects.
* @author Dr. Salim Lakhani
* @version 1.1, 2017, February 7
*/
public interface MyCollectionInterface<T> {
/**
* Adds a new entry to this collection
*
* @param newItem The object to be added to the collection
* @return True if the addition is successful, or false if not.
*/
public boolean add (T newItem);
//************************************************************************
/**
* Removes one unspecified entry from the collection, 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 collection.
*
* @param anEntry The entry to be removed.
* @return true if the removal was successful, false if not.
*/
public boolean remove (T anEntry);
//************************************************************************
/**
* Removes all entries from this collection.
*/
public void clear();
//************************************************************************
/**
* Gets the current number of entries in this collection.
*
* @return The integer number of entries currently in the collection.
*/
public int getCurrentSize();
//************************************************************************
/**
* Check to see if the collection is empty.
*
* @return True if the collection is empty, or false if not.
*/
public boolean isEmpty();
//************************************************************************
/**
* Counts the number of times a given entry appears in this collection.
*
* @param anEntry The entry to be counted.
* @return The number of times anEntry appears in the collection.
*/
public int getFrequencyOf(T anEntry);
//************************************************************************
/**
* Tests whether this collection contains a given entry.
*
* @param anEntry The entry to locate.
* @return True if the collection contains anEntry, or false if not.
*/
public boolean contains (T anEntry);
//************************************************************************
/**
* Retrieves all entries that are in this collection.
*
* @return A newly allocated array of all the entries in the collection.
* Note: If the collection is empty, the returned array is empty.
*/
public Object[] toArray ();
}