Example usage for org.apache.commons.lang3.math NumberUtils toInt

List of usage examples for org.apache.commons.lang3.math NumberUtils toInt

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math NumberUtils toInt.

Prototype

public static int toInt(final String str, final int defaultValue) 

Source Link

Document

Convert a String to an int, returning a default value if the conversion fails.

If the string is null, the default value is returned.

 NumberUtils.toInt(null, 1) = 1 NumberUtils.toInt("", 1)   = 1 NumberUtils.toInt("1", 0)  = 1 

Usage

From source file:com.mpush.test.client.ConnClientTestMain.java

public static void main(String[] args) throws Exception {
    int count = 1;
    String userPrefix = "";
    int printDelay = 1;
    boolean sync = true;

    if (args.length > 0) {
        count = NumberUtils.toInt(args[0], count);
    }/* w w w .ja v  a  2  s .c  o m*/

    if (args.length > 1) {
        userPrefix = args[1];
    }

    if (args.length > 2) {
        printDelay = NumberUtils.toInt(args[2], printDelay);
    }

    if (args.length > 3) {
        sync = !"1".equals(args[3]);
    }

    testConnClient(count, userPrefix, printDelay, sync);
}

From source file:io.apiman.test.common.echo.EchoServer.java

public static void main(String[] args) throws Exception {
    int port = NumberUtils.toInt(System.getProperty("io.apiman.test.common.echo.port"), 9999); //$NON-NLS-1$
    new EchoServer(port).start().join();
}

From source file:com.netsteadfast.greenstep.util.PdfConvertUtils.java

public static void main(String args[]) throws Exception {
    if (args == null || args.length != 2) {
        System.out.println("PdfConvertUtils [FILE] [RESOLUTION]");
        System.out.println("Example: PdfConvertUtils /test.pdf 120");
        System.exit(1);/*from ww  w.  j a  v  a 2  s.co  m*/
    }
    System.out.println("source document file: " + args[0]);
    int res = NumberUtils.toInt(args[1], 300);
    List<File> imageFiles = toImageFiles(new File(args[0]), res);
    for (File file : imageFiles) {
        System.out.println(file.getPath());
    }
}

From source file:com.esri.geoevent.test.performance.ConsumerMain.java

/**
 * Main method - this is used to when running from command line
 *
 * @param args Command Line Parameters/*from w w w  .  j  a  va 2 s  .c  o m*/
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {

    // performer options
    Options performerOptions = new Options();
    performerOptions
            .addOption(OptionBuilder
                    .withLongOpt("type").withDescription("One of the following values: ["
                            + Protocol.getAllowableValues() + "]. (Default value is tcp).")
                    .hasArg().create("t"));
    performerOptions.addOption(OptionBuilder.withLongOpt("commandListenerPort").withDescription(
            "The TCP Port where consumer will listen for commands from the orchestrator. (Default value is 5010).")
            .hasArg().create("p"));
    performerOptions.addOption(OptionBuilder.withLongOpt("serverPort")
            .withDescription("The TCP Port where the server will listen for events. (Default value is 5675)")
            .hasArg().create("sp"));
    performerOptions.addOption("h", "help", false, "print the help message");

    // parse the command line
    CommandLineParser parser = new BasicParser();
    CommandLine cmd;

    // parse
    try {
        cmd = parser.parse(performerOptions, args, false);
    } catch (ParseException error) {
        printHelp(performerOptions);
        return;
    }

    // User requested Help 
    if (cmd.hasOption("h")) {
        printHelp(performerOptions);
        return;
    }

    if (cmd.getOptions().length == 0) {

        ConsumerUI ui = new ConsumerUI();
        ui.run();

    } else {
        // parse out the performer options
        String protocolValue = cmd.getOptionValue("t");
        String commandListenerPortValue = cmd.getOptionValue("p");

        if (protocolValue == null) {
            protocolValue = "tcp";
        }
        if (commandListenerPortValue == null) {
            commandListenerPortValue = "5020";
        }
        // validate
        if (!validateTestHarnessOptions(protocolValue, commandListenerPortValue)) {
            printHelp(performerOptions);
            return;
        }

        // parse the values
        Protocol protocol = Protocol.fromValue(protocolValue);
        boolean isLocal = "local".equalsIgnoreCase(commandListenerPortValue);
        int commandListenerPort = -1;
        if (!isLocal) {
            commandListenerPort = Integer.parseInt(commandListenerPortValue);
        }

        int serverPort = NumberUtils.toInt(cmd.getOptionValue("sp"), 5775);
        PerformanceCollector consumer;
        switch (protocol) {
        case TCP:
            consumer = new TcpEventConsumer();
            break;
        case TCP_SERVER:
            consumer = new TcpServerEventConsumer(serverPort);
            break;
        case WEBSOCKETS:
            consumer = new WebsocketEventConsumer();
            break;
        case WEBSOCKET_SERVER:
            consumer = new WebsocketServerEventConsumer(serverPort);
            break;
        case ACTIVE_MQ:
            consumer = new ActiveMQEventConsumer();
            break;
        case RABBIT_MQ:
            consumer = new RabbitMQEventConsumer();
            break;
        case STREAM_SERVICE:
            consumer = new StreamServiceEventConsumer();
            break;
        case KAFKA:
            consumer = new KafkaEventConsumer();
            break;
        case BDS:
            consumer = new BdsEventConsumer();
            break;
        case AZURE:
            consumer = new AzureIoTHubConsumer();
            break;
        default:
            return;
        }
        consumer.listenOnCommandPort((isLocal ? 5020 : commandListenerPort), true);

    }

}

