Example usage for org.apache.commons.lang.math RandomUtils nextBoolean

List of usage examples for org.apache.commons.lang.math RandomUtils nextBoolean

Introduction

In this page you can find the example usage for org.apache.commons.lang.math RandomUtils nextBoolean.

Prototype

public static boolean nextBoolean() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed boolean value from the Math.random() sequence.

Usage

From source file:net.nelz.simplesm.config.MemcachedConnectionBeanTest.java

@Test
public void testInAndOut() {
    final boolean consistent = RandomUtils.nextBoolean();
    final String addresses = RandomStringUtils.randomAlphanumeric(12);

    final MemcachedConnectionBean bean = new MemcachedConnectionBean();
    bean.setConsistentHashing(consistent);
    bean.setNodeList(addresses);/*from ww  w  .j a v a2s.  c o  m*/

    assertEquals(consistent, bean.isConsistentHashing());
    assertEquals(addresses, bean.getNodeList());
}

From source file:com.google.code.ssm.providers.CacheConfigurationTest.java

@Test
public void testInAndOut() {
    final boolean consistent = RandomUtils.nextBoolean();
    final int opTimeout = RandomUtils.nextInt();
    final boolean useBinaryProt = RandomUtils.nextBoolean();

    final CacheConfiguration conf = new CacheConfiguration();
    conf.setConsistentHashing(consistent);
    conf.setOperationTimeout(opTimeout);
    conf.setUseBinaryProtocol(useBinaryProt);

    assertEquals(consistent, conf.isConsistentHashing());
    assertEquals(opTimeout, conf.getOperationTimeout().intValue());
    assertEquals(useBinaryProt, conf.isUseBinaryProtocol());
}

From source file:com.alibaba.otter.shared.common.utils.ExecutorTemplateTest.java

@Test(expectedExceptions = RuntimeException.class)
public void testException() {
    template.start();//from  w w  w  .  j  a  v a 2 s. c om
    long start = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        template.submit(new Runnable() {

            public void run() {
                if (RandomUtils.nextBoolean()) {
                    try {
                        Thread.sleep(RandomUtils.nextInt(5000) + 5000);
                    } catch (InterruptedException e) {
                        System.out.println("i'm cancel");
                    }
                } else {
                    throw new RuntimeException("i'm error");
                }
            }
        });
    }

    template.waitForResult();
    long end = System.currentTimeMillis();
    System.out.println("cost : " + (end - start));
}

From source file:com.rabbitmq.jms.sample.StockQuoter.java

@Scheduled(fixedRate = 5000L) // every 5 seconds
public void publishQuote() {

    // Pick a random stock symbol
    Collections.shuffle(stocks);/*  w  w  w  .  ja v  a2s . c  o  m*/
    String symbol = stocks.get(0);

    // Toss a coin and decide if the price goes...
    if (RandomUtils.nextBoolean()) {
        // ...up by a random 0-10%
        lastPrice.put(symbol, new Double(
                Math.round(lastPrice.get(symbol) * (1 + RandomUtils.nextInt(10) / 100.0) * 100) / 100));
    } else {
        // ...or down by a similar random amount
        lastPrice.put(symbol, new Double(
                Math.round(lastPrice.get(symbol) * (1 - RandomUtils.nextInt(10) / 100.0) * 100) / 100));
    }

    // Log new price locally
    log.info("Quote..." + symbol + " is now " + lastPrice.get(symbol));

    // Coerce a javax.jms.MessageCreator
    MessageCreator messageCreator = (Session session) -> {
        return session.createObjectMessage("Quote..." + symbol + " is now " + lastPrice.get(symbol));
    };

    // And publish to RabbitMQ using Spring's JmsTemplate
    jmsTemplate.send("rabbit-trader-channel", messageCreator);
}

From source file:li.l1t.common.intake.help.CommandHelpExtractor.java

private void appendHoverHintMessage() {
    if (!messages.isEmpty() && RandomUtils.nextBoolean()) {
        messages.add(/*from  ww  w  .jav  a  2s.  co m*/
                translator -> new ComponentBuilder(translator.translateBuiltIn(Message.of("Help.HoverHint")))
                        .color(ChatColor.GOLD).create());
    }
}

From source file:net.sf.click.jquery.examples.page.ajax.ActionDemo.java

