-
Notifications
You must be signed in to change notification settings - Fork 7
/
SSet.java
125 lines (109 loc) · 3.58 KB
/
SSet.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
113
114
115
116
117
118
119
120
121
122
123
124
125
import java.util.Comparator;
import java.util.Iterator;
/**
* The SSet<T> interface is a simple interface that allows a class to implement
* all the functionality of the (more complicated) SortedSet<T> interface.
*
* This class is a modified version of the class created by Professor Morin.
*
* @param <T>
*/
public interface SSet<T> extends Iterable<T> {
/**
* @return the comparator used by this SSet
*/
public Comparator<? super T> comparator();
/**
* @return the number of elements in this SSet
*/
public int size();
/**
* Find the smallest element in the SSet that is greater than or equal to x.
*
* @param x
* @return the smallest element in the SSet that is greater than or equal to
* x or null if no such element exists
*/
public T find(T x);
/**
* Find the smallest element in the SSet that is greater than or equal to x.
* If x is null, return the smallest element in the SSet
*
* @param x
* @return the smallest element in the SSet that is greater than or equal to
* x or null if no such element exists. If x is null then the
* smallest element in the SSet
*/
public T findGE(T x);
/**
* Find the largest element in the SSet that is less than to x. If x is
* null, return the largest element in the SSet
*
* @param x
* @return the largest element in the SSet that is less than x. If x is null
* then the smallest element in the SSet
*/
public T findLT(T x);
/**
* Add the element x to the SSet
*
* @param x
* @return true if the element was added or false if x was already in the
* set
*/
public boolean add(T x);
/**
* Remove the element x from the SSet
*
* @param x
* @return true if x was removed and false if x was not removed (because x
* was not present)
*/
public boolean remove(T x);
/**
* Clear the SSet, removing all elements from the set
*/
public void clear();
/**
* Return an iterator that iterates over the elements in sorted order,
* starting at the first element that is greater than or equal to x.
*/
public Iterator<T> iterator(T x);
/**
* The following operations follow the mathematical definitions of a SET. For more information,
* look at the interface, defined in Java's API jva.util.SET
*/
/** Modifies the current SSet with the resulting union with sset.
* Again, union here follows the definition of a set union.
* @param sset
* @return boolean upon success
*/
public boolean unionWith(SSet<T> sset);
/** Modifies the current SSet with the resulting intersection with sset.
* @param sset
* @return boolean upon success
*/
public boolean intersectWith(SSet<T> sset);
/** Modifies the current SSet with the resulting difference with sset.
* Difference here means that all elements that belong to the current set, but
* do not belong to the input set, i.e. sset, are retained.
* @param sset
* @return boolean upon success
*/
public boolean differenceWith(SSet<T> sset);
/** Checks if all elements in the current Set exist in the sset.
* @param sset
* @return boolean - true if it's a subset, false otherwise
*/
public boolean subsetOf(SSet<T> sset);
/** Checks if x is a member of the current set.
* @param x
* @return boolean - true if x is a member, false otherwise
*/
public boolean belongsTo(T x);
/**
* Convenience method. Create a string representing all elements, with useful information for testing/debugging.
* @return String
*/
public String toString();
}