|
35 | 35 | import java.util.Set; |
36 | 36 |
|
37 | 37 | import static java.util.Arrays.asList; |
| 38 | +import static java.util.Collections.singletonList; |
38 | 39 | import static org.junit.Assert.assertEquals; |
39 | 40 | import static org.junit.Assert.assertNull; |
40 | 41 |
|
@@ -70,7 +71,7 @@ public void first() { |
70 | 71 | assertEquals("[]", U.first(U.range(3), -2).toString()); |
71 | 72 | assertEquals("[]", new U<>(U.range(3)).first(0).toString()); |
72 | 73 | assertEquals("[]", new U<>(U.range(3)).first(-1).toString()); |
73 | | - assertEquals("[]", U.chain(asList("a")).first(-100).value().toString()); |
| 74 | + assertEquals("[]", U.chain(singletonList("a")).first(-100).value().toString()); |
74 | 75 | //array |
75 | 76 | assertEquals(5, U.first(new Integer[] {5, 4, 3, 2, 1}).intValue()); |
76 | 77 | //static, chain, object with predicate |
@@ -118,7 +119,7 @@ public void firstOrNull() { |
118 | 119 | @Test(expected = NoSuchElementException.class) |
119 | 120 | @SuppressWarnings("unchecked") |
120 | 121 | public void firstEmpty() { |
121 | | - U.first(asList()); |
| 122 | + U.first(Collections.emptyList()); |
122 | 123 | } |
123 | 124 |
|
124 | 125 | /* |
@@ -150,11 +151,11 @@ public void head() { |
150 | 151 | @Test |
151 | 152 | public void singleOrNull() { |
152 | 153 | U<Integer> uWithMoreElement = new U<>(asList(1, 2, 3)); |
153 | | - U<Integer> uWithOneElement = new U<>(asList(1)); |
| 154 | + U<Integer> uWithOneElement = new U<>(singletonList(1)); |
154 | 155 |
|
155 | 156 | final Integer result1 = U.singleOrNull(asList(1, 2, 3)); |
156 | 157 | assertNull(result1); |
157 | | - final int result2 = U.singleOrNull(asList(1)); |
| 158 | + final int result2 = U.singleOrNull(singletonList(1)); |
158 | 159 | assertEquals(1, result2); |
159 | 160 | final Integer result3 = U.singleOrNull(new ArrayList<>()); |
160 | 161 | assertNull(result3); |
@@ -312,9 +313,9 @@ public void interpose() { |
312 | 313 | assertEquals("[0]", U.interpose(U.range(1), 500).toString()); |
313 | 314 | assertEquals("[a, interpose, b, interpose, c]", new U<>(asList("a", "b", "c")) |
314 | 315 | .interpose("interpose").toString()); |
315 | | - assertEquals("[a]", new U<>(asList("a")).interpose("interpose").toString()); |
316 | | - assertEquals("[a, b]", new U<>(asList("a, b")).interpose(null).toString()); |
317 | | - assertEquals("[a]", U.chain(asList("a")).interpose("interpose").toString()); |
| 316 | + assertEquals("[a]", new U<>(singletonList("a")).interpose("interpose").toString()); |
| 317 | + assertEquals("[a, b]", new U<>(singletonList("a, b")).interpose(null).toString()); |
| 318 | + assertEquals("[a]", U.chain(singletonList("a")).interpose("interpose").toString()); |
318 | 319 | assertEquals("[]", U.chain(U.newArrayList()).interpose("interpose").toString()); |
319 | 320 | assertEquals("[a, b, c]", U.chain(asList("a", "b", "c")).interpose(null).toString()); |
320 | 321 | assertEquals("[?, interpose, !, interpose, -]", U.chain(asList("?", "!", "-")) |
@@ -342,13 +343,13 @@ public void interposeByList() { |
342 | 343 | list2.add(1); |
343 | 344 | assertEquals("[1]", U.interposeByList(list2, U.range(100, 300, 50)).toString()); |
344 | 345 | assertEquals("[0, 100, 1, 2, 3]", U.interposeByList(U.range(4), U.newIntegerList(100)).toString()); |
345 | | - assertEquals("[a, zzz, b, c]", new U<>(asList("a", "b", "c")).interposeByList(asList("zzz")).toString()); |
| 346 | + assertEquals("[a, zzz, b, c]", new U<>(asList("a", "b", "c")).interposeByList(singletonList("zzz")).toString()); |
346 | 347 | assertEquals("[a, b, c]", new U<>(asList("a", "b", "c")).interposeByList(null).toString()); |
347 | | - assertEquals("[a]", new U<>(asList("a")).interposeByList(asList("zzz")).toString()); |
| 348 | + assertEquals("[a]", new U<>(singletonList("a")).interposeByList(singletonList("zzz")).toString()); |
348 | 349 | assertEquals("[a, b, c]", new U<>(asList("a", "b", "c")).interposeByList(list1).toString()); |
349 | 350 | assertEquals("[a, aaa, b, bbb, c]", new U<>(asList("a", "b", "c")) |
350 | 351 | .interposeByList(asList("aaa", "bbb", "ccc")).toString()); |
351 | | - assertEquals("[a]", U.chain(asList("a")).interposeByList(asList("aaa", "bbb", "ccc")).toString()); |
| 352 | + assertEquals("[a]", U.chain(singletonList("a")).interposeByList(asList("aaa", "bbb", "ccc")).toString()); |
352 | 353 | assertEquals("[aaa, bbb, ccc]", U.chain(asList("aaa", "bbb", "ccc")).interposeByList(null).toString()); |
353 | 354 | list2.clear(); |
354 | 355 | assertEquals("[]", U.chain(list2).interposeByList(U.range(6)).toString()); |
@@ -556,17 +557,21 @@ public void compact() { |
556 | 557 | @Test |
557 | 558 | @SuppressWarnings("unchecked") |
558 | 559 | public void flatten() { |
559 | | - final List<Integer> result = U.flatten(asList(1, asList(2, asList(3, asList(asList(4)))))); |
| 560 | + final List<Integer> result = U.flatten(asList(1, asList(2, asList(3, singletonList(singletonList(4)))))); |
560 | 561 | assertEquals("[1, 2, 3, 4]", result.toString()); |
561 | | - final List<Integer> result2 = U.flatten(asList(1, asList(2, asList(3, asList(asList(4))))), true); |
| 562 | + final List<Integer> result2 = U.flatten(asList(1, asList(2, asList(3, singletonList(singletonList(4))))), true); |
562 | 563 | assertEquals("[1, 2, [3, [[4]]]]", result2.toString()); |
563 | | - final List<Integer> result3 = U.flatten(asList(1, asList(2, asList(3, asList(asList(4))))), false); |
| 564 | + final List<Integer> result3 = U.flatten(asList(1, asList(2, asList(3, |
| 565 | + singletonList(singletonList(4))))), false); |
564 | 566 | assertEquals("[1, 2, 3, 4]", result3.toString()); |
565 | | - final List<Integer> resultObj = new U(asList(1, asList(2, asList(3, asList(asList(4)))))).flatten(); |
| 567 | + final List<Integer> resultObj = new U(asList(1, asList(2, asList(3, |
| 568 | + singletonList(singletonList(4)))))).flatten(); |
566 | 569 | assertEquals("[1, 2, 3, 4]", resultObj.toString()); |
567 | | - final List<Integer> resultObj2 = new U(asList(1, asList(2, asList(3, asList(asList(4)))))).flatten(true); |
| 570 | + final List<Integer> resultObj2 = new U(asList(1, asList(2, asList(3, |
| 571 | + singletonList(singletonList(4)))))).flatten(true); |
568 | 572 | assertEquals("[1, 2, [3, [[4]]]]", resultObj2.toString()); |
569 | | - final List<Integer> resultObj3 = new U(asList(1, asList(2, asList(3, asList(asList(4)))))).flatten(false); |
| 573 | + final List<Integer> resultObj3 = new U(asList(1, asList(2, asList(3, |
| 574 | + singletonList(singletonList(4)))))).flatten(false); |
570 | 575 | assertEquals("[1, 2, 3, 4]", resultObj3.toString()); |
571 | 576 | } |
572 | 577 |
|
@@ -639,7 +644,7 @@ public int compareTo(Person person) { |
639 | 644 | return 0; |
640 | 645 | } |
641 | 646 | } |
642 | | - U.<Person>sortedIndex(asList(new Person()), new Person(), "age"); |
| 647 | + U.<Person>sortedIndex(singletonList(new Person()), new Person(), "age"); |
643 | 648 | } |
644 | 649 |
|
645 | 650 | /* |
|
0 commit comments