Skip to content

Commit c1b49ae

Browse files
committed
Fix compiler warnings.
1 parent c729ef1 commit c1b49ae

File tree

12 files changed

+162
-17
lines changed

12 files changed

+162
-17
lines changed

lodash-plugin/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@
4949
<plugin>
5050
<groupId>org.apache.maven.plugins</groupId>
5151
<artifactId>maven-compiler-plugin</artifactId>
52-
<version>2.3.2</version>
52+
<version>3.3</version>
5353
<configuration>
5454
<source>1.6</source>
5555
<target>1.6</target>
5656
<encoding>UTF-8</encoding>
57+
<compilerArgs>
58+
<arg>-Xlint:unchecked</arg>
59+
<arg>-Xlint:deprecation</arg>
60+
</compilerArgs>
5761
</configuration>
5862
</plugin>
5963
<plugin>

lodash-plugin/src/main/java/com/github/underscore/lodash/$.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,12 @@ public Chain<List<T>> dropRightWhile(final Predicate<T> pred) {
338338
return new Chain<List<T>>($.dropRightWhile(value(), pred));
339339
}
340340

341+
@SuppressWarnings("unchecked")
341342
public Chain<List<Object>> fill(final Object value) {
342343
return new Chain<List<Object>>($.fill((List<Object>) value(), value));
343344
}
344345

346+
@SuppressWarnings("unchecked")
345347
public Chain<List<Object>> fill(final Object value, final Integer start, final Integer end) {
346348
return new Chain<List<Object>>($.fill((List<Object>) value(), value, start, end));
347349
}
@@ -350,10 +352,12 @@ public Chain<List<?>> flattenDeep() {
350352
return new Chain<List<?>>($.flattenDeep((List<?>) value()));
351353
}
352354

355+
@SuppressWarnings("unchecked")
353356
public Chain<List<Object>> pull(final Object ... values) {
354357
return new Chain<List<Object>>($.pull((List<Object>) value(), values));
355358
}
356359

360+
@SuppressWarnings("unchecked")
357361
public Chain<List<Object>> pullAt(final Integer ... indexes) {
358362
return new Chain<List<Object>>($.pullAt((List<Object>) value(), indexes));
359363
}
@@ -386,6 +390,7 @@ public Chain<List<T>> takeRightWhile(final Predicate<T> pred) {
386390
return new Chain<List<T>>($.takeRightWhile(value(), pred));
387391
}
388392

393+
@SuppressWarnings("unchecked")
389394
public Chain<List<T>> xor(final List<T> list) {
390395
return new Chain<List<T>>($.xor(value(), list));
391396
}
@@ -394,6 +399,7 @@ public Chain<List<T>> at(final Integer ... indexes) {
394399
return new Chain<List<T>>($.at(value(), indexes));
395400
}
396401

402+
@SuppressWarnings("unchecked")
397403
public <T extends Number> Chain<T> sum() {
398404
return new Chain<T>($.sum((List<T>) value()));
399405
}
@@ -402,10 +408,12 @@ public <F extends Number> Chain<F> sum(final Function1<T, F> func) {
402408
return new Chain<F>($.sum((List<T>) value(), func));
403409
}
404410

411+
@SuppressWarnings("unchecked")
405412
public Chain<Double> mean() {
406413
return new Chain<Double>($.mean((List<Number>) value()));
407414
}
408415

416+
@SuppressWarnings("unchecked")
409417
public Chain<Double> median() {
410418
return new Chain<Double>($.median((List<Number>) value()));
411419
}
@@ -543,7 +551,7 @@ public static <T> Chain chain(final T ... list) {
543551
return new $.Chain<T>(Arrays.asList(list));
544552
}
545553

