Example usage for java.lang Integer parseInt

List of usage examples for java.lang Integer parseInt

Introduction

In this page you can find the example usage for java.lang Integer parseInt.

Prototype

public static int parseInt(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal integer.

Usage

From source file:com.artofsolving.jodconverter.cli.ConvertDocument.java

public static void main(String[] arguments) throws Exception {
    CommandLineParser commandLineParser = new PosixParser();
    CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments);

    int port = SocketOpenOfficeConnection.DEFAULT_PORT;
    if (commandLine.hasOption(OPTION_PORT.getOpt())) {
        port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt()));
    }/*from   ww  w .  j a v a 2s  .c  om*/

    String outputFormat = null;
    if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) {
        outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt());
    }

    boolean verbose = false;
    if (commandLine.hasOption(OPTION_VERBOSE.getOpt())) {
        verbose = true;
    }

    DocumentFormatRegistry registry;
    if (commandLine.hasOption(OPTION_XML_REGISTRY.getOpt())) {
        File registryFile = new File(commandLine.getOptionValue(OPTION_XML_REGISTRY.getOpt()));
        if (!registryFile.isFile()) {
            System.err.println("ERROR: specified XML registry file not found: " + registryFile);
            System.exit(EXIT_CODE_XML_REGISTRY_NOT_FOUND);
        }
        registry = new XmlDocumentFormatRegistry(new FileInputStream(registryFile));
        if (verbose) {
            System.out.println("-- loaded document format registry from " + registryFile);
        }
    } else {
        registry = new DefaultDocumentFormatRegistry();
    }

    String[] fileNames = commandLine.getArgs();
    if ((outputFormat == null && fileNames.length != 2) || fileNames.length < 1) {
        String syntax = "convert [options] input-file output-file; or\n"
                + "[options] -f output-format input-file [input-file...]";
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(syntax, OPTIONS);
        System.exit(EXIT_CODE_TOO_FEW_ARGS);
    }

    OpenOfficeConnection connection = new SocketOpenOfficeConnection(port);
    try {
        if (verbose) {
            System.out.println("-- connecting to OpenOffice.org on port " + port);
        }
        connection.connect();
    } catch (ConnectException officeNotRunning) {
        System.err.println(
                "ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port "
                        + port + ".");
        System.exit(EXIT_CODE_CONNECTION_FAILED);
    }
    try {
        DocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry);
        if (outputFormat == null) {
            File inputFile = new File(fileNames[0]);
            File outputFile = new File(fileNames[1]);
            convertOne(converter, inputFile, outputFile, verbose);
        } else {
            for (int i = 0; i < fileNames.length; i++) {
                File inputFile = new File(fileNames[i]);
                File outputFile = new File(FilenameUtils.getFullPath(fileNames[i])
                        + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat);
                convertOne(converter, inputFile, outputFile, verbose);
            }
        }
    } finally {
        if (verbose) {
            System.out.println("-- disconnecting");
        }
        connection.disconnect();
    }
}

From source file:eu.delving.x3ml.X3MLCommandLine.java

public static void main(String[] args) {
    Option xml = new Option("xml", true, "XML input records: -xml input.xml (@ = stdin)");
    xml.setRequired(true);/*from  www  .  j ava2s .  com*/
    Option x3ml = new Option("x3ml", true, "X3ML mapping definition: -x3ml mapping.x3ml (@ = stdin)");
    x3ml.setRequired(true);
    Option rdf = new Option("rdf", true, "The RDF output file name: -rdf output.rdf");
    Option policy = new Option("policy", true, "The value policy file: -policy policy.xml");
    Option rdfFormat = new Option("format", true,
            "Output format: -format application/n-triples, text/turtle, application/rdf+xml (default)");
    Option validate = new Option("validate", false, "Validate X3ML v1.0 using XSD");
    Option uuidTestSize = new Option("uuidTestSize", true,
            "Create a test UUID generator of the given size. Default is UUID from operating system");
    options.addOption(rdfFormat).addOption(rdf).addOption(x3ml).addOption(xml).addOption(policy)
            .addOption(validate).addOption(uuidTestSize);
    try {
        CommandLine cli = PARSER.parse(options, args);
        int uuidTestSizeValue = -1;
        String uuidTestSizeString = cli.getOptionValue("uuidTestSize");
        if (uuidTestSizeString != null) {
            uuidTestSizeValue = Integer.parseInt(uuidTestSizeString);
        }
        go(cli.getOptionValue("xml"), cli.getOptionValue("x3ml"), cli.getOptionValue("policy"),
                cli.getOptionValue("rdf"), cli.getOptionValue("format"), cli.hasOption("validate"),
                uuidTestSizeValue);
    } catch (Exception e) {
        error(e.getMessage());
    }

}

