Parcourir la source

Fixes #647 use typed empty lists

Tyler Matthews il y a 9 ans
Parent
révision
6c516fc78f

+ 1
- 1
exercises/custom-set/src/example/java/CustomSet.java Voir le fichier

11
     private Set<T> set;
11
     private Set<T> set;
12
 
12
 
13
     public CustomSet() {
13
     public CustomSet() {
14
-        this(Collections.EMPTY_LIST);
14
+        this(Collections.emptyList());
15
     }
15
     }
16
 
16
 
17
     public CustomSet(Collection<T> data) {
17
     public CustomSet(Collection<T> data) {

+ 27
- 27
exercises/custom-set/src/test/java/CustomSetTest.java Voir le fichier

12
     @Test
12
     @Test
13
     public void setsWithNoElementsAreEmpty() {
13
     public void setsWithNoElementsAreEmpty() {
14
         final boolean actual
14
         final boolean actual
15
-                = new CustomSet<>(Collections.EMPTY_LIST)
15
+                = new CustomSet<>(Collections.emptyList())
16
                         .isEmpty();
16
                         .isEmpty();
17
         assertTrue(actual);
17
         assertTrue(actual);
18
     }
18
     }
31
     @Test
31
     @Test
32
     public void nothingIsContainedInAnEmptySet() {
32
     public void nothingIsContainedInAnEmptySet() {
33
         final boolean actual
33
         final boolean actual
34
-                = new CustomSet<>(Collections.EMPTY_LIST)
34
+                = new CustomSet<>(Collections.emptyList())
35
                         .contains(1);
35
                         .contains(1);
36
 
36
 
37
         assertFalse(actual);
37
         assertFalse(actual);
61
     @Test
61
     @Test
62
     public void emptySetIsASubsetOfAnotherEmptySet() {
62
     public void emptySetIsASubsetOfAnotherEmptySet() {
63
         final boolean actual
63
         final boolean actual
64
-                = new CustomSet<>(Collections.EMPTY_LIST)
64
+                = new CustomSet<>(Collections.emptyList())
65
                         .isSubset(
65
                         .isSubset(
66
-                                new CustomSet<>(Collections.EMPTY_LIST)
66
+                                new CustomSet<>(Collections.emptyList())
67
                         );
67
                         );
68
 
68
 
69
         assertTrue(actual);
69
         assertTrue(actual);
75
         final boolean actual
75
         final boolean actual
76
                 = new CustomSet<>(Collections.singletonList(1))
76
                 = new CustomSet<>(Collections.singletonList(1))
77
                         .isSubset(
77
                         .isSubset(
78
-                                new CustomSet<>(Collections.EMPTY_LIST)
78
+                                new CustomSet<>(Collections.emptyList())
79
                         );
79
                         );
80
 
80
 
81
         assertTrue(actual);
81
         assertTrue(actual);
85
     @Test
85
     @Test
86
     public void nonEmptySetIsNotASubsetOfEmptySet() {
86
     public void nonEmptySetIsNotASubsetOfEmptySet() {
87
         final boolean actual
87
         final boolean actual
88
-                = new CustomSet<>(Collections.EMPTY_LIST)
88
+                = new CustomSet<>(Collections.emptyList())
89
                         .isSubset(
89
                         .isSubset(
90
                                 new CustomSet<>(Collections.singletonList(1))
90
                                 new CustomSet<>(Collections.singletonList(1))
91
                         );
91
                         );
133
     @Test
133
     @Test
134
     public void theEmptySetIsDisjointWithItself() {
134
     public void theEmptySetIsDisjointWithItself() {
135
         final boolean actual
135
         final boolean actual
136
-                = new CustomSet<>(Collections.EMPTY_LIST)
136
+                = new CustomSet<>(Collections.emptyList())
137
                         .isDisjoint(
137
                         .isDisjoint(
138
-                                new CustomSet<>(Collections.EMPTY_LIST)
138
+                                new CustomSet<>(Collections.emptyList())
139
                         );
139
                         );
140
 
140
 
141
         assertTrue(actual);
141
         assertTrue(actual);
145
     @Test
145
     @Test
146
     public void emptySetIsDisjointWithNonEmptySet() {
146
     public void emptySetIsDisjointWithNonEmptySet() {
147
         final boolean actual
147
         final boolean actual
148
-                = new CustomSet<>(Collections.EMPTY_LIST)
148
+                = new CustomSet<>(Collections.emptyList())
149
                         .isDisjoint(
149
                         .isDisjoint(
150
                                 new CustomSet<>(Collections.singletonList(1))
150
                                 new CustomSet<>(Collections.singletonList(1))
151
                         );
151
                         );
159
         final boolean actual
159
         final boolean actual
160
                 = new CustomSet<>(Collections.singletonList(1))
160
                 = new CustomSet<>(Collections.singletonList(1))
161
                         .isDisjoint(
161
                         .isDisjoint(
162
-                                new CustomSet<>(Collections.EMPTY_LIST)
162
+                                new CustomSet<>(Collections.emptyList())
163
                         );
163
                         );
164
 
164
 
165
         assertTrue(actual);
165
         assertTrue(actual);
193
     @Test
193
     @Test
194
     public void emptySetsAreEqual() {
194
     public void emptySetsAreEqual() {
195
         final boolean actual
195
         final boolean actual
196
-                = new CustomSet<>(Collections.EMPTY_LIST)
196
+                = new CustomSet<>(Collections.emptyList())
197
                         .equals(
197
                         .equals(
198
-                                new CustomSet<>(Collections.EMPTY_LIST)
198
+                                new CustomSet<>(Collections.emptyList())
199
                         );
199
                         );
200
 
200
 
201
         assertTrue(actual);
201
         assertTrue(actual);
205
     @Test
205
     @Test
206
     public void emptySetIsNotEqualToNonEmptySet() {
206
     public void emptySetIsNotEqualToNonEmptySet() {
207
         final boolean actual
207
         final boolean actual
208
-                = new CustomSet<>(Collections.EMPTY_LIST)
208
+                = new CustomSet<>(Collections.emptyList())
209
                         .equals(
209
                         .equals(
210
                                 new CustomSet<>(Arrays.asList(1, 2, 3))
210
                                 new CustomSet<>(Arrays.asList(1, 2, 3))
211
                         );
211
                         );
219
         final boolean actual
219
         final boolean actual
220
                 = new CustomSet<>(Arrays.asList(1, 2, 3))
220
                 = new CustomSet<>(Arrays.asList(1, 2, 3))
221
                         .equals(
221
                         .equals(
222
-                                new CustomSet<>(Collections.EMPTY_LIST)
222
+                                new CustomSet<>(Collections.emptyList())
223
                         );
223
                         );
224
 
224
 
225
         assertFalse(actual);
225
         assertFalse(actual);
258
                         Collections.unmodifiableList(Collections.singletonList(element))
258
                         Collections.unmodifiableList(Collections.singletonList(element))
259
                 );
259
                 );
260
         final CustomSet<Integer> actual
260
         final CustomSet<Integer> actual
261
-                = new CustomSet<>(Collections.EMPTY_LIST);
261
+                = new CustomSet<>(Collections.emptyList());
262
 
262
 
263
         actual.add(element);
263
         actual.add(element);
264
 
264
 
306
     @Test
306
     @Test
307
     public void intersectionOfTwoEmptySetsIsAnEmptySet() {
307
     public void intersectionOfTwoEmptySetsIsAnEmptySet() {
308
         final CustomSet<Integer> actual
308
         final CustomSet<Integer> actual
309
-                = new CustomSet<>(Collections.EMPTY_LIST)
309
+                = new CustomSet<Integer>(Collections.emptyList())
310
                         .getIntersection(
310
                         .getIntersection(
311
-                                new CustomSet<>(Collections.EMPTY_LIST)
311
+                                new CustomSet<>(Collections.emptyList())
312
                         );
312
                         );
313
 
313
 
314
         assertNotNull(actual);
314
         assertNotNull(actual);
319
     @Test
319
     @Test
320
     public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
320
     public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
321
         final CustomSet<Integer> actual
321
         final CustomSet<Integer> actual
322
-                = new CustomSet<>(Collections.EMPTY_LIST)
322
+                = new CustomSet<Integer>(Collections.emptyList())
323
                         .getIntersection(
323
                         .getIntersection(
324
                                 new CustomSet<>(Arrays.asList(3, 2, 5))
324
                                 new CustomSet<>(Arrays.asList(3, 2, 5))
325
                         );
325
                         );
334
         final CustomSet<Integer> actual
334
         final CustomSet<Integer> actual
335
                 = new CustomSet<>(Arrays.asList(1, 2, 3, 4))
335
                 = new CustomSet<>(Arrays.asList(1, 2, 3, 4))
336
                         .getIntersection(
336
                         .getIntersection(
337
-                                new CustomSet<>(Collections.EMPTY_LIST)
337
+                                new CustomSet<>(Collections.emptyList())
338
                         );
338
                         );
339
 
339
 
340
         assertNotNull(actual);
340
         assertNotNull(actual);
377
     @Test
377
     @Test
378
     public void differenceOfTwoEmptySetsIsAnEmptySet() {
378
     public void differenceOfTwoEmptySetsIsAnEmptySet() {
379
         final CustomSet<Integer> actual
379
         final CustomSet<Integer> actual
380
-                = new CustomSet<>(Collections.EMPTY_LIST)
380
+                = new CustomSet<Integer>(Collections.emptyList())
381
                         .getDifference(
381
                         .getDifference(
382
-                                new CustomSet<>(Collections.EMPTY_LIST)
382
+                                new CustomSet<>(Collections.emptyList())
383
                         );
383
                         );
384
 
384
 
385
         assertNotNull(actual);
385
         assertNotNull(actual);
390
     @Test
390
     @Test
391
     public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
391
     public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
392
         final CustomSet<Integer> actual
392
         final CustomSet<Integer> actual
393
-                = new CustomSet<>(Collections.EMPTY_LIST)
393
+                = new CustomSet<Integer>(Collections.emptyList())
394
                         .getDifference(
394
                         .getDifference(
395
                                 new CustomSet<>(Arrays.asList(3, 2, 5))
395
                                 new CustomSet<>(Arrays.asList(3, 2, 5))
396
                         );
396
                         );
409
         final CustomSet<Integer> actual
409
         final CustomSet<Integer> actual
410
                 = new CustomSet<>(Arrays.asList(1, 2, 3, 4))
410
                 = new CustomSet<>(Arrays.asList(1, 2, 3, 4))
411
                         .getDifference(
411
                         .getDifference(
412
-                                new CustomSet<>(Collections.EMPTY_LIST)
412
+                                new CustomSet<>(Collections.emptyList())
413
                         );
413
                         );
414
 
414
 
415
         assertNotNull(actual);
415
         assertNotNull(actual);
439
     @Test
439
     @Test
440
     public void unionOfTwoEmptySetsIsAnEmptySet() {
440
     public void unionOfTwoEmptySetsIsAnEmptySet() {
441
         final CustomSet<Integer> actual
441
         final CustomSet<Integer> actual
442
-                = new CustomSet<>(Collections.EMPTY_LIST)
442
+                = new CustomSet<Integer>(Collections.emptyList())
443
                         .getUnion(
443
                         .getUnion(
444
-                                new CustomSet<>(Collections.EMPTY_LIST)
444
+                                new CustomSet<>(Collections.emptyList())
445
                         );
445
                         );
446
 
446
 
447
         assertNotNull(actual);
447
         assertNotNull(actual);
456
                         Collections.unmodifiableList(Collections.singletonList(2))
456
                         Collections.unmodifiableList(Collections.singletonList(2))
457
                 );
457
                 );
458
         final CustomSet<Integer> actual
458
         final CustomSet<Integer> actual
459
-                = new CustomSet<>(Collections.EMPTY_LIST)
459
+                = new CustomSet<Integer>(Collections.emptyList())
460
                         .getUnion(
460
                         .getUnion(
461
                                 new CustomSet<>(Collections.singletonList(2))
461
                                 new CustomSet<>(Collections.singletonList(2))
462
                         );
462
                         );
476
         final CustomSet<Integer> actual
476
         final CustomSet<Integer> actual
477
                 = new CustomSet<>(Arrays.asList(1, 3))
477
                 = new CustomSet<>(Arrays.asList(1, 3))
478
                         .getUnion(
478
                         .getUnion(
479
-                                new CustomSet<>(Collections.EMPTY_LIST)
479
+                                new CustomSet<>(Collections.emptyList())
480
                         );
480
                         );
481
 
481
 
482
         assertNotNull(actual);
482
         assertNotNull(actual);