546-
public Chain chain() {
554+
public Chain<T> chain() {
547555
return new $.Chain<T>(newArrayList(value()));
548556
}
549557

@@ -617,6 +625,7 @@ public static List<Object> fill(final List<Object> list, Object value) {
617625
return list;
618626
}
619627

628+
@SuppressWarnings("unchecked")
620629
public List<Object> fill(Object value) {
621630
return fill((List<Object>) getIterable(), value);
622631
}
@@ -628,6 +637,7 @@ public static List<Object> fill(final List<Object> list, Object value, Integer s
628637
return list;
629638
}
630639

640+
@SuppressWarnings("unchecked")
631641
public List<Object> fill(Object value, Integer start, Integer end) {
632642
return fill((List<Object>) getIterable(), value, start, end);
633643
}
@@ -651,6 +661,7 @@ public static List<Object> pull(final List<Object> list, Object ... values) {
651661
return list;
652662
}
653663

664+
@SuppressWarnings("unchecked")
654665
public List<Object> pull(Object ... values) {
655666
return pull((List<Object>) getIterable(), values);
656667
}
@@ -670,6 +681,7 @@ public static List<Object> pullAt(final List<Object> list, final Integer ... ind
670681
return result;
671682
}
672683

684+
@SuppressWarnings("unchecked")
673685
public List<Object> pullAt(final Integer ... indexes) {
674686
return pullAt((List<Object>) getIterable(), indexes);
675687
}
@@ -738,6 +750,7 @@ public List<T> takeRightWhile(final Predicate<T> pred) {
738750
return takeRightWhile(getIterable(), pred);
739751
}
740752

753+
@SuppressWarnings("unchecked")
741754
public static <T> List<T> xor(final List<T> ... lists) {
742755
int index = -1;
743756
int length = lists.length;
@@ -749,6 +762,7 @@ public static <T> List<T> xor(final List<T> ... lists) {
749762
return uniq(result);
750763
}
751764

765+
@SuppressWarnings("unchecked")
752766
public List<T> xor(final List<T> list) {
753767
return xor((List<T>) getIterable(), list);
754768
}
@@ -787,14 +801,17 @@ public static <E, F extends Number> F sum(final Iterable<E> iterable, final Fun
787801
return result;
788802
}
789803

804+
@SuppressWarnings("unchecked")
790805
public <T extends Number> T sum() {
791806
return (T) sum((List<T>) getIterable());
792807
}
793808

809+
@SuppressWarnings("unchecked")
794810
public <E, F extends Number> F sum(final Function1<E, F> func) {
795811
return (F) sum((List<E>) getIterable(), func);
796812
}
797813

814+
@SuppressWarnings("unchecked")
798815
public static <T extends Number> T add(final T first, final T second) {
799816
if (first == null) {
800817
return second;
@@ -863,10 +880,12 @@ public static <T extends Number> double mean(final Iterable<T> iterable) {
863880
return result.doubleValue() / count;
864881
}
865882

883+
@SuppressWarnings("unchecked")
866884
public double mean() {
867885
return mean((Iterable<Number>) getIterable());
868886
}
869887

888+
@SuppressWarnings("unchecked")
870889
public static <T extends Number> double median(final Iterable<T> iterable) {
871890
final List<T> result = newArrayList((Collection) iterable);
872891
final int size = size(iterable);
@@ -876,6 +895,7 @@ public static <T extends Number> double median(final Iterable<T> iterable) {
876895
return (result.get(size / 2 - 1).doubleValue() + result.get(size / 2).doubleValue()) / 2;
877896
}
878897

898+
@SuppressWarnings("unchecked")
879899
public double median() {
880900
return median((Iterable<Number>) getIterable());
881901
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class LodashTest {
4646
_.chunk(['a', 'b', 'c', 'd'], 3);
4747
// → [['a', 'b', 'c'], ['d']]
4848
*/
49+
@SuppressWarnings("unchecked")
4950
@Test
5051
public void chunk() {
5152
assertEquals("[[a, b], [c, d]]", $.chunk(asList("a", "b", "c", "d"), 2).toString());
@@ -67,6 +68,7 @@ public void chunk() {
6768
_.drop([1, 2, 3], 0);
6869
// → [1, 2, 3]
6970
*/
71+
@SuppressWarnings("unchecked")
7072
@Test
7173
public void drop() {
7274
assertEquals("[2, 3]", $.drop(asList(1, 2, 3)).toString());
@@ -92,6 +94,7 @@ public void drop() {
9294
_.dropRight([1, 2, 3], 0);
9395
// → [1, 2, 3]
9496
*/
97+
@SuppressWarnings("unchecked")
9598
@Test
9699
public void dropRight() {
97100
assertEquals("[1, 2]", $.dropRight(asList(1, 2, 3)).toString());
@@ -110,6 +113,7 @@ public void dropRight() {
110113
});
111114
// → [3]
112115
*/
116+
@SuppressWarnings("unchecked")
113117
@Test
114118
public void dropWhile() {
115119
assertEquals("[3]", $.dropWhile(asList(1, 2, 3), new Predicate<Integer>() {
@@ -135,6 +139,7 @@ public Boolean apply(Integer n) {
135139
});
136140
// → [1, 2]
137141
*/
142+
@SuppressWarnings("unchecked")
138143
@Test
139144
public void dropRightWhile() {
140145
assertEquals("[1, 2]", $.dropRightWhile(asList(1, 2, 3), new Predicate<Integer>() {
@@ -167,6 +172,7 @@ public Boolean apply(Integer n) {
167172
_.fill([4, 6, 8], '*', 1, 2);
168173
// → [4, '*', 8]
169174
*/
175+
@SuppressWarnings("unchecked")
170176
@Test
171177
public void fill() {
172178
List<Object> array = new ArrayList<Object>(asList(1, 2, 3));
@@ -194,6 +200,7 @@ public void fill() {
194200
_.flattenDeep([1, [2, 3, [4]]]);
195201
// → [1, 2, 3, 4]
196202
*/
203+
@SuppressWarnings("unchecked")
197204
@Test
198205
public void flattenDeep() {
199206
final List<Integer> result = $.flattenDeep(asList(1, asList(2, 3, asList(asList(4)))));
@@ -211,6 +218,7 @@ public void flattenDeep() {
211218
console.log(array);
212219
// → [1, 1]
213220
*/
221+
@SuppressWarnings("unchecked")
214222
@Test
215223
public void pull() {
216224
List<Object> array = new ArrayList<Object>(asList(1, 2, 3, 1, 2, 3));
@@ -234,6 +242,7 @@ public void pull() {
234242
console.log(evens);
235243
// → [10, 20]
236244
*/
245+
@SuppressWarnings("unchecked")
237246
@Test
238247
public void pullAt() {
239248
List<Object> array = new ArrayList<Object>(asList(5, 10, 15, 20));
@@ -262,6 +271,7 @@ public void pullAt() {
262271
console.log(evens);
263272
// → [2, 4]
264273
*/
274+
@SuppressWarnings("unchecked")
265275
@Test
266276
public void remove() {
267277
List<Integer> array = new ArrayList<Integer>(asList(1, 2, 3, 4));
@@ -303,6 +313,7 @@ public Boolean apply(final Integer n) {
303313
_.take([1, 2, 3], 0);
304314
// → []
305315
*/
316+
@SuppressWarnings("unchecked")
306317
@Test
307318
public void take() {
308319
assertEquals("[1]", $.take(asList(1, 2, 3)).toString());
@@ -328,6 +339,7 @@ public void take() {
328339
_.takeRight([1, 2, 3], 0);
329340
// → []
330341
*/
342+
@SuppressWarnings("unchecked")
331343
@Test
332344
public void takeRight() {
333345
assertEquals("[3]", $.takeRight(asList(1, 2, 3)).toString());
@@ -346,6 +358,7 @@ public void takeRight() {
346358
});
347359
// → [1, 2]
348360
*/
361+
@SuppressWarnings("unchecked")
349362
@Test
350363
public void takeWhile() {
351364
assertEquals("[1, 2]", $.takeWhile(asList(1, 2, 3), new Predicate<Integer>() {
@@ -371,6 +384,7 @@ public Boolean apply(Integer n) {
371384
});
372385
// → [2, 3]
373386
*/
387+
@SuppressWarnings("unchecked")
374388
@Test
375389
public void takeRightWhile() {
376390
assertEquals("[2, 3]", $.takeRightWhile(asList(1, 2, 3), new Predicate<Integer>() {
@@ -394,6 +408,7 @@ public Boolean apply(Integer n) {
394408
_.xor([1, 2], [4, 2]);
395409
// → [1, 4]
396410
*/
411+
@SuppressWarnings("unchecked")
397412
@Test
398413
public void xor() {
399414
assertEquals("[1, 4]", $.xor(asList(1, 2), asList(4, 2)).toString());
@@ -406,13 +421,15 @@ public void xor() {
406421
_.at(['a', 'b', 'c'], 0, 2);
407422
// → ['a', 'c']
408423
*/
424+
@SuppressWarnings("unchecked")
409425
@Test
410426
public void at() {
411427
assertEquals("[a, c]", $.at(asList("a", "b", "c"), 0, 2).toString());
412428
assertEquals("[a, c]", new $(asList("a", "b", "c")).at(0, 2).toString());
413429
assertEquals("[a, c]", $.chain(asList("a", "b", "c")).at(0, 2).value().toString());
414430
}
415431

432+
@SuppressWarnings("unchecked")
416433
@Test
417434
public void main() {
418435
$.main(new String[] {});
@@ -425,6 +442,7 @@ public void main() {
425442
$.chain("");
426443
}
427444

445+
@SuppressWarnings("unchecked")
428446
@Test
429447
public void chain() {
430448
$.chain(new String[] {""}).first();

lodash-plugin/src/test/java/com/github/underscore/lodash/MathTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package com.github.underscore.lodash;
2525

2626
import com.github.underscore.Function1;
27+
import com.github.underscore.Predicate;
2728
import java.math.BigDecimal;
2829
import java.math.BigInteger;
2930
import java.util.*;
@@ -48,6 +49,7 @@ public class MathTest {
4849
_.sum([-1, -2, -3]);
4950
=> -6
5051
*/
52+
@SuppressWarnings("unchecked")
5153
@Test
5254
public void sum() {
5355
final Byte result = $.sum(asList((byte) 1, (byte) 2, (byte) 3));
@@ -126,6 +128,7 @@ public double doubleValue() {
126128
_.mean([0, 1, 2]);
127129
=> 1
128130
*/
131+
@SuppressWarnings("unchecked")
129132
@Test
130133
public void mean() {
131134
final Double result = $.mean(asList((double) 0, (double) 0.5, (double) 1));
@@ -148,6 +151,7 @@ public void mean() {
148151
_.median([0, 0, 1, 2, 3, 4]);
149152
=> 1.5
150153
*/
154+
@SuppressWarnings("unchecked")
151155
@Test
152156
public void median() {
153157
final Double result = $.median(asList((int) 0, (int) 0, (int) 0, (int) 0, (int) 5));
@@ -165,8 +169,29 @@ public void median() {
165169
assertEquals("1.5", result4.toString());
166170
}
167171

172+
// http://stackoverflow.com/questions/27772432/is-there-a-underscore-js-lib-for-java
173+
@SuppressWarnings("unchecked")
168174
@Test
169-
public void main() throws Exception {
175+
public void sumOfInt() {
176+
/*
177+
String[] words = {"Gallinule", "Escambio", "Aciform", "Entortilation", "Extensibility"};
178+
int sum = Arrays.stream(words)
179+
.filter(w -> w.startsWith("E"))
180+
.mapToInt(w -> w.length())
181+
.sum();
182+
System.out.println("Sum of letters in words starting with E... " + sum);
183+
*/
184+
String[] words = {"Gallinule", "Escambio", "Aciform", "Entortilation", "Extensibility"};
185+
int sum = (Integer) $.chain(asList(words))
186+
.filter(new Predicate<String>() { public Boolean apply(String item) { return item.startsWith("E"); } })
187+
.map(new Function1<String, Integer>() { public Integer apply(String item) { return item.length(); } })
188+
.sum().item();
189+
assertEquals(34, sum);
190+
}
191+
192+
@SuppressWarnings("unchecked")
193+
@Test
194+
public void main() {
170195
$.main(new String[] {});
171196
new $("");
172197
new $(asList()).chain();

0 commit comments

Comments
 (0)