@Override
public void onInit() {
    // Example 1/*from ww w.j ava  2 s  .  c  om*/
    // The target div will have its content replaced through Ajax
    final Div target1 = new Div("target1");
    addControl(target1);

    // Create a Ajaxified link that will update a specified target with an
    // ActionResult
    JQActionButton button = new JQActionButton("button", "Click here to make Ajax request");

    button.addBehavior(new JQBehavior() {

        @Override
        public ActionResult onAction(Control source, JQEvent event) {
            // Create a response that will be placed inside the target div
            JQTaconite actionResult = new JQTaconite();
            actionResult.replaceContent(target1, createResponse());
            return actionResult;
        }
    });
    addControl(button);

    // Example 2
    // The target div will have its content replaced through Ajax
    final Div target2 = new Div("target2");
    addControl(target2);

    // Another target div will have its content replaced through Ajax
    final Div target3 = new Div("target3");
    addControl(target3);

    ActionLink link = new ActionLink("link", "Click here to make Ajax request");

    // Provide an alternative message when an Ajax call is made
    /*
    behavior.setIndicatorMessage("\"<h1><img src=\""
    + getContext().getRequest().getContextPath()
    + "/assets/images/indicator.gif\" /> Just a moment...</h1>\"");
     */

    link.addBehavior(new JQBehavior(JQEvent.CLICK) {

        @Override
        public ActionResult onAction(Control source, JQEvent event) {
            // This actionResult will randomly update one target and clear the other

            JQTaconite response = new JQTaconite();
            // Randomly update a different target
            if (RandomUtils.nextBoolean()) {
                response.empty(target3);
                response.replaceContent(target2, createResponse());
            } else {
                //activeTargetId = target3.getId();
                //inactiveTargetId = target2.getId();
                response.empty(target2);
                response.replaceContent(target3, createResponse());
            }

            return response;

            // Return normal Javascript that will be executed by JQuery
            //return new ActionResult("jQuery('#" + activeTargetId + "').html(\"" + createResponse() + "\");" +
            //   "jQuery('#" + inactiveTargetId + "').html(\"\");");
        }
    });
    addControl(link);
}

From source file:com.epam.catgenome.util.BlockCompressedDataStreamsTest.java

private void doWrite(BlockCompressedDataOutputStream outputStream) throws IOException {
    outputStream.writeFloat(RandomUtils.nextFloat());
    outputStream.writeDouble(RandomUtils.nextDouble());
    outputStream.writeLong(RandomUtils.nextLong());
    outputStream.writeInt(RandomUtils.nextInt());
    outputStream.writeShort(0);/* w  w  w. j a  v a  2 s  .  c  o  m*/
    outputStream.writeBoolean(RandomUtils.nextBoolean());
    outputStream.writeBytes("test");
    outputStream.writeByte(RandomUtils.nextInt());
    outputStream.writeChar(TEST_CHAR_ID);
    outputStream.writeChars("test");
    outputStream.flush();
}

From source file:net.nelz.simplesm.aop.MockMemcachedClient.java

public Map<String, Object> getBulk(Collection<String> strings) throws OperationTimeoutException {
    final Map<String, Object> results = new HashMap<String, Object>();
    for (final String key : strings) {
        final Object result = map.get(key);
        if (result != null) {
            results.put(key, result);//from   www.  j a v  a  2 s .  c  o  m
        } else if (RandomUtils.nextBoolean()) {
            results.put(key, result);
        }
    }
    return results;
}

From source file:com.epam.catgenome.manager.externaldb.bindings.ExternalDBBindingTest.java

private Object createParam(Class type)
        throws IllegalAccessException, InvocationTargetException, InstantiationException {
    Object param;// ww  w.  j  a va2  s  . c  o m
    if (type == String.class) {
        param = "test";
    } else if (type == Integer.class || type == Integer.TYPE) {
        param = RandomUtils.nextInt();
    } else if (type == Long.class || type == Long.TYPE) {
        param = RandomUtils.nextLong();
    } else if (type == Float.class || type == Float.TYPE) {
        param = RandomUtils.nextFloat();
    } else if (type == Double.class || type == Double.TYPE) {
        param = RandomUtils.nextDouble();
    } else if (type == Boolean.class || type == Boolean.TYPE) {
        param = RandomUtils.nextBoolean();
    } else if (type == BigInteger.class) {
        param = new BigInteger(TEST_BIGINTEGER);
    } else if (type == List.class) {
        param = new ArrayList<>();
    } else if (type == XMLGregorianCalendar.class) {
        try {
            param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    } else {
        Constructor[] constructors = type.getConstructors();
        param = constructors[0].newInstance();
    }

    return param;
}

From source file:net.nelz.simplesm.aop.ReadThroughMultiCacheTest.java

@Test
public void testGenerateResults() {
    final List<Object> keyObjects = new ArrayList<Object>();
    final Map<Object, String> obj2key = new HashMap<Object, String>();
    final Map<String, Object> key2result = new HashMap<String, Object>();
    final List<Object> expectedResults = new ArrayList<Object>();
    final int length = 10;
    for (int ix = 0; ix < length; ix++) {
        final String keyObject = RandomStringUtils.randomAlphanumeric(8);
        final String key = keyObject + "-" + RandomStringUtils.randomAlphanumeric(4);

        keyObjects.add(keyObject);/*from www  .j  ava 2 s . c o  m*/
        obj2key.put(keyObject, key);

        if (RandomUtils.nextBoolean()) {
            final String result = RandomStringUtils.randomAlphanumeric(15);
            key2result.put(key, result);
            expectedResults.add(result);
        } else {
            key2result.put(key, new PertinentNegativeNull());
            expectedResults.add(null);
        }
    }

    coord.setKeyObjects(keyObjects);
    coord.getObj2Key().putAll(obj2key);
    coord.getKey2Result().putAll(key2result);

    final List<Object> results = coord.generateResultList();

    assertEquals(length, results.size());
    assertEquals(expectedResults, results);
}