Skip to content

Commit ffb0506

Browse files
committed
Improve type cast.
1 parent b0bc916 commit ffb0506

File tree

1 file changed

+10
-20
lines changed
  • src/main/java/com/github/underscore

1 file changed

+10
-20
lines changed

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,8 @@ public T first() {
755755
return iterable.iterator().next();
756756
}
757757

758-
@SuppressWarnings("unchecked")
759758
public List<T> first(final int n) {
760-
return ((List) iterable).subList(0, n);
759+
return ((List<T>) iterable).subList(0, n);
761760
}
762761

763762
public static <E> E first(final Iterable<E> iterable, final Predicate<E> pred) {
@@ -792,7 +791,6 @@ public static <E> E head(final Iterable<E> iterable) {
792791
return first(iterable);
793792
}
794793

795-
@SuppressWarnings("unchecked")
796794
public static <E> E head(final E ... array) {
797795
return first(array);
798796
}
@@ -826,17 +824,14 @@ public static <E> E[] initial(final E[] array, final int n) {
826824
return Arrays.copyOf(array, array.length - n);
827825
}
828826

829-
@SuppressWarnings("unchecked")
830827
public List<T> initial() {
831-
return initial((List) iterable, 1);
828+
return initial((List<T>) iterable, 1);
832829
}
833830

834-
@SuppressWarnings("unchecked")
835831
public List<T> initial(final int n) {
836-
return initial((List) iterable, n);
832+
return initial((List<T>) iterable, n);
837833
}
838834

839-
@SuppressWarnings("unchecked")
840835
public static <E> E last(final E ... array) {
841836
return array[array.length - 1];
842837
}
@@ -853,9 +848,8 @@ public T last() {
853848
return last((List<T>) iterable);
854849
}
855850

856-
@SuppressWarnings("unchecked")
857851
public List<T> last(final int n) {
858-
return last((List) iterable, n);
852+
return last((List<T>) iterable, n);
859853
}
860854

861855
public static <E> E last(final List<E> list, final Predicate<E> pred) {
@@ -902,14 +896,12 @@ public static <E> E[] rest(final E[] array, final int n) {
902896
return (E[]) rest(Arrays.asList(array), n).toArray();
903897
}
904898

905-
@SuppressWarnings("unchecked")
906899
public List<T> rest() {
907-
return rest((List) iterable);
900+
return rest((List<T>) iterable);
908901
}
909902

910-
@SuppressWarnings("unchecked")
911903
public List<T> rest(int n) {
912-
return rest((List) iterable, n);
904+
return rest((List<T>) iterable, n);
913905
}
914906

915907
public static <E> List<E> tail(final List<E> list) {
@@ -920,7 +912,6 @@ public static <E> List<E> tail(final List<E> list, final int n) {
920912
return rest(list, n);
921913
}
922914

923-
@SuppressWarnings("unchecked")
924915
public static <E> E[] tail(final E ... array) {
925916
return rest(array);
926917
}
@@ -983,14 +974,13 @@ public static <E> E[] compact(final E[] array, final E falsyValue) {
983974
return (E[]) compact(Arrays.asList(array), falsyValue).toArray();
984975
}
985976

986-
@SuppressWarnings("unchecked")
987977
public List<T> compact() {
988-
return compact((List) iterable);
978+
return compact((List<T>) iterable);
989979
}
990980

991981
@SuppressWarnings("unchecked")
992982
public List<T> compact(final T falsyValue) {
993-
return compact((List) iterable, falsyValue);
983+
return compact((List<T>) iterable, falsyValue);
994984
}
995985

996986
public static <E> List<E> flatten(final List<?> list) {
@@ -1017,11 +1007,11 @@ private static <E> void flatten(final List<?> fromTreeList, final List<E> toFlat
10171007
}
10181008

10191009
public List<T> flatten() {
1020-
return flatten((List) iterable);
1010+
return flatten((List<T>) iterable);
10211011
}
10221012

10231013
public List<T> flatten(final boolean shallow) {
1024-
return flatten((List) iterable, shallow);
1014+
return flatten((List<T>) iterable, shallow);
10251015
}
10261016

10271017
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)