|
60 | 60 | * |
61 | 61 | * @author Valentyn Kolesnikov |
62 | 62 | */ |
| 63 | +@SuppressWarnings("java:S3740") |
63 | 64 | public class Underscore<T> { |
64 | 65 | private static final Map<String, Function<String, String>> FUNCTIONS = newLinkedHashMap(); |
65 | 66 | private static final Map<String, String> TEMPLATE_SETTINGS = new HashMap<>(); |
@@ -139,6 +140,7 @@ public boolean test(final E elem) { |
139 | 140 | return false; |
140 | 141 | } |
141 | 142 | } catch (Exception ignored) { |
| 143 | + // ignored |
142 | 144 | } |
143 | 145 | } |
144 | 146 | } |
@@ -266,7 +268,9 @@ public T next() { |
266 | 268 | } |
267 | 269 |
|
268 | 270 | @Override |
269 | | - public void remove() {} |
| 271 | + public void remove() { |
| 272 | + // ignored |
| 273 | + } |
270 | 274 | }; |
271 | 275 | } |
272 | 276 | } |
@@ -774,18 +778,23 @@ public static <E> List<E> invoke( |
774 | 778 | .getClass() |
775 | 779 | .getMethod(methodName, argTypes.toArray(new Class[0])); |
776 | 780 | for (E arg : iterable) { |
777 | | - try { |
778 | | - result.add((E) method.invoke(arg, args.toArray(new Object[0]))); |
779 | | - } catch (Exception e) { |
780 | | - throw new IllegalArgumentException(e); |
781 | | - } |
| 781 | + doInvoke(args, result, method, arg); |
782 | 782 | } |
783 | 783 | } catch (NoSuchMethodException e) { |
784 | 784 | throw new IllegalArgumentException(e); |
785 | 785 | } |
786 | 786 | return result; |
787 | 787 | } |
788 | 788 |
|
| 789 | + @SuppressWarnings("unchecked") |
| 790 | + private static <E> void doInvoke(List<Object> args, List<E> result, Method method, E arg) { |
| 791 | + try { |
| 792 | + result.add((E) method.invoke(arg, args.toArray(new Object[0]))); |
| 793 | + } catch (Exception e) { |
| 794 | + throw new IllegalArgumentException(e); |
| 795 | + } |
| 796 | + } |
| 797 | + |
789 | 798 | public List<T> invoke(final String methodName, final List<Object> args) { |
790 | 799 | return invoke(iterable, methodName, args); |
791 | 800 | } |
@@ -1165,7 +1174,6 @@ public static <E> int size(final E... array) { |
1165 | 1174 | return array.length; |
1166 | 1175 | } |
1167 | 1176 |
|
1168 | | - @SuppressWarnings("unchecked") |
1169 | 1177 | public static <E> List<List<E>> partition(final Iterable<E> iterable, final Predicate<E> pred) { |
1170 | 1178 | final List<E> retVal1 = newArrayList(); |
1171 | 1179 | final List<E> retVal2 = newArrayList(); |
@@ -2880,7 +2888,7 @@ public Chain<T> compact(final T falsyValue) { |
2880 | 2888 |
|
2881 | 2889 | @SuppressWarnings("unchecked") |
2882 | 2890 | public Chain flatten() { |
2883 | | - return new Chain(Underscore.flatten(list)); |
| 2891 | + return new Chain<>(Underscore.flatten(list)); |
2884 | 2892 | } |
2885 | 2893 |
|
2886 | 2894 | public <F> Chain<F> map(final Function<? super T, F> func) { |
@@ -3246,7 +3254,7 @@ public String toString() { |
3246 | 3254 | /* |
3247 | 3255 | * Documented, #mixin |
3248 | 3256 | */ |
3249 | | - public static void mixin(final String funcName, final Function<String, String> func) { |
| 3257 | + public static void mixin(final String funcName, final UnaryOperator<String> func) { |
3250 | 3258 | FUNCTIONS.put(funcName, func); |
3251 | 3259 | } |
3252 | 3260 |
|
|
0 commit comments