-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionInterface.java
More file actions
36 lines (29 loc) · 1.28 KB
/
CollectionInterface.java
File metadata and controls
36 lines (29 loc) · 1.28 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
//----------------------------------------------------------------------------
// CollectionInterface.java by Dale/Joyce/Weems Chapter 5
//
// Interface for a class that implements a collection of T.
// A collection allows addition, removal, and access of elements.
//
// Nullelements are not allowed. Duplicate elements are allowed.
//----------------------------------------------------------------------------
public interface CollectionInterface<T>
{
boolean add(T element);
// Attempts to add element to this collection.
// Returns true if successful, false otherwise.
T get(T target);
// Returns an element e from this collection such that e.equals(target).
// If no such e exists, returns null.
boolean contains(T target);
// Returns true if this collection contains an element e such that
// e.equals(target); otherwise returns false.
boolean remove (T target);
// Removes an element e from this collection such that e.equals(target)
// and returns true. If no such e exists, returns false.
boolean isFull();
// Returns true if this collection is full; otherwise, returns false.
boolean isEmpty();
// Returns true if this collection is empty; otherwise, returns false.
int size();
// Returns the number of elements in this collection.
}