/** * Converts an array of lambda expressions into an array of their evaluation results. * * @param suppliers an array of lambda expressions or {@code null} * @return an array containing the results of evaluating the lambda expressions (or {@code null} if the suppliers * array was {@code null} */ public static Object[] getAll(final Supplier<?>... suppliers) { if (suppliers == null) { return null; } final Object[] result = new Object[suppliers.length]; for (int i = 0; i < result.length; i++) { result[i] = get(suppliers[i]); } return result; }
protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message, final Supplier<?>... paramSuppliers) { final Message msg = messageFactory.newMessage(message, LambdaUtil.getAll(paramSuppliers)); logMessageSafely(fqcn, level, marker, msg, msg.getThrowable()); }
protected void logMessage(final String fqcn, final Level level, final Marker marker, final Supplier<?> msgSupplier, final Throwable t) { final Message message = LambdaUtil.getMessage(msgSupplier, messageFactory); logMessageSafely(fqcn, level, marker, message, (t == null && message != null) ? message.getThrowable() : t); }
protected void logMessage(final String fqcn, final Level level, final Marker marker, final MessageSupplier msgSupplier, final Throwable t) { final Message message = LambdaUtil.get(msgSupplier); logMessageSafely(fqcn, level, marker, message, (t == null && message != null) ? message.getThrowable() : t); }
@Test(expected = RuntimeException.class) public void testGetAllThrowsExceptionIfAnyOfTheSuppliersThrowsException() { final Supplier<String> function1 = new Supplier<String>() { @Override public String get() { return "abc"; } }; final Supplier<String> function2 = new Supplier<String>() { @Override public String get() { throw new RuntimeException(); } }; final Supplier<?>[] functions = { function1, function2 }; LambdaUtil.getAll(functions); } }
protected void logMessage(final String fqcn, final Level level, final Marker marker, final Supplier<?> msgSupplier, final Throwable t) { final Message message = LambdaUtil.getMessage(msgSupplier, messageFactory); logMessageSafely(fqcn, level, marker, message, (t == null && message != null) ? message.getThrowable() : t); }
@Test(expected = RuntimeException.class) public void testGetSupplierExceptionIfSupplierThrowsException() { LambdaUtil.get(new Supplier<String>() { @Override public String get() { throw new RuntimeException(); } }); }
@Test public void testGetAllReturnsNullArrayIfSupplierArrayNull() { final Object[] actual = LambdaUtil.getAll((Supplier<?>[]) null); assertNull(actual); }
@Test(expected = RuntimeException.class) public void testGetMessageSupplierExceptionIfSupplierThrowsException() { LambdaUtil.get(new MessageSupplier() { @Override public Message get() { throw new RuntimeException(); } }); }
@Test public void testGetAllReturnsNullElementsIfSupplierArrayContainsNulls() { final Supplier<?>[] functions = new Supplier<?>[3]; final Object[] actual = LambdaUtil.getAll(functions); assertEquals(actual.length, functions.length); for (final Object object : actual) { assertNull(object); } }
@Test public void testGetSupplierResultOfSupplier() { final String expected = "result"; final Object actual = LambdaUtil.get(new Supplier<String>() { @Override public String get() { return expected; } }); assertSame(expected, actual); }
@Test public void testGetAllReturnsResultOfSuppliers() { final String expected1 = "result1"; final Supplier<String> function1 = new Supplier<String>() { @Override public String get() { return expected1; } }; final String expected2 = "result2"; final Supplier<String> function2 = new Supplier<String>() { @Override public String get() { return expected2; } }; final Supplier<?>[] functions = { function1, function2 }; final Object[] actual = LambdaUtil.getAll(functions); assertEquals(actual.length, functions.length); assertSame(expected1, actual[0]); assertSame(expected2, actual[1]); }
@Test public void testGetSupplierReturnsNullIfSupplierNull() { final Object actual = LambdaUtil.get((Supplier<?>) null); assertNull(actual); }
protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message, final Supplier<?>... paramSuppliers) { final Message msg = messageFactory.newMessage(message, LambdaUtil.getAll(paramSuppliers)); logMessageSafely(fqcn, level, marker, msg, msg.getThrowable()); }
@Test public void testGetMessageSupplierReturnsNullIfSupplierNull() { final Object actual = LambdaUtil.get((MessageSupplier) null); assertNull(actual); }
@Test public void testGetMessageSupplierResultOfSupplier() { final Message expected = new SimpleMessage("hi"); final Message actual = LambdaUtil.get(new MessageSupplier() { @Override public Message get() { return expected; } }); assertSame(expected, actual); }
/** * Converts an array of lambda expressions into an array of their evaluation results. * * @param suppliers an array of lambda expressions or {@code null} * @return an array containing the results of evaluating the lambda expressions (or {@code null} if the suppliers * array was {@code null} */ public static Object[] getAll(final Supplier<?>... suppliers) { if (suppliers == null) { return null; } final Object[] result = new Object[suppliers.length]; for (int i = 0; i < result.length; i++) { result[i] = get(suppliers[i]); } return result; }
protected void logMessage(final String fqcn, final Level level, final Marker marker, final MessageSupplier msgSupplier, final Throwable t) { final Message message = LambdaUtil.get(msgSupplier); logMessageSafely(fqcn, level, marker, message, (t == null && message != null) ? message.getThrowable() : t); }