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:Superstitious.java

public static void main(String[] args) {
    Month month = null;/*from   w ww  .  ja v a  2s .  co m*/
    LocalDate date = null;

    if (args.length < 2) {
        System.out.printf("Usage: Superstitious <month> <day>%n");
        throw new IllegalArgumentException();
    }

    try {
        month = Month.valueOf(args[0].toUpperCase());
    } catch (IllegalArgumentException exc) {
        System.out.printf("%s is not a valid month.%n", args[0]);
        throw exc; // Rethrow the exception.
    }

    int day = Integer.parseInt(args[1]);

    try {
        date = Year.now().atMonth(month).atDay(day);
    } catch (DateTimeException exc) {
        System.out.printf("%s %s is not a valid date.%n", month, day);
        throw exc; // Rethrow the exception.
    }

    System.out.println(date.query(new FridayThirteenQuery()));
}

From source file:com.rapleaf.hank.cli.AddDomainToDomainGroup.java

/**
 * @param args//from w w  w. j a  v  a 2 s  .c  om
 * @throws IOException
 * @throws ParseException
 * @throws NumberFormatException
 * @throws InvalidConfigurationException
 */
public static void main(String[] args)
        throws IOException, ParseException, NumberFormatException, InvalidConfigurationException {
    Options options = new Options();
    options.addOption("g", "domain-group", true, "the name of the domain group");
    options.addOption("d", "domain", true, "the name of the domain to be added to the group");
    options.addOption("i", "id", true, "the id for the domain in this group");
    options.addOption("c", "config", true,
            "path of a valid config file with coordinator connection information");
    try {
        CommandLine line = new GnuParser().parse(options, args);
        CommandLineChecker.check(line, options, new String[] { "config", "domain-group", "domain" },
                AddDomainToDomainGroup.class);
        ClientConfigurator configurator = new YamlClientConfigurator(line.getOptionValue("config"));
        addDomainToDomainGroup(configurator, line.getOptionValue("domain-group"), line.getOptionValue("domain"),
                Integer.parseInt(line.getOptionValue("id")));
    } catch (ParseException e) {
        new HelpFormatter().printHelp("add_domain", options);
        throw e;
    }
}

From source file:com.redhat.poc.jdg.bankofchina.function.TestCase411RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/*from w w  w .  j  a  v  a 2s. c om*/
    Options options = new Options();
    options.addOption("s", true, "The start csv file number option");
    options.addOption("e", true, "The end csv file number option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("s")) {
            String start = commandLine.getOptionValue("s");
            if (start != null && start.length() > 0) {
                csvFileStart = Integer.parseInt(start);
            }
        }
        if (commandLine.hasOption("e")) {
            String end = commandLine.getOptionValue("e");
            if (end != null && end.length() > 0) {
                csvFileEnd = Integer.parseInt(end);
            }
        }
    }

    System.out.println(
            "%%%%%%%%%  csv ?, ?, ?(ms),"
                    + new Date().getTime());

    for (int i = csvFileStart; i <= csvFileEnd; i++) {
        new TestCase411RemoteMultiThreads(i).start();
    }
}

From source file:TreeNode.java

public static void main(String[] argv) throws IOException {
    BinaryTree bt = new BinaryTree();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int val;
    char ch = ' ';
    String clearbuffer;/*from   w ww  . j a  v a 2s.c o m*/
    do {
        System.out.print("Enter a number: ");
        val = Integer.parseInt(br.readLine());
        bt.insert(val);
        System.out.print("Do you wish to enter more values (Y/N).....");
        ch = (char) br.read();
        clearbuffer = br.readLine();
    } while (ch == 'y' || ch == 'Y');
    System.out.println("Postorder traversal of given tree is: ");
    bt.postorder();
    System.out.println("Preorder traversal of given tree is: ");
    bt.preorder();
    System.out.println("Inorder traversal of given tree is: ");
    bt.inorder();
}

From source file:au.org.ala.layers.stats.ObjectsStatsGenerator.java

