/** * Reflection based reduce by. * * @param array array of items to reduce by * @param object function * @param methodName name of method * @param <T> type of function * @return reduction */ private static <T> long reduceByR(final int[] array, T object, String methodName) { try { Method method = Invoker.invokeReducerLongIntReturnLongMethod(object, methodName); long sum = 0; for (int v : array) { sum = (long) method.invoke(object, sum, v); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } }
/** * Reflection based reduce by. * * @param array array of items to reduce by * @param object function * @param <T> type of function * @return reduction */ private static <T> long reduceByR(final int[] array, int length, T object) { try { Method method = Invoker.invokeReducerLongIntReturnLongMethod(object); long sum = 0; for (int index = 0; index < length; index++) { int v = array[index]; sum = (long) method.invoke(object, sum, v); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } }