Skip to content

Commit 2806231

Browse files
committed
Sync with underscore-java.
1 parent 8816396 commit 2806231

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
lines changed

checkstyle.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<module name="FileLength">
2121
<property name="fileExtensions" value="java"/>
2222
<property name="severity" value="warning"/>
23-
<property name="max" value="2800"/>
23+
<property name="max" value="3900"/>
2424
</module>
2525
<module name="RegexpSingleline">
2626
<property name="format" value="\s+$"/>
@@ -85,11 +85,11 @@
8585
<module name="UnusedImports"/>
8686
<module name="RedundantImport"/>
8787
<module name="LineLength">
88-
<property name="severity" value="warning"/>
88+
<property name="severity" value="error"/>
8989
<property name="max" value="120"/>
9090
</module>
9191
<module name="MethodLength">
92-
<property name="severity" value="warning"/>
92+
<property name="severity" value="error"/>
9393
<property name="max" value="120"/>
9494
</module>
9595
<module name="AnonInnerLength">

src/main/java/com/github/underscore/U.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,8 @@ public static <T> List<List<T>> chunkFill(final Iterable<T> iterable, final int
18811881
return chunkFill(iterable, size, size, fillValue);
18821882
}
18831883

1884-
public static <T> List<List<T>> chunkFill(final Iterable<T> iterable, final int size, final int step, final T fillValue) {
1884+
public static <T> List<List<T>> chunkFill(final Iterable<T> iterable, final int size,
1885+
final int step, final T fillValue) {
18851886
if (step <= 0 || size < 0) {
18861887
return newArrayList();
18871888
}

src/test/java/com/github/underscore/ArraysTest.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright 2015-2018 Valentyn Kolesnikov
4+
* Copyright 2015-2019 Valentyn Kolesnikov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -301,7 +301,8 @@ public void chunk() {
301301
assertEquals("[]", new U<Integer>(U.range(7)).chunk(3, 0).toString());
302302
assertEquals("[[a, b], [c, d]]", U.chain(asList("a", "b", "c", "d")).chunk(2).value().toString());
303303
assertEquals("[]", U.chain(asList("a", "b", "c", "d")).chunk(0).value().toString());
304-
assertEquals("[[a, b], [b, c], [c, d], [d]]", U.chain(asList("a", "b", "c", "d")).chunk(2, 1).value().toString());
304+
assertEquals("[[a, b], [b, c], [c, d], [d]]", U.chain(asList("a", "b", "c", "d"))
305+
.chunk(2, 1).value().toString());
305306
assertEquals("[]", U.chain(asList("a", "b", "c", "d")).chunk(4, 0).value().toString());
306307
}
307308

@@ -316,13 +317,16 @@ public void chunkFill() {
316317
assertEquals("[]", U.chunkFill(U.range(7), -2, 3, 500).toString());
317318
assertEquals("[]", U.chunkFill(U.range(7), 2, 0, 500).toString());
318319
assertEquals("[]", U.chunkFill(U.range(7), 2, -2, 500).toString());
319-
assertEquals("[[a, b, c], [d, fill, fill]]", new U<String>(asList("a", "b", "c", "d")).chunkFill(3, "fill").toString());
320+
assertEquals("[[a, b, c], [d, fill, fill]]", new U<String>(asList("a", "b", "c", "d"))
321+
.chunkFill(3, "fill").toString());
320322
assertEquals("[]", new U<String>(asList("a", "b", "c", "d")).chunkFill(0, "fill").toString());
321-
assertEquals("[[0, 1, 2], [2, 3, 4], [4, 5, 500]]", new U<Integer>(U.range(6)).chunkFill(3, 2, 500).toString());
323+
assertEquals("[[0, 1, 2], [2, 3, 4], [4, 5, 500]]", new U<Integer>(U.range(6))
324+
.chunkFill(3, 2, 500).toString());
322325
assertEquals("[]", new U<Integer>(U.range(7)).chunkFill(3, 0, 500).toString());
323326
assertEquals("[[a, b], [c, d]]", U.chain(asList("a", "b", "c", "d")).chunkFill(2, "fill").value().toString());
324327
assertEquals("[]", U.chain(asList("a", "b", "c", "d")).chunkFill(0, "fill").value().toString());
325-
assertEquals("[[a, b], [b, c], [c, d], [d, fill]]", U.chain(asList("a", "b", "c", "d")).chunkFill(2, 1, "fill").value().toString());
328+
assertEquals("[[a, b], [b, c], [c, d], [d, fill]]", U.chain(asList("a", "b", "c", "d"))
329+
.chunkFill(2, 1, "fill").value().toString());
326330
assertEquals("[]", U.chain(asList("a", "b", "c", "d")).chunkFill(4, 0, "fill").value().toString());
327331
}
328332

@@ -384,13 +388,15 @@ public void interpose() {
384388
assertEquals("[]", U.interpose(U.newArrayList(), null).toString());
385389
assertEquals("[0, 1, 2, 3]", U.interpose(U.newArrayList(U.range(4)), null).toString());
386390
assertEquals("[0]", U.interpose(U.range(1), 500).toString());
387-
assertEquals("[a, interpose, b, interpose, c]", new U<String>(asList("a", "b", "c")).interpose("interpose").toString());
391+
assertEquals("[a, interpose, b, interpose, c]", new U<String>(asList("a", "b", "c"))
392+
.interpose("interpose").toString());
388393
assertEquals("[a]", new U<String>(asList("a")).interpose("interpose").toString());
389394
assertEquals("[a, b]", new U<String>(asList("a, b")).interpose(null).toString());
390395
assertEquals("[a]", U.chain(asList("a")).interpose("interpose").toString());
391396
assertEquals("[]", U.chain(U.newArrayList()).interpose("interpose").toString());
392397
assertEquals("[a, b, c]", U.chain(asList("a", "b", "c")).interpose(null).toString());
393-
assertEquals("[?, interpose, !, interpose, -]", U.chain(asList("?", "!", "-")).interpose("interpose").toString());
398+
assertEquals("[?, interpose, !, interpose, -]", U.chain(asList("?", "!", "-"))
399+
.interpose("interpose").toString());
394400
}
395401

396402
/*
@@ -418,12 +424,14 @@ public void interposeByList() {
418424
assertEquals("[a, b, c]", new U<String>(asList("a", "b", "c")).interposeByList(null).toString());
419425
assertEquals("[a]", new U<String>(asList("a")).interposeByList(asList("zzz")).toString());
420426
assertEquals("[a, b, c]", new U<String>(asList("a", "b", "c")).interposeByList(list1).toString());
421-
assertEquals("[a, aaa, b, bbb, c]", new U<String>(asList("a", "b", "c")).interposeByList(asList("aaa", "bbb", "ccc")).toString());
427+
assertEquals("[a, aaa, b, bbb, c]", new U<String>(asList("a", "b", "c"))
428+
.interposeByList(asList("aaa", "bbb", "ccc")).toString());
422429
assertEquals("[a]", U.chain(asList("a")).interposeByList(asList("aaa", "bbb", "ccc")).toString());
423430
assertEquals("[aaa, bbb, ccc]", U.chain(asList("aaa", "bbb", "ccc")).interposeByList(null).toString());
424431
list2.clear();
425432
assertEquals("[]", U.chain(list2).interposeByList(U.range(6)).toString());
426-
assertEquals("[?, aaa, !, bbb, -]", U.chain(asList("?", "!", "-")).interposeByList(asList("aaa", "bbb", "ccc")).toString());
433+
assertEquals("[?, aaa, !, bbb, -]", U.chain(asList("?", "!", "-"))
434+
.interposeByList(asList("aaa", "bbb", "ccc")).toString());
427435
}
428436

429437
/*
@@ -492,9 +500,8 @@ public boolean test(String arg) {
492500
}, "b").toString());
493501
assertEquals("[a, aa, cc, ccc]", new U<String>(asList("a", "aa", "cc", "ccc")).replace(
494502
null, "b").toString());
495-
Set<Integer> set = new HashSet<Integer>() { {
496-
addAll(U.range(7));
497-
} };
503+
Set<Integer> set = new HashSet<Integer>();
504+
set.addAll(U.range(7));
498505
assertEquals("[0, 1, 2, 100, 100, 100, 100]", U.chain(set).replace(
499506
new Predicate<Integer>() {
500507
@Override
@@ -530,9 +537,13 @@ public boolean test(int i, String arg) {
530537
}, "f").toString());
531538
assertEquals("[a, aa, cc, ccc]", new U<String>(asList("a", "aa", "cc", "ccc")).replaceIndexed(
532539
null, "b").toString());
533-
List<Integer> list = new ArrayList<Integer>() { {
534-
add(100); add(22); add(88); add(6530); add(-25); add(-1000);
535-
} };
540+
List<Integer> list = new ArrayList<Integer>();
541+
list.add(100);
542+
list.add(22);
543+
list.add(88);
544+
list.add(6530);
545+
list.add(-25);
546+
list.add(-1000);
536547
assertEquals("[100, 0, 88, 6530, 0, -1000]", U.chain(list).replaceIndexed(
537548
new PredicateIndexed<Integer>() {
538549
@Override

src/test/java/com/github/underscore/ObjectsTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright 2015-2018 Valentyn Kolesnikov
4+
* Copyright 2015-2019 Valentyn Kolesnikov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -91,14 +91,8 @@ public void invert() {
9191
*/
9292
@Test
9393
public void functions() {
94-
class Test {
95-
public void test() {
96-
}
97-
public void test$() {
98-
}
99-
}
100-
List<String> result = U.functions(Test.class);
101-
assertEquals(1, U.first(result, 1).size());
94+
List<String> result = U.functions(U.class);
95+
assertEquals(5, U.first(result, 5).size());
10296
}
10397

10498
/*

src/test/java/com/github/underscore/UnderscoreTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright 2015-2018 Valentyn Kolesnikov
4+
* Copyright 2015-2019 Valentyn Kolesnikov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -215,7 +215,8 @@ public void splitAt() {
215215
assertEquals("[[0, 1], [2, 3, 4]]", new U<Integer>(U.range(5)).splitAt(2).toString());
216216
assertEquals("[[0, 1], [2, 3, 4]]", U.chain(U.range(5)).splitAt(2).value().toString());
217217
assertEquals("[[a, b], [c, d, e]]", U.splitAt(asList('a', 'b', 'c', 'd', 'e'), 2).toString());
218-
assertEquals("[[ant, bird], [camel, dog, elephant]]", U.splitAt(asList("ant", "bird", "camel", "dog", "elephant"), 2).toString());
218+
assertEquals("[[ant, bird], [camel, dog, elephant]]", U.splitAt(
219+
asList("ant", "bird", "camel", "dog", "elephant"), 2).toString());
219220
assertEquals("[[0.1, 0.2], [0.3, 0.4, 0.5]]", U.splitAt(asList(0.1, 0.2, 0.3, 0.4, 0.5), 2).toString());
220221
final Integer[] array = {0, 1, 2, 3, 4};
221222
assertEquals("[[0, 1], [2, 3, 4]]", U.splitAt(array, 2).toString());
@@ -238,7 +239,8 @@ public void takeSkipping() {
238239
assertEquals("[0, 2, 4]", new U<Integer>(U.range(5)).takeSkipping(2).toString());
239240
assertEquals("[0, 2, 4]", U.chain(U.range(5)).takeSkipping(2).value().toString());
240241
assertEquals("[a, c, e]", U.takeSkipping(asList('a', 'b', 'c', 'd', 'e'), 2).toString());
241-
assertEquals("[ant, camel, elephant]", U.takeSkipping(asList("ant", "bird", "camel", "dog", "elephant"), 2).toString());
242+
assertEquals("[ant, camel, elephant]", U.takeSkipping(
243+
asList("ant", "bird", "camel", "dog", "elephant"), 2).toString());
242244
assertEquals("[0.1, 0.3, 0.5]", U.takeSkipping(asList(0.1, 0.2, 0.3, 0.4, 0.5), 2).toString());
243245
final Integer[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
244246
assertEquals("[0, 3, 6, 9]", U.takeSkipping(array, 3).toString());

src/test/java/com/github/underscore/lodash/LodashTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright 2016-2018 Valentyn Kolesnikov
4+
* Copyright 2015-2019 Valentyn Kolesnikov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -755,6 +755,11 @@ public void accept(String str) {
755755
U.chain(new Integer[] {0}).distinct();
756756
U.chain(new Integer[] {0}).distinctBy(new Function<Integer, Integer>() {
757757
public Integer apply(Integer value) { return value; } });
758+
}
759+
760+
@SuppressWarnings("unchecked")
761+
@Test
762+
public void chain2() {
758763
U.chain(new String[] {""}).union();
759764
U.chain(new String[] {""}).intersection();
760765
U.chain(new String[] {""}).difference();

0 commit comments

Comments
 (0)