public IfFunctionBuilder<I,O> apply(Function<? super I,? extends O> function) { IfFunctionBuilder<I, O> result = new IfFunctionBuilder<I,O>(input); result.tests.put(test, function); return result; } }
@Test public void testIfPredicateAndSupplier() { IfFunctionsTest.checkTF(Functionals.ifPredicate(Predicates.equalTo(false)).get(Suppliers.ofInstance("F")) .ifEquals(true).value("T").defaultGet(Suppliers.ofInstance("?")).build(), "?"); }
public IfFunctionBuilderApplying<I,O> ifEquals(I test) { return ifPredicate(Predicates.equalTo(test)); } public IfFunctionBuilderApplying<I,O> ifNotEquals(I test) {
@Test public void testIfNotEqual() { IfFunctionsTest.checkTF(Functionals.ifNotEquals(false).value("T").defaultValue("F").build(), "T"); }
public static <I,O> IfFunctionBuilder<I,O> newInstance(Class<I> testType, Class<O> returnType) { return new IfFunctionBuilder<I,O>(); }
@Test public void testIf() { IfFunctionsTest.checkTF(Functionals.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?").build(), "?"); }
@Test public void testIfNoBuilder() { IfFunctionsTest.checkTF(Functionals.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?"), "?"); }
@Test public void testNoBuilder() { checkTF(IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?"), "?"); }
public IfFunctionBuilderApplying<I,O> ifNotEquals(I test) { return ifPredicate(Predicates.not(Predicates.equalTo(test))); }
public IfFunctionBuilder<I,O> defaultValue(O defaultValue) { return defaultApply(new Functionals.ConstantFunction<I,O>(defaultValue, defaultValue)); } @SuppressWarnings("unchecked")
@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, "?"); }
@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"); }
@Test public void testNotEqual() { checkTF(IfFunctions.ifNotEquals(false).value("T").defaultValue("F").build(), "T"); }
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 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("?"), "?"); }
@SuppressWarnings("unchecked") public IfFunctionBuilder<I,O> defaultGet(Supplier<? extends O> defaultSupplier) { return defaultApply(Functions.forSupplier(defaultSupplier)); } public IfFunctionBuilder<I,O> defaultApply(Function<? super I,? extends O> defaultFunction) {
@Test public void testCommonUsage() { checkTF(IfFunctions.ifEquals(false).value("F").ifEquals(true).value("T").defaultValue("?").build(), "?"); }
public static final EnricherSpec<?> newEnricherForServiceUpIfNotUpIndicatorsEmpty() { // The function means: if the serviceNotUpIndicators is not null, then serviceNotUpIndicators.size()==0; // otherwise return the default value. return Enrichers.builder() .transforming(SERVICE_NOT_UP_INDICATORS).<Object>publishing(Attributes.SERVICE_UP) .suppressDuplicates(true) .computing( Functionals.<Map<String,?>> ifNotEquals(null).<Object>apply(Functions.forPredicate(CollectionFunctionals.<String>mapSizeEquals(0))) .defaultValue(Entities.UNCHANGED) ) .uniqueTag(DEFAULT_ENRICHER_UNIQUE_TAG) .build(); }
public IfFunctionBuilder<I,O> defaultApply(Function<? super I,? extends O> defaultFunction) { IfFunctionBuilder<I, O> result = new IfFunctionBuilder<I,O>(this); result.defaultFunction = defaultFunction; return result; } }