/** @see IfFunctions */ public static <I> IfFunctionBuilderApplyingFirst<I> ifPredicate(Predicate<I> test) { return IfFunctions.ifPredicate(test); }
/** @see IfFunctions */ public static <I> IfFunctionBuilderApplyingFirst<I> ifEquals(I test) { return IfFunctions.ifEquals(test); }
/** @see IfFunctions */ public static <I> IfFunctionBuilderApplyingFirst<I> ifNotEquals(I test) { return IfFunctions.ifNotEquals(test); }
@Test public void testWithoutCast() { Function<Boolean, String> f = IfFunctions.newInstance(Boolean.class, String.class).ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?").build(); checkTF(f, "?"); }
public static <I> IfFunctionBuilderApplyingFirst<I> ifEquals(I test) { return ifPredicate(Predicates.equalTo(test)); } public static <I> IfFunctionBuilderApplyingFirst<I> ifNotEquals(I test) {
@Test public void testNoBuilder() { checkTF(IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?"), "?"); }
@Test public void testFunction() { checkTF(IfFunctions.ifNotEquals((Boolean)null).apply(new Function<Boolean, String>() { @Override public String apply(Boolean input) { return input.toString().toUpperCase().substring(0, 1); } }).defaultValue("?"), "?"); }
public static <I> IfFunctionBuilderApplyingFirst<I> ifNotEquals(I test) { return ifPredicate(Predicates.not(Predicates.equalTo(test))); }
@Test public void testNoDefault() { checkTF(IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").build(), null); }
@Test public void testNotEqual() { checkTF(IfFunctions.ifNotEquals(false).value("T").defaultValue("F").build(), "T"); }
@Test public void testPredicateAndSupplier() { // we cannot use checkTF here as an IntelliJ issues causes the project to fail to launch as IntelliJ does not // recognize the return value of IfFunctions.ifPredicate as Function<Boolean, String> Function function = IfFunctions.ifPredicate(Predicates.equalTo(false)).get(Suppliers.ofInstance("F")) .ifEquals(true).value("T").defaultGet(Suppliers.ofInstance("?")).build(); Assert.assertEquals(function.apply(true), "T"); Assert.assertEquals(function.apply(false), "F"); Assert.assertEquals(function.apply(null), "?"); }
@Test public void testWithCast() { Function<Boolean, String> f = IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?").build(); checkTF(f, "?"); }
private <T> void propagateMasterAttribute(AttributeSensor<T> att) { enrichers().add(Enrichers.builder() .aggregating(att) .publishing(att) .computing(IfFunctions.<Collection<T>>ifPredicate(CollectionFunctionals.notEmpty()) .apply(CollectionFunctionals.firstElement()) .defaultValue(null)) .entityFilter(MySqlClusterUtils.IS_MASTER) .build()); }
@Test public void testCommonUsage() { checkTF(IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?").build(), "?"); }
@Test public void testSupportsReplace() { checkTF(IfFunctions.ifEquals(false).value("false").ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?").build(), "?"); }
@Test public void testIsImmutableAndSupportsReplace() { IfFunctionBuilder<Boolean, String> f = IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?"); IfFunctionBuilder<Boolean, String> f2 = f.ifEquals(false).value("false").defaultValue("X"); IfFunctionBuilder<Boolean, String> f3 = f2.ifEquals(false).value("F"); checkTF(f, "?"); checkTF(f3, "X"); Assert.assertEquals(f2.apply(false), "false"); }