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:io.confluent.kafkarest.tools.ConsumerPerformance.java

public static void main(String[] args) throws Exception {
    if (args.length < 4) {
        System.out.println("Usage: java " + ConsumerPerformance.class.getName() + " rest_url topic_name "
                + "num_records target_records_sec");
        System.exit(1);//from w w  w  . jav a2s .  co m
    }

    String baseUrl = args[0];
    String topic = args[1];
    int numRecords = Integer.parseInt(args[2]);
    int throughput = Integer.parseInt(args[3]);

    ConsumerPerformance perf = new ConsumerPerformance(baseUrl, topic, numRecords, throughput);
    // We need an approximate # of iterations per second, but we don't know how many records per
    // request we'll receive so we don't know how many iterations per second we need to hit the
    // target rate. Get an approximate value using the default max # of records per request the
    // server will return.
    perf.run();
    perf.close();
}

From source file:org.jboss.teiid.quickstart.PortfolioHTTPClient.java

public static void main(String[] args) throws URISyntaxException, UnsupportedEncodingException {

    String hostname = "localhost";
    int port = 8080;
    String username = "restUser";
    String password = "password1!";
    if (args.length == 4) {
        hostname = args[0];//www .  ja  v a2 s  .  co  m
        port = Integer.parseInt(args[1]);
        username = args[2];
        password = args[3];
    }

    HttpClientBuilder builder = HttpClientBuilder.create();
    HttpHost targetHost = new HttpHost(hostname, port);
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    AuthScope scope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    credsProvider.setCredentials(scope, credentials);
    builder.setDefaultCredentialsProvider(credsProvider);
    HttpClient client = builder.build();

    execute(client, new HttpGet("http://localhost:8080/PortfolioRest_1/Rest/foo/1"));
    execute(client, new HttpGet("http://localhost:8080/PortfolioRest_1/Rest/getAllStocks"));
    execute(client, new HttpGet("http://localhost:8080/PortfolioRest_1/Rest/getAllStockById/1007"));
    execute(client, new HttpGet("http://localhost:8080/PortfolioRest_1/Rest/getAllStockBySymbol/IBM"));

}

From source file:com.github.xbn.examples.lang.non_xbn.VerifyUserInputIsANumberWithIsNumber.java

public static final void main(String[] ignored) {

    int num = -1;
    boolean isNum = false;

    do {//from w  ww.  jav  a2s .c o  m
        System.out.print("Number please: ");
        String strInput = (new Scanner(System.in)).next();
        if (!NumberUtils.isNumber(strInput)) {
            System.out.println(strInput + " is not a number. Try again.");
        } else {
            //Safe to convert
            num = Integer.parseInt(strInput);
            isNum = true;
        }
    } while (!isNum);

    System.out.println("Number: " + num);
}

From source file:edu.snu.leader.discrete.simulator.Main.java

public static void main(String[] args) {
    System.setProperty("sim-properties", "cfg/sim/discrete/sim-properties.parameters");

    _simulationProperties = MiscUtils.loadProperties("sim-properties");

    String stringShouldRunGraphical = _simulationProperties.getProperty("run-graphical");
    Validate.notEmpty(stringShouldRunGraphical, "Run graphical option required");
    shouldRunGraphical = Boolean.parseBoolean(stringShouldRunGraphical);

    String stringTotalRuns = _simulationProperties.getProperty("run-count");
    Validate.notEmpty(stringTotalRuns, "Run count required");
    totalRuns = Integer.parseInt(stringTotalRuns);

    if (!shouldRunGraphical) {
        // run just text
        for (int run = 1; run <= totalRuns; run++) {
            System.out.println("Run " + run);
            System.out.println();

            // create and initialize simulator
            Simulator simulator = new Simulator(run);
            _simulationProperties.put("current-run", String.valueOf(run));
            simulator.initialize(_simulationProperties);
            // run it
            simulator.execute();/*from  w  w  w  .j  a  va  2s.c om*/
        }
    } else {
        // run graphical
        DebugLocationsStructure db = new DebugLocationsStructure("Conflict Simulation", 800, 600, 60);
        _simulationProperties.put("current-run", String.valueOf(1));
        db.initialize(_simulationProperties, 1);
        db.run();
    }
}

