This repository was archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSortedSet.java
112 lines (98 loc) · 3.46 KB
/
SortedSet.java
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package assign08;
import java.util.ArrayList;
import java.util.Collection;
import java.util.NoSuchElementException;
/**
* An interface for representing a sorted set of generically-typed items. By
* definition, a set contains no duplicate items. The items are ordered using
* their natural ordering (i.e., each item must be Comparable). Note that this
* interface is much like Java's SortedSet, but simpler.
*
* @author Erin Parker
* @version March 17, 2021
*/
public interface SortedSet<Type extends Comparable<? super Type>> {
/**
* Ensures that this set contains the specified item.
*
* @param item - the item whose presence is ensured in this set
* @return true if this set changed as a result of this method call (that is, if
* the input item was actually inserted); otherwise, returns false
*/
public boolean add(Type item);
/**
* Ensures that this set contains all items in the specified collection.
*
* @param items - the collection of items whose presence is ensured in this set
* @return true if this set changed as a result of this method call (that is, if
* any item in the input collection was actually inserted); otherwise,
* returns false
*/
public boolean addAll(Collection<? extends Type> items);
/**
* Removes all items from this set. The set will be empty after this method
* call.
*/
public void clear();
/**
* Determines if there is an item in this set that is equal to the specified
* item.
*
* @param item - the item sought in this set
* @return true if there is an item in this set that is equal to the input item;
* otherwise, returns false
*/
public boolean contains(Type item);
/**
* Determines if for each item in the specified collection, there is an item in
* this set that is equal to it.
*
* @param items - the collection of items sought in this set
* @return true if for each item in the specified collection, there is an item
* in this set that is equal to it; otherwise, returns false
*/
public boolean containsAll(Collection<? extends Type> items);
/**
* Returns the first (i.e., smallest) item in this set.
*
* @throws NoSuchElementException if the set is empty
*/
public Type first() throws NoSuchElementException;
/**
* Returns true if this set contains no items.
*/
public boolean isEmpty();
/**
* Returns the last (i.e., largest) item in this set.
*
* @throws NoSuchElementException if the set is empty
*/
public Type last() throws NoSuchElementException;
/**
* Ensures that this set does not contain the specified item.
*
* @param item - the item whose absence is ensured in this set
* @return true if this set changed as a result of this method call (that is, if
* the input item was actually removed); otherwise, returns false
*/
public boolean remove(Type item);
/**
* Ensures that this set does not contain any of the items in the specified
* collection.
*
* @param items - the collection of items whose absence is ensured in this set
* @return true if this set changed as a result of this method call (that is, if
* any item in the input collection was actually removed); otherwise,
* returns false
*/
public boolean removeAll(Collection<? extends Type> items);
/**
* Returns the number of items in this set.
*/
public int size();
/**
* Returns an ArrayList containing all of the items in this set, in sorted
* order.
*/
public ArrayList<Type> toArrayList();
}