From source file:com.esri.geoevent.test.performance.ProducerMain.java

/**
 * Main method - this is used to when running from command line
 *
 * @param args Command Line Options//from   w w w. jav  a 2s . c  o  m
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {

    // performer options
    Options performerOptions = new Options();
    performerOptions
            .addOption(OptionBuilder
                    .withLongOpt("type").withDescription("One of the following values: ["
                            + Protocol.getAllowableValues() + "]. (Default value is tcp).")
                    .hasArg().create("t"));
    performerOptions.addOption(OptionBuilder.withLongOpt("commandListenerPort").withDescription(
            "The TCP Port where producer will listen for commands from the orchestrator. (Default value is 5020).")
            .hasArg().create("p"));
    performerOptions.addOption(OptionBuilder.withLongOpt("serverPort")
            .withDescription("The TCP Port where the server will produce events. (Default value is 5665)")
            .hasArg().create("sp"));
    performerOptions.addOption("h", "help", false, "print the help message");

    // parse the command line
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;

    // parse
    try {
        cmd = parser.parse(performerOptions, args, false);
    } catch (ParseException error) {
        printHelp(performerOptions);
        return;
    }

    if (cmd.getOptions().length == 0) {
        // No Args Start GUI
        ProducerUI ui = new ProducerUI();
        ui.run();
    } else {
        // User Request Help Page
        if (cmd.hasOption("h")) {
            printHelp(performerOptions);
            return;
        }

        // parse out the performer options
        String protocolValue = cmd.getOptionValue("t");
        String commandListenerPortValue = cmd.getOptionValue("p");

        if (protocolValue == null) {
            protocolValue = "tcp";
        }
        if (commandListenerPortValue == null) {
            commandListenerPortValue = "5010";
        }

        // validate
        if (!validateTestHarnessOptions(protocolValue, commandListenerPortValue)) {
            printHelp(performerOptions);
            return;
        }

        // parse the values
        Protocol protocol = Protocol.fromValue(protocolValue);
        boolean isLocal = "local".equalsIgnoreCase(commandListenerPortValue);
        int commandListenerPort = -1;
        if (!isLocal) {
            commandListenerPort = Integer.parseInt(commandListenerPortValue);
        }

        int serverPort = NumberUtils.toInt(cmd.getOptionValue("sp"), 5665);
        PerformanceCollector producer = null;
        switch (protocol) {
        case TCP:
            producer = new TcpEventProducer();
            break;
        case TCP_SERVER:
            producer = new TcpServerEventProducer(serverPort);
            break;
        case WEBSOCKETS:
            producer = new WebsocketEventProducer();
            break;
        case ACTIVE_MQ:
            producer = new ActiveMQEventProducer();
            break;
        case RABBIT_MQ:
            producer = new RabbitMQEventProducer();
            break;
        case STREAM_SERVICE:
            producer = new StreamServiceEventProducer();
            break;
        case KAFKA:
            producer = new KafkaEventProducer();
            break;
        case WEBSOCKET_SERVER:
            producer = new WebsocketServerEventProducer(serverPort);
            break;
        case AZURE:
            producer = new AzureIoTHubProducer();
            break;
        case REST_JSON:
            producer = new JsonEventProducer();
            break;
        default:
            return;
        }
        producer.listenOnCommandPort((isLocal ? 5010 : commandListenerPort), true);

    }

}

From source file:jease.cms.service.Revisions.java

/**
 * Minimum count of revisions to be kept. -1 means unlimited.
 *///ww w  .j  a va 2 s .  c  o  m
public static int getCount() {
    return NumberUtils.toInt(Registry.getParameter(Names.JEASE_REVISION_COUNT), -1);
}

From source file:ezbake.common.openshift.OpenShiftUtil.java

public static HostAndPort getThriftPrivateInfo() {
    String ip = Preconditions.checkNotNull(System.getenv("OPENSHIFT_JAVA_THRIFTRUNNER_IP"));
    String port = Preconditions.checkNotNull(System.getenv("OPENSHIFT_JAVA_THRIFTRUNNER_TCP_PORT"));
    return HostAndPort.fromParts(ip, NumberUtils.toInt(port, -1));
}

From source file:com.yahoo.parsec.filters.ProfilingFilter.java

@Override
public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException {
    Request request = ctx.getRequest();
    int requestCount = NumberUtils
            .toInt(request.getHeaders().getFirstValue(ParsecClientDefine.HEADER_PROFILING_REQUEST_COUNT), 0);
    request.getHeaders().replaceWith(ParsecClientDefine.HEADER_PROFILING_REQUEST_COUNT,
            String.valueOf(++requestCount));

    return super.filter(ctx);
}

From source file:jease.cms.service.Revisions.java

/**
 * Number of days in the past for which revisions should be kept. -1 means
 * unlimited./*from ww w .j  a v a2 s  .  c  o  m*/
 */
public static int getDays() {
    return NumberUtils.toInt(Registry.getParameter(Names.JEASE_REVISION_DAYS), -1);
}

From source file:info.donsun.core.utils.Values.java

/**
 * ??//from  w w w. ja  v a  2s.  co  m
 * 
 * @param obj 
 * @param defaultValue null
 * @return 
 */
public static int getInt(Object key, int defaultValue) {
    return NumberUtils.toInt(getString(key), defaultValue);
}