From source file:org.eclipse.swt.snippets.Snippet340.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 340");
    shell.setLayout(new GridLayout());
    shell.setText("Description Relation Example");

    // (works with either a Label or a READ_ONLY Text)
    final Label liveLabel = new Label(shell, SWT.BORDER | SWT.READ_ONLY);
    //   final Text liveLabel = new Text(shell, SWT.BORDER | SWT.READ_ONLY);
    liveLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    liveLabel.setText("Live region messages go here");

    new Label(shell, SWT.NONE).setText("Type an integer from 1 to 4:");

    final Text textField = new Text(shell, SWT.SINGLE | SWT.BORDER);
    textField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    textField.addModifyListener(e -> {
        String textValue = textField.getText();
        String message = textValue + " is not valid input.";
        try {/*  ww w.  j  a v  a2s . c om*/
            int value = Integer.parseInt(textValue);
            switch (value) {
            case 1:
                message = "One for the money,";
                break;
            case 2:
                message = "Two for the show,";
                break;
            case 3:
                message = "Three to get ready,";
                break;
            case 4:
                message = "And four to go!";
                break;
            }
        } catch (NumberFormatException ex) {
        }
        liveLabel.setText(message);
        textField.getAccessible().sendEvent(ACC.EVENT_DESCRIPTION_CHANGED, null);
        textField.setSelection(0, textField.getCharCount());
    });
    textField.getAccessible().addRelation(ACC.RELATION_DESCRIBED_BY, liveLabel.getAccessible());
    liveLabel.getAccessible().addRelation(ACC.RELATION_DESCRIPTION_FOR, textField.getAccessible());
    textField.getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getDescription(AccessibleEvent event) {
            event.result = liveLabel.getText();
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:PlayerPiano.java

public static void main(String[] args) throws MidiUnavailableException, InvalidMidiDataException, IOException {
    int instrument = 0;
    int tempo = 120;
    String filename = null;/*ww  w.  ja  v a 2 s .  c o m*/

    // Parse the options
    // -i <instrument number> default 0, a piano. Allowed values: 0-127
    // -t <beats per minute> default tempo is 120 quarter notes per minute
    // -o <filename> save to a midi file instead of playing
    int a = 0;
    while (a < args.length) {
        if (args[a].equals("-i")) {
            instrument = Integer.parseInt(args[a + 1]);
            a += 2;
        } else if (args[a].equals("-t")) {
            tempo = Integer.parseInt(args[a + 1]);
            a += 2;
        } else if (args[a].equals("-o")) {
            filename = args[a + 1];
            a += 2;
        } else
            break;
    }

    char[] notes = args[a].toCharArray();

    // 16 ticks per quarter note.
    Sequence sequence = new Sequence(Sequence.PPQ, 16);

    // Add the specified notes to the track
    addTrack(sequence, instrument, tempo, notes);

    if (filename == null) { // no filename, so play the notes
        // Set up the Sequencer and Synthesizer objects
        Sequencer sequencer = MidiSystem.getSequencer();
        sequencer.open();
        Synthesizer synthesizer = MidiSystem.getSynthesizer();
        synthesizer.open();
        sequencer.getTransmitter().setReceiver(synthesizer.getReceiver());

        // Specify the sequence to play, and the tempo to play it at
        sequencer.setSequence(sequence);
        sequencer.setTempoInBPM(tempo);

        // Let us know when it is done playing
        sequencer.addMetaEventListener(new MetaEventListener() {
            public void meta(MetaMessage m) {
                // A message of this type is automatically sent
                // when we reach the end of the track
                if (m.getType() == END_OF_TRACK)
                    System.exit(0);
            }
        });
        // And start playing now.
        sequencer.start();
    } else { // A file name was specified, so save the notes
        int[] allowedTypes = MidiSystem.getMidiFileTypes(sequence);
        if (allowedTypes.length == 0) {
            System.err.println("No supported MIDI file types.");
        } else {
            MidiSystem.write(sequence, allowedTypes[0], new File(filename));
            System.exit(0);
        }
    }
}

From source file:com.moreopen.config.center.ConfigCenterLauncher.java

public static void main(String[] args) throws Exception {
    final String PROFILE_NAME = "/app.properties";
    Properties properties = PropertiesLoaderUtils
            .loadProperties(new UrlResource(ConfigCenterLauncher.class.getResource(PROFILE_NAME)));
    int port = Integer.parseInt(properties.getProperty("webserver.port"));
    if (port == 0) {
        logger.error("property: config.webserver.port not found, please check " + PROFILE_NAME);
        return;/*from w w w  . j a  va  2  s .co m*/
    }
    // launch the monitor console server
    new ConfigCenterLauncher(port).run();
    server.join();
}

From source file:ThreadDemo.java

/**
 * This main method creates and starts two threads in addition to the initial
 * thread that the interpreter creates to invoke the main() method.
 *///from   w  w  w  . j a v a  2s.c  om
public static void main(String[] args) {
    // Create the first thread: an instance of this class. Its body is
    // the run() method above
    ThreadDemo thread1 = new ThreadDemo();

    // Create the second thread by passing a Runnable object to the
    // Thread() construtor. The body of this thread is the run() method
    // of the anonymous Runnable object below.
    Thread thread2 = new Thread(new Runnable() {
        public void run() {
            for (int i = 0; i < 5; i++)
                compute();
        }
    });

    // Set the priorities of these two threads, if any are specified
    if (args.length >= 1)
        thread1.setPriority(Integer.parseInt(args[0]));
    if (args.length >= 2)
        thread2.setPriority(Integer.parseInt(args[1]));

    // Start the two threads running
    thread1.start();
    thread2.start();

    // This main() method is run by the initial thread created by the
    // Java interpreter. Now that thread does some stuff, too.
    for (int i = 0; i < 5; i++)
        compute();

    // We could wait for the threads to stop running with these lines
    // But they aren't necessary here, so we don't bother.
    // try {
    // thread1.join();
    // thread2.join();
    // } catch (InterruptedException e) {}

    // The Java VM exits only when the main() method returns, and when all
    // threads stop running (except for daemon threads--see setDaemon()).
}

From source file:com.ifeng.sorter.NginxApp.java

public static void main(String[] args) {

    String input = "src/test/resources/data/nginx_report.txt";

    PrintWriter pw = null;//w  ww  . jav  a 2 s .c  o  m

    Map<String, List<LogBean>> resultMap = new HashMap<String, List<LogBean>>();
    List<String> ips = new ArrayList<String>();

    try {
        List<String> lines = FileUtils.readLines(new File(input));
        List<LogBean> items = new ArrayList<LogBean>();

        for (String line : lines) {
            String[] values = line.split("\t");

            if (values != null && values.length == 3) {// ip total seria
                try {
                    String ip = values[0].trim();
                    String total = values[1].trim();
                    String seria = values[2].trim();

                    LogBean bean = new LogBean(ip, Integer.parseInt(total), seria);

                    items.add(bean);

                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        }

        Collections.sort(items);

        for (LogBean bean : items) {
            String key = bean.getIp();

            if (resultMap.containsKey(key)) {
                resultMap.get(key).add(bean);
            } else {
                List<LogBean> keyList = new ArrayList<LogBean>();
                keyList.add(bean);
                resultMap.put(key, keyList);

                ips.add(key);
            }
        }

        pw = new PrintWriter("src/test/resources/output/result.txt", "UTF-8");

        for (String ip : ips) {
            List<LogBean> list = resultMap.get(ip);

            for (LogBean bean : list) {
                pw.append(bean.toString());
                pw.println();
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        pw.flush();
        pw.close();
    }
}

From source file:hu.sztaki.incremental.ml.streaming.imsr.IMSR.java

public static void main(String[] args) throws Exception {

    // set up the execution environment
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

    // get arguments
    String fileName = "src/test/resources/1.csv";
    int batchSize = 5;
    if (args.length > 0) {
        fileName = args[0];/*from w  w  w.j av  a  2 s .  co m*/
        if (args.length > 1) {
            batchSize = Integer.parseInt(args[1]);
        }
    }

    // get input data
    DataStream<Tuple2<double[][], double[][]>> stream = env
            .addSource(new MatrixVectorPairSource(fileName, batchSize), 1);

    MatrixSink sink = new MatrixSink();

    stream.map(new MatrixMapper()).reduce(new MatrixSumReducer()).addSink(sink);

    // execute program
    env.execute("Streaming Linear Regression (IMSR)");
}