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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
using System.Collections.Generic;
namespace Antlr4.Runtime.Misc
{
/// <summary>A generic set of integers.</summary>
/// <remarks>A generic set of integers.</remarks>
/// <seealso cref="IntervalSet"/>
public interface IIntSet
{
/// <summary>Adds the specified value to the current set.</summary>
/// <remarks>Adds the specified value to the current set.</remarks>
/// <param name="el">the value to add</param>
/// <exception>
/// IllegalStateException
/// if the current set is read-only
/// </exception>
void Add(int el);
/// <summary>
/// Modify the current
/// <see cref="IIntSet"/>
/// object to contain all elements that are
/// present in itself, the specified
/// <paramref name="set"/>
/// , or both.
/// </summary>
/// <param name="set">
/// The set to add to the current set. A
/// <see langword="null"/>
/// argument is
/// treated as though it were an empty set.
/// </param>
/// <returns>
///
/// <c>this</c>
/// (to support chained calls)
/// </returns>
/// <exception>
/// IllegalStateException
/// if the current set is read-only
/// </exception>
[return: NotNull]
IIntSet AddAll(IIntSet set);
/// <summary>
/// Return a new
/// <see cref="IIntSet"/>
/// object containing all elements that are
/// present in both the current set and the specified set
/// <paramref name="a"/>
/// .
/// </summary>
/// <param name="a">
/// The set to intersect with the current set. A
/// <see langword="null"/>
/// argument is treated as though it were an empty set.
/// </param>
/// <returns>
/// A new
/// <see cref="IIntSet"/>
/// instance containing the intersection of the
/// current set and
/// <paramref name="a"/>
/// . The value
/// <see langword="null"/>
/// may be returned in
/// place of an empty result set.
/// </returns>
[return: Nullable]
IIntSet And(IIntSet a);
/// <summary>
/// Return a new
/// <see cref="IIntSet"/>
/// object containing all elements that are
/// present in
/// <paramref name="elements"/>
/// but not present in the current set. The
/// following expressions are equivalent for input non-null
/// <see cref="IIntSet"/>
/// instances
/// <c>x</c>
/// and
/// <c>y</c>
/// .
/// <ul>
/// <li>
/// <c>x.complement(y)</c>
/// </li>
/// <li>
/// <c>y.subtract(x)</c>
/// </li>
/// </ul>
/// </summary>
/// <param name="elements">
/// The set to compare with the current set. A
/// <see langword="null"/>
/// argument is treated as though it were an empty set.
/// </param>
/// <returns>
/// A new
/// <see cref="IIntSet"/>
/// instance containing the elements present in
/// <paramref name="elements"/>
/// but not present in the current set. The value
/// <see langword="null"/>
/// may be returned in place of an empty result set.
/// </returns>
[return: Nullable]
IIntSet Complement(IIntSet elements);
/// <summary>
/// Return a new
/// <see cref="IIntSet"/>
/// object containing all elements that are
/// present in the current set, the specified set
/// <paramref name="a"/>
/// , or both.
/// <p>
/// This method is similar to
/// <see cref="AddAll(IIntSet)"/>
/// , but returns a new
/// <see cref="IIntSet"/>
/// instance instead of modifying the current set.</p>
/// </summary>
/// <param name="a">
/// The set to union with the current set. A
/// <see langword="null"/>
/// argument
/// is treated as though it were an empty set.
/// </param>
/// <returns>
/// A new
/// <see cref="IIntSet"/>
/// instance containing the union of the current
/// set and
/// <paramref name="a"/>
/// . The value
/// <see langword="null"/>
/// may be returned in place of an
/// empty result set.
/// </returns>
[return: Nullable]
IIntSet Or(IIntSet a);
/// <summary>
/// Return a new
/// <see cref="IIntSet"/>
/// object containing all elements that are
/// present in the current set but not present in the input set
/// <paramref name="a"/>
/// .
/// The following expressions are equivalent for input non-null
/// <see cref="IIntSet"/>
/// instances
/// <c>x</c>
/// and
/// <c>y</c>
/// .
/// <ul>
/// <li>
/// <c>y.subtract(x)</c>
/// </li>
/// <li>
/// <c>x.complement(y)</c>
/// </li>
/// </ul>
/// </summary>
/// <param name="a">
/// The set to compare with the current set. A
/// <see langword="null"/>
/// argument is treated as though it were an empty set.
/// </param>
/// <returns>
/// A new
/// <see cref="IIntSet"/>
/// instance containing the elements present in
/// <c>elements</c>
/// but not present in the current set. The value
/// <see langword="null"/>
/// may be returned in place of an empty result set.
/// </returns>
[return: Nullable]
IIntSet Subtract(IIntSet a);
/// <summary>Return the total number of elements represented by the current set.</summary>
/// <remarks>Return the total number of elements represented by the current set.</remarks>
/// <returns>
/// the total number of elements represented by the current set,
/// regardless of the manner in which the elements are stored.
/// </returns>
int Count
{
get;
}
/// <summary>
/// Returns
/// <see langword="true"/>
/// if this set contains no elements.
/// </summary>
/// <returns>
///
/// <see langword="true"/>
/// if the current set contains no elements; otherwise,
/// <see langword="false"/>
/// .
/// </returns>
bool IsNil
{
get;
}
/// <summary><inheritDoc/></summary>
bool Equals(object obj);
/// <summary>
/// Returns the single value contained in the set, if
/// <see cref="Count()"/>
/// is 1;
/// otherwise, returns
/// <see cref="TokenConstants.InvalidType"/>
/// .
/// </summary>
/// <returns>
/// the single value contained in the set, if
/// <see cref="Count()"/>
/// is 1;
/// otherwise, returns
/// <see cref="TokenConstants.InvalidType"/>
/// .
/// </returns>
int SingleElement
{
get;
}
/// <summary>
/// Returns
/// <see langword="true"/>
/// if the set contains the specified element.
/// </summary>
/// <param name="el">The element to check for.</param>
/// <returns>
///
/// <see langword="true"/>
/// if the set contains
/// <paramref name="el"/>
/// ; otherwise
/// <see langword="false"/>
/// .
/// </returns>
bool Contains(int el);
/// <summary>Removes the specified value from the current set.</summary>
/// <remarks>
/// Removes the specified value from the current set. If the current set does
/// not contain the element, no changes are made.
/// </remarks>
/// <param name="el">the value to remove</param>
/// <exception>
/// IllegalStateException
/// if the current set is read-only
/// </exception>
void Remove(int el);
/// <summary>Return a list containing the elements represented by the current set.</summary>
/// <remarks>
/// Return a list containing the elements represented by the current set. The
/// list is returned in ascending numerical order.
/// </remarks>
/// <returns>
/// A list containing all element present in the current set, sorted
/// in ascending numerical order.
/// </returns>
[return: NotNull]
IList<int> ToList();
/// <summary><inheritDoc/></summary>
string ToString();
}
}