From source file:it.tizianofagni.sparkboost.AdaBoostMHLearnerExe.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("b", "binaryProblem", false,
            "Indicate if the input dataset contains a binary problem and not a multilabel one");
    options.addOption("z", "labels0based", false,
            "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included");
    options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark");
    options.addOption("w", "windowsLocalModeFix", true,
            "Set the directory containing the winutils.exe command");
    options.addOption("dp", "documentPartitions", true, "The number of document partitions");
    options.addOption("fp", "featurePartitions", true, "The number of feature partitions");
    options.addOption("lp", "labelPartitions", true, "The number of label partitions");

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;//from www .  j  ava2s.  com
    String[] remainingArgs = null;
    try {
        cmd = parser.parse(options, args);
        remainingArgs = cmd.getArgs();
        if (remainingArgs.length != 5)
            throw new ParseException("You need to specify all mandatory parameters");
    } catch (ParseException e) {
        System.out.println("Parsing failed.  Reason: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(AdaBoostMHLearnerExe.class.getSimpleName()
                + " [OPTIONS] <inputFile> <outputFile> <numIterations> <sparkMaster> <parallelismDegree>",
                options);
        System.exit(-1);
    }

    boolean binaryProblem = false;
    if (cmd.hasOption("b"))
        binaryProblem = true;
    boolean labels0Based = false;
    if (cmd.hasOption("z"))
        labels0Based = true;
    boolean enablingSparkLogging = false;
    if (cmd.hasOption("l"))
        enablingSparkLogging = true;

    if (cmd.hasOption("w")) {
        System.setProperty("hadoop.home.dir", cmd.getOptionValue("w"));
    }

    String inputFile = remainingArgs[0];
    String outputFile = remainingArgs[1];
    int numIterations = Integer.parseInt(remainingArgs[2]);
    String sparkMaster = remainingArgs[3];
    int parallelismDegree = Integer.parseInt(remainingArgs[4]);

    long startTime = System.currentTimeMillis();

    // Disable Spark logging.
    if (!enablingSparkLogging) {
        Logger.getLogger("org").setLevel(Level.OFF);
        Logger.getLogger("akka").setLevel(Level.OFF);
    }

    // Create and configure Spark context.
    SparkConf conf = new SparkConf().setAppName("Spark AdaBoost.MH learner");
    JavaSparkContext sc = new JavaSparkContext(conf);

    // Create and configure learner.
    AdaBoostMHLearner learner = new AdaBoostMHLearner(sc);
    learner.setNumIterations(numIterations);

    if (cmd.hasOption("dp")) {
        learner.setNumDocumentsPartitions(Integer.parseInt(cmd.getOptionValue("dp")));
    }
    if (cmd.hasOption("fp")) {
        learner.setNumFeaturesPartitions(Integer.parseInt(cmd.getOptionValue("fp")));
    }
    if (cmd.hasOption("lp")) {
        learner.setNumLabelsPartitions(Integer.parseInt(cmd.getOptionValue("lp")));
    }

    // Build classifier with MPBoost learner.
    BoostClassifier classifier = learner.buildModel(inputFile, labels0Based, binaryProblem);

    // Save classifier to disk.
    DataUtils.saveModel(sc, classifier, outputFile);

    long endTime = System.currentTimeMillis();
    System.out.println("Execution time: " + (endTime - startTime) + " milliseconds.");
}

From source file:io.netty.example.http.helloworld.HttpHelloWorldServer.java

public static void main(String[] args) throws Exception {
    int port;/*from  w  ww. ja v a2 s.  co  m*/
    if (args.length > 0) {
        port = Integer.parseInt(args[0]);
    } else {
        port = 8082;
    }
    new HttpHelloWorldServer(port).run();
}

From source file:com.ict.dtube.example.operation.Producer.java

public static void main(String[] args) throws MQClientException, InterruptedException {
    CommandLine commandLine = buildCommandline(args);
    if (commandLine != null) {
        String group = commandLine.getOptionValue('g');
        String topic = commandLine.getOptionValue('t');
        String tags = commandLine.getOptionValue('a');
        String keys = commandLine.getOptionValue('k');
        String msgCount = commandLine.getOptionValue('c');

        DtubeProducer producer = new DtubeProducer(group);
        producer.setInstanceName(Long.toString(System.currentTimeMillis()));

        producer.start();/*from   w  w  w .ja  va2  s .c  om*/

        for (int i = 0; i < Integer.parseInt(msgCount); i++) {
            try {
                Message msg = new Message(//
                        topic, // topic
                        tags, // tag
                        keys, // key
                        ("Hello Dtube " + i).getBytes());// body
                SendResult sendResult = producer.send(msg);

                System.out.printf("%-8d %s\n", i, sendResult);
            } catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }

        producer.shutdown();
    }
}

From source file:com.boozallen.cognition.kom.KafakOffsetMonitor.java

public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;/*ww  w  .  ja v a2 s  .c o  m*/
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("KafakOffsetMonitor", options);
        System.exit(1);
    }

    KafakOffsetMonitor monitor = new KafakOffsetMonitor();
    monitor.zkHosts = cmd.getOptionValue("zkHosts");
    monitor.zkRoot = cmd.getOptionValue("zkRoot", "/storm-kafka");
    monitor.spoutId = cmd.getOptionValue("spoutId");
    monitor.logstashHost = cmd.getOptionValue("logstashHost");
    monitor.logstashPort = Integer.parseInt(cmd.getOptionValue("logstashPort"));

    int refresh = Integer.parseInt(cmd.getOptionValue("refresh", "15"));

    Timer timer = new Timer();
    int period = refresh * 1000;
    int delay = 0;
    timer.schedule(monitor, delay, period);
}

From source file:io.pivotal.kr.load_gen.Main.java

public static void main(String[] args) throws IOException {
    if (args.length != 6) {
        System.err.println(/*w w  w  .j a  v  a  2s .  c  om*/
                "Correct usage: java -jar load-gen.jar <batch|autocommit> <insert|select|update|delete> <dataDir> <sqlMapConfigXMLPath> <delimiter> <numberOfThreads>");

        System.exit(-1);
    }

    String type = args[0];
    String mode = args[1];
    String dataDir = args[2];
    String sqlMapConfigXMLPath = args[3];
    String delimiter = args[4];
    String numberOfThreads = args[5];

    if (StringUtils.isEmpty(type) || StringUtils.isEmpty(mode) || StringUtils.isEmpty(dataDir)
            || StringUtils.isEmpty(sqlMapConfigXMLPath) || StringUtils.isEmpty(delimiter)
            || StringUtils.isEmpty(numberOfThreads)) {
        System.err.println(
                "Correct usage: java -jar load-gen.jar <batch|autocommit> <insert|select|update|delete> <dataDir> <sqlMapConfigXMLPath> <delimiter> <numberOfThreads>");

        System.exit(-1);
    }

    dataDir = stripSurroundingQuotes(dataDir);
    sqlMapConfigXMLPath = stripSurroundingQuotes(sqlMapConfigXMLPath);
    delimiter = stripSurroundingQuotes(delimiter);

    new GemfireXDLoadManager(type, mode, dataDir, sqlMapConfigXMLPath, delimiter,
            Integer.parseInt(numberOfThreads));
}

From source file:com.twitter.distributedlog.messaging.ConsoleProxyPartitionedMultiWriter.java

public static void main(String[] args) throws Exception {
    if (2 != args.length) {
        System.out.println(HELP);
        return;//  w  ww.j  a v a  2s.  c o m
    }

    String finagleNameStr = args[0];
    final String streamList = args[1];

    DistributedLogClient client = DistributedLogClientBuilder.newBuilder()
            .clientId(ClientId.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true)
            .finagleNameStr(finagleNameStr).build();
    String[] streamNameList = StringUtils.split(streamList, ',');
    PartitionedWriter<Integer, String> partitionedWriter = new PartitionedWriter<Integer, String>(
            streamNameList, new IntPartitioner(), client);

    // Setup Terminal
    Terminal terminal = Terminal.setupTerminal();
    ConsoleReader reader = new ConsoleReader();
    String line;
    while ((line = reader.readLine(PROMPT_MESSAGE)) != null) {
        String[] parts = StringUtils.split(line, ':');
        if (parts.length != 2) {
            System.out.println("Invalid input. Needs 'KEY:VALUE'");
            continue;
        }
        int key;
        try {
            key = Integer.parseInt(parts[0]);
        } catch (NumberFormatException nfe) {
            System.out.println("Invalid input. Needs 'KEY:VALUE'");
            continue;
        }
        String value = parts[1];

        partitionedWriter.write(key, value).addEventListener(new FutureEventListener<DLSN>() {
            @Override
            public void onFailure(Throwable cause) {
                System.out.println("Encountered error on writing data");
                cause.printStackTrace(System.err);
                Runtime.getRuntime().exit(0);
            }

            @Override
            public void onSuccess(DLSN value) {
                // done
            }
        });
    }

    client.close();
}

From source file:com.github.jakz.geophoto.reverse.NominatimReverseGeocodingJAPI.java

public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("use -help for instructions");
    } else if (args.length < 2) {
        if (args[0].equals("-help")) {
            System.out.println("Mandatory parameters:");
            System.out.println("   -lat [latitude]");
            System.out.println("   -lon [longitude]");
            System.out.println("\nOptional parameters:");
            System.out.println("   -zoom [0-18] | from 0 (country) to 18 (street address), default 18");
            System.out.println("   -osmid       | show also osm id and osm type of the address");
            System.out.println("\nThis page:");
            System.out.println("   -help");
        } else//w  w w .j a  va  2 s .c o m
            System.err.println("invalid parameters, use -help for instructions");
    } else {
        boolean latSet = false;
        boolean lonSet = false;
        boolean osm = false;

        double lat = -200;
        double lon = -200;
        int zoom = 18;

        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-lat")) {
                try {
                    lat = Double.parseDouble(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid latitude");
                    return;
                }

                latSet = true;
                i++;
                continue;
            } else if (args[i].equals("-lon")) {
                try {
                    lon = Double.parseDouble(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid longitude");
                    return;
                }

                lonSet = true;
                i++;
                continue;
            } else if (args[i].equals("-zoom")) {
                try {
                    zoom = Integer.parseInt(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid zoom");
                    return;
                }

                i++;
                continue;
            } else if (args[i].equals("-osm")) {
                osm = true;
            } else {
                System.err.println("invalid parameters, use -help for instructions");
                return;
            }
        }

        if (latSet && lonSet) {
            NominatimReverseGeocodingJAPI nominatim = new NominatimReverseGeocodingJAPI(zoom);
            Geocode address = nominatim.reverse(new Coordinate(lat, lon));
            System.out.println(address);
        } else {
            System.err.println("please specifiy -lat and -lon, use -help for instructions");
        }
    }
}

From source file:tetrad.rrd.TestInstallTotalData.java

public static void main(String[] args) {
    String[] configLocations = new String[] { "applicationContext_rrd.xml" };
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configLocations);

    TetradRrdInitializer tetradInitial = (TetradRrdInitializer) context.getBean("tetradRrdInitializer");
    DeviceInMemory deviceInMemory = (DeviceInMemory) context.getBean("deviceInMemory");
    MongoInMemory mongoInMemory = (MongoInMemory) context.getBean("mongoInMemory");
    try {/*from   w w  w. j  av  a 2 s .c o  m*/
        deviceInMemory.createDeviceGroup();
        mongoInMemory.createMongoGroup();
        String poolSize = TetradRrdConfig.getTetradRrdConfig("default_rrdPoolSize");
        TetradRrdDbPool.setPoolCount(Integer.parseInt(poolSize));

        //         tetradInitial.installTotalRrdDb();
        tetradInitial.install();
        //         tetradInitial.input();
        //         TestInstallTotalData a = new TestInstallTotalData();
        //         a.initaillTotalRrd();
    } catch (Exception e) {
        System.out.println("install error");
    }
}