public static void main(String[] args) {
    long start = System.currentTimeMillis();

    String fid = null;/*  ww  w  . java  2 s  .c o m*/

    logger.info(
            "args[0] = threadcount, args[1] = db connection string, args[2] = db username, args[3] = password");
    if (args.length >= 4) {
        CONCURRENT_THREADS = Integer.parseInt(args[0]);
        db_url = args[1];
        db_usr = args[2];
        db_pwd = args[3];
    }
    if (args.length > 4) {
        fid = args[4];
    }

    Connection c = getConnection();
    //String count_sql = "select count(*) as cnt from objects where bbox is null or area_km is null";
    String count_sql = "select count(*) as cnt from objects where area_km is null and st_geometrytype(the_geom) <> 'ST_Point' ";
    if (StringUtils.isEmpty(fid)) {
        count_sql = count_sql + " and fid = '" + fid + "'";
    }

    int count = 0;
    try {
        Statement s = c.createStatement();
        ResultSet rs = s.executeQuery(count_sql);
        while (rs.next()) {
            count = rs.getInt("cnt");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    int iter = count / 200000;

    logger.info("Breaking into " + iter + " iterations");
    for (int i = 0; i <= iter; i++) {
        long iterStart = System.currentTimeMillis();
        //  updateBbox();
        updateArea(fid);
        logger.info("iteration " + i + " completed after " + (System.currentTimeMillis() - iterStart) + "ms");
        logger.info("total time taken is " + (System.currentTimeMillis() - start) + "ms");
    }
}

From source file:com.francetelecom.admindm.changedustate.callviaacs.CallChangeDUStateUninstallCapabilityOnEdgeAcs.java

/**
 * @param args/*from  w  w w . j  a v  a  2  s.c o  m*/
 */
public static void main(final String[] args) {
    HttpClient client = new HttpClient();
    // client.getHostConfiguration().setProxy("", );

    String host = null;
    String port = null;
    String address = "http://" + host + ":" + port + "/edge/api/";

    String acsUsername = null;
    String acsPassword = null;

    if (host == null || port == null || acsUsername == null || acsPassword == null) {
        throw new InvalidParameterException("Fill host: " + host + ", port: " + port + ", acsUsername: "
                + acsUsername + ", and acsPassword: " + acsPassword + ".");
    }

    String realm = "NBBS_API_Realm";

    AuthScope authscope = new AuthScope(host, Integer.parseInt(port), realm);

    // client.getState().setCredentials(realm, host,
    // new UsernamePasswordCredentials(acsUsername, acsPassword));

    client.getState().setCredentials(authscope, new UsernamePasswordCredentials(acsUsername, acsPassword));

    PostMethod post = null;

    // -----
    // ----- Execution de la capability : changeDUStateUninstall
    // -----

    post = new PostMethod(address + "capability/execute");

    post.addParameter(new NameValuePair("deviceId", "10003"));
    post.addParameter(new NameValuePair("timeoutMs", "60000"));
    post.addParameter(new NameValuePair("capability", "\"changeDUStateUninstall\""));

    // UUID: string
    // Version: string
    // ExecutionEnvRef: String

    JSONObject object = new JSONObject();
    object.put("UUID", "45");
    object.put("Version", "2.2.0");
    object.put("ExecutionEnvRef", "ExecutionEnvRef_value");
    post.addParameter(new NameValuePair("input", object.toString()));

    post.setDoAuthentication(true);

    // post.addParameter(new NameValuePair("deviceId", "60001"));

    // -----
    // ----- Partie commune : Execution du post
    // -----

    try {
        int status = client.executeMethod(post);
        System.out.println("status: " + status);
        String resp = post.getResponseBodyAsString();
        System.out.println("resp: " + resp);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        // release any connection resources used by the method
        post.releaseConnection();
    }
}

From source file:com.cloud.test.longrun.PerformanceWithAPI.java

public static void main(String[] args) {

    List<String> argsList = Arrays.asList(args);
    Iterator<String> iter = argsList.iterator();
    String host = "http://localhost";
    int numThreads = 1;

    while (iter.hasNext()) {
        String arg = iter.next();
        if (arg.equals("-h")) {
            host = "http://" + iter.next();
        }/*www.  jav a  2s . c o  m*/
        if (arg.equals("-t")) {
            numThreads = Integer.parseInt(iter.next());
        }
        if (arg.equals("-n")) {
            numVM = Integer.parseInt(iter.next());
        }
    }

    final String server = host + ":" + _apiPort + "/";
    final String developerServer = host + ":" + _developerPort + _apiUrl;

    s_logger.info("Starting test in " + numThreads + " thread(s). Each thread is launching " + numVM + " VMs");

    for (int i = 0; i < numThreads; i++) {
        new Thread(new Runnable() {
            public void run() {
                try {

                    String username = null;
                    String singlePrivateIp = null;
                    String singlePublicIp = null;
                    Random ran = new Random();
                    username = Math.abs(ran.nextInt()) + "-user";

                    //Create User
                    User myUser = new User(username, username, server, developerServer);
                    try {
                        myUser.launchUser();
                        myUser.registerUser();
                    } catch (Exception e) {
                        s_logger.warn("Error code: ", e);
                    }

                    if (myUser.getUserId() != null) {
                        s_logger.info("User " + myUser.getUserName()
                                + " was created successfully, starting VM creation");
                        //create VMs for the user
                        for (int i = 0; i < numVM; i++) {
                            //Create a new VM, add it to the list of user's VMs
                            VirtualMachine myVM = new VirtualMachine(myUser.getUserId());
                            myVM.deployVM(_zoneId, _serviceOfferingId, _templateId, myUser.getDeveloperServer(),
                                    myUser.getApiKey(), myUser.getSecretKey());
                            myUser.getVirtualMachines().add(myVM);
                            singlePrivateIp = myVM.getPrivateIp();

                            if (singlePrivateIp != null) {
                                s_logger.info(
                                        "VM with private Ip " + singlePrivateIp + " was successfully created");
                            } else {
                                s_logger.info("Problems with VM creation for a user" + myUser.getUserName());
                                break;
                            }

                            //get public IP address for the User            
                            myUser.retrievePublicIp(_zoneId);
                            singlePublicIp = myUser.getPublicIp().get(myUser.getPublicIp().size() - 1);
                            if (singlePublicIp != null) {
                                s_logger.info("Successfully got public Ip " + singlePublicIp + " for user "
                                        + myUser.getUserName());
                            } else {
                                s_logger.info("Problems with getting public Ip address for user"
                                        + myUser.getUserName());
                                break;
                            }

                            //create ForwardProxy rules for user's VMs
                            int responseCode = CreateForwardingRule(myUser, singlePrivateIp, singlePublicIp,
                                    "22", "22");
                            if (responseCode == 500)
                                break;
                        }

                        s_logger.info("Deployment successful..." + numVM
                                + " VMs were created. Waiting for 5 min before performance test");
                        Thread.sleep(300000L); // Wait 

                        //Start performance test for the user
                        s_logger.info("Starting performance test for Guest network that has "
                                + myUser.getPublicIp().size() + " public IP addresses");
                        for (int j = 0; j < myUser.getPublicIp().size(); j++) {
                            s_logger.info("Starting test for user which has "
                                    + myUser.getVirtualMachines().size() + " vms. Public IP for the user is "
                                    + myUser.getPublicIp().get(j) + " , number of retries is " + _retry
                                    + " , private IP address of the machine is"
                                    + myUser.getVirtualMachines().get(j).getPrivateIp());
                            guestNetwork myNetwork = new guestNetwork(myUser.getPublicIp().get(j), _retry);
                            myNetwork.setVirtualMachines(myUser.getVirtualMachines());
                            new Thread(myNetwork).start();
                        }

                    }
                } catch (Exception e) {
                    s_logger.error(e);
                }
            }
        }).start();

    }
}

From source file:com.francetelecom.admindm.changedustate.callviaacs.CallChangeDUStateUpdateCapabilityOnEdgeAcs.java

/**
 * @param args/*from  w  w  w  .  j  a va  2 s .  co m*/
 */
public static void main(final String[] args) {
    HttpClient client = new HttpClient();
    // client.getHostConfiguration().setProxy("", );

    String host = null;
    String port = null;
    String address = "http://" + host + ":" + port + "/edge/api/";

    String acsUsername = null;
    String acsPassword = null;

    if (host == null || port == null || acsUsername == null || acsPassword == null) {
        throw new InvalidParameterException("Fill host: " + host + ", port: " + port + ", acsUsername: "
                + acsUsername + ", and acsPassword: " + acsPassword + ".");
    }

    String realm = "NBBS_API_Realm";

    AuthScope authscope = new AuthScope(host, Integer.parseInt(port), realm);

    // client.getState().setCredentials(realm, host,
    // new UsernamePasswordCredentials(acsUsername, acsPassword));

    client.getState().setCredentials(authscope, new UsernamePasswordCredentials(acsUsername, acsPassword));

    PostMethod post = null;

    // -----
    // ----- Execution de la capability : changeDUStateUpdate
    // -----

    post = new PostMethod(address + "capability/execute");

    post.addParameter(new NameValuePair("deviceId", "10003"));
    post.addParameter(new NameValuePair("timeoutMs", "60000"));
    post.addParameter(new NameValuePair("capability", "\"changeDUStateUpdate\""));

    // UUID: string
    // Version: string
    // URL: string
    // Username: string
    // Password: string

    JSONObject object = new JSONObject();
    object.put("UUID", "45");
    object.put("Version", "1.0.0");
    object.put("URL", "http://127.0.0.1:8085/a/org.apache.felix.http.jetty-2.2.0.jar");
    object.put("Username", "Username_value");
    object.put("Password", "Password_value");
    post.addParameter(new NameValuePair("input", object.toString()));

    post.setDoAuthentication(true);

    // post.addParameter(new NameValuePair("deviceId", "60001"));

    // -----
    // ----- Partie commune : Execution du post
    // -----

    try {
        int status = client.executeMethod(post);
        System.out.println("status: " + status);
        String resp = post.getResponseBodyAsString();
        System.out.println("resp: " + resp);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        // release any connection resources used by the method
        post.releaseConnection();
    }
}

From source file:com.github.jryans.websockettap.WebSocketTap.java

public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        System.out.println("Usage: WebSocketTap serverPort clientPort");
        System.exit(1);//from   www . j  a va 2  s.  co  m
    }

    new WebSocketTap(Integer.parseInt(args[0]), Integer.parseInt(args[1])).startServer();
}

From source file:msuresh.raftdistdb.AtomixDB.java

/**
 * Main Method which runs a Apache CLI which takes 3 different options for the 3 operations <br>
 * @param args <br>/*from   w  w  w.j  a v a  2  s . c  o m*/
 * Options : <br>
 * -setup numberOfReplicas numberOfPartitions -- which sets the system given thenumber of partitions number of replicas per partition<br>
 * -set key Value -- adds a key value pair to the DB<br>
 * -get key -- returns a value for the key if it exists<br>
 * @throws InterruptedException 
 */
public static void main(String[] args) throws InterruptedException, ExecutionException, FileNotFoundException {
    Options options = new Options();
    Option opt = new Option("setup", true, "Sets up the replica that run the Raft Consensus Algorithm.");
    opt.setArgs(3);
    options.addOption(opt);
    opt = new Option("set", true, " Add a key-value pair into the Distributed Database.");
    opt.setArgs(3);
    options.addOption(opt);
    opt = new Option("get", true, "Given a key gets the value from the DB");
    opt.setArgs(2);
    options.addOption(opt);
    opt = new Option("clean", false, "Cleans the state information.");
    options.addOption(opt);
    opt = new Option("test", true, "Cleans the state information.");
    opt.setArgs(2);
    options.addOption(opt);
    try {
        CommandLineParser parser = new BasicParser();
        CommandLine line = null;
        line = parser.parse(options, args);
        if (line.hasOption("setup")) {
            String[] vals = line.getOptionValues("setup");
            System.out.println(vals[0]);
            RaftCluster.createCluster(vals[0], Integer.parseInt(vals[1]), Integer.parseInt(vals[2]));
        } else if (line.hasOption("set")) {
            String[] vals = line.getOptionValues("set");
            addKey(vals[0], vals[1], vals[2]);
        } else if (line.hasOption("get")) {
            String[] vals = line.getOptionValues("get");
            getKey(vals[0], vals[1]);
        } else if (line.hasOption("clean")) {
            cleanState();
        } else if (line.hasOption("test")) {
            String[] vals = line.getOptionValues("test");
            TestAtomix.createCluster(vals[0], Integer.parseInt(vals[1]));
        }
    } catch (ParseException exp) {
        System.out.println("Unexpected exception:" + exp.getMessage());
    }
}