Example usage for org.apache.commons.lang3 BooleanUtils toStringOnOff

List of usage examples for org.apache.commons.lang3 BooleanUtils toStringOnOff

Introduction

In this page you can find the example usage for org.apache.commons.lang3 BooleanUtils toStringOnOff.

Prototype

public static String toStringOnOff(final boolean bool) 

Source Link

Document

Converts a boolean to a String returning 'on' or 'off' .

 BooleanUtils.toStringOnOff(true)   = "on" BooleanUtils.toStringOnOff(false)  = "off" 

Usage

From source file:io.seldon.api.state.ClientAlgorithmStore.java

@Override
public void configUpdated(String client, String configKey, String configValue) {
    SimpleModule module = new SimpleModule("StrategyDeserializerModule");
    module.addDeserializer(Strategy.class, new StrategyDeserializer());
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(module);/*w w  w.  j  a  va2  s.  com*/
    if (configKey.equals(ALG_KEY)) {
        logger.info("Received new algorithm config for " + client + ": " + configValue);
        try {
            List<AlgorithmStrategy> strategies = new ArrayList<>();
            Map<String, AlgorithmStrategy> stratMap = new HashMap<>();
            AlgorithmConfig config = mapper.readValue(configValue, AlgorithmConfig.class);
            for (Algorithm algorithm : config.algorithms) {
                AlgorithmStrategy strategy = toAlgorithmStrategy(algorithm);
                strategies.add(strategy);
            }
            AlgorithmResultsCombiner combiner = applicationContext.getBean(config.combiner,
                    AlgorithmResultsCombiner.class);
            Map<Integer, Double> actionWeightMap = toActionWeightMap(config.actionWeights);
            store.put(client, new SimpleClientStrategy(Collections.unmodifiableList(strategies), combiner,
                    config.diversityLevel, ClientStrategy.DEFAULT_NAME, actionWeightMap));
            storeMap.put(client, Collections.unmodifiableMap(stratMap));
            logger.info("Successfully added new algorithm config for " + client);
        } catch (IOException | BeansException e) {
            logger.error("Couldn't update algorithms for client " + client, e);
        }
    } else if (configKey.equals(TESTING_SWITCH_KEY)) {
        // not json as its so simple
        Boolean onOff = BooleanUtils.toBooleanObject(configValue);
        if (onOff == null) {
            logger.error("Couldn't set testing switch for client " + client + ", input was " + configValue);
        } else {
            logger.info("Testing switch for client " + client + " moving from '"
                    + BooleanUtils.toStringOnOff(testingOnOff.get(client)) + "' to '"
                    + BooleanUtils.toStringOnOff(onOff) + "'");
            testingOnOff.put(client, BooleanUtils.toBooleanObject(configValue));
        }
    } else if (configKey.equals(TEST)) {
        logger.info("Received new testing config for " + client + ":" + configValue);
        try {
            TestConfig config = mapper.readValue(configValue, TestConfig.class);
            List<VariationTestingClientStrategy.Variation> variations = new ArrayList<>();
            for (TestVariation var : config.variations) {
                List<AlgorithmStrategy> strategies = new ArrayList<>();
                for (Algorithm alg : var.config.algorithms) {
                    AlgorithmStrategy strategy = toAlgorithmStrategy(alg);
                    strategies.add(strategy);
                }
                AlgorithmResultsCombiner combiner = applicationContext.getBean(var.config.combiner,
                        AlgorithmResultsCombiner.class);
                Map<Integer, Double> actionWeightMap = toActionWeightMap(var.config.actionWeights);
                variations.add(new VariationTestingClientStrategy.Variation(
                        new SimpleClientStrategy(Collections.unmodifiableList(strategies), combiner,
                                var.config.diversityLevel, var.label, actionWeightMap),
                        new BigDecimal(var.ratio)));

            }
            tests.put(client, VariationTestingClientStrategy.build(variations));
            logger.info("Succesfully added " + variations.size() + " variation test for " + client);
        } catch (NumberFormatException | IOException e) {
            logger.error("Couldn't add test for client " + client, e);
        }
    } else if (configKey.equals(RECTAG)) {
        logger.info("Received new rectag config for " + client + ": " + configValue);
        try {
            RecTagConfig config = mapper.readValue(configValue, RecTagConfig.class);
            if (config.defaultStrategy == null) {
                logger.error("Couldn't read rectag config as there was no default alg");
                return;
            }

            ClientStrategy defStrategy = toStrategy(config.defaultStrategy);
            Map<String, ClientStrategy> recTagStrats = new HashMap<>();
            for (Map.Entry<String, Strategy> entry : config.recTagToStrategy.entrySet()) {
                recTagStrats.put(entry.getKey(), toStrategy(entry.getValue()));
            }
            recTagStrategies.put(client, new RecTagClientStrategy(defStrategy, recTagStrats));
            logger.info("Successfully added rec tag strategy for " + client);
        } catch (NumberFormatException | IOException e) {
            logger.error("Couldn't add rectag strategy for client " + client, e);
        }

    }
}

From source file:yoyo.framework.standard.shared.commons.lang.BooleanUtilsTest.java

@Test
public void test() {
    assertThat(BooleanUtils.and(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.and(new boolean[] { true, false }), is(false));
    assertThat(BooleanUtils.isFalse(false), is(true));
    assertThat(BooleanUtils.isNotFalse(false), is(false));
    assertThat(BooleanUtils.isNotTrue(true), is(false));
    assertThat(BooleanUtils.isTrue(true), is(true));
    assertThat(BooleanUtils.negate(Boolean.FALSE), is(true));
    assertThat(BooleanUtils.or(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.or(new boolean[] { true, false }), is(true));
    assertThat(BooleanUtils.toBoolean(Boolean.TRUE), is(true));
    assertThat(BooleanUtils.toBoolean(0), is(false));
    assertThat(BooleanUtils.toBoolean(1), is(true));
    assertThat(BooleanUtils.toBoolean((String) null), is(false));
    assertThat(BooleanUtils.toBoolean("true"), is(true));
    assertThat(BooleanUtils.toBoolean("hoge"), is(false));
    assertThat(BooleanUtils.toBooleanDefaultIfNull(null, false), is(false));
    assertThat(BooleanUtils.toBooleanObject(0), is(Boolean.FALSE));
    assertThat(BooleanUtils.toBooleanObject(1), is(Boolean.TRUE));
    assertThat(BooleanUtils.toInteger(true), is(1));
    assertThat(BooleanUtils.toInteger(false), is(0));
    assertThat(BooleanUtils.toIntegerObject(true), is(Integer.valueOf(1)));
    assertThat(BooleanUtils.toIntegerObject(false), is(Integer.valueOf(0)));
    assertThat(BooleanUtils.toString(true, "true", "false"), is("true"));
    assertThat(BooleanUtils.toString(false, "true", "false"), is("false"));
    assertThat(BooleanUtils.toStringOnOff(true), is("on"));
    assertThat(BooleanUtils.toStringOnOff(false), is("off"));
    assertThat(BooleanUtils.toStringTrueFalse(true), is("true"));
    assertThat(BooleanUtils.toStringTrueFalse(false), is("false"));
    assertThat(BooleanUtils.toStringYesNo(true), is("yes"));
    assertThat(BooleanUtils.toStringYesNo(false), is("no"));
    assertThat(BooleanUtils.xor(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.xor(new boolean[] { true, false }), is(true));
    assertThat(BooleanUtils.xor(new boolean[] { true, true }), is(false));
}