List of usage examples for java.lang Integer parseInt
public static int parseInt(String s) throws NumberFormatException
From source file:PrintServiceTest.java
public static void main(String[] args) { DocFlavor flavor = DocFlavor.URL.GIF; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null); if (args.length == 0) { if (services.length == 0) System.out.println("No printer for flavor " + flavor); else {//w w w . j ava2s . com System.out.println("Specify a file of flavor " + flavor + "\nand optionally the number of the desired printer."); for (int i = 0; i < services.length; i++) System.out.println((i + 1) + ": " + services[i].getName()); } System.exit(0); } String fileName = args[0]; int p = 1; if (args.length > 1) p = Integer.parseInt(args[1]); try { if (fileName == null) return; FileInputStream in = new FileInputStream(fileName); Doc doc = new SimpleDoc(in, flavor, null); DocPrintJob job = services[p - 1].createPrintJob(); job.print(doc, null); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (PrintException e) { e.printStackTrace(); } }
From source file:fr.inria.zenith.randomWalk.RandomWalkTsG.java
/** * @param args the command line arguments * @throws java.io.IOException/*from w w w .java2s . co m*/ */ public static void main(String[] args) throws IOException, Exception { if (args.length < 2) { System.err.println("Usage: randomWalkTimeSeriesGenerator <FileName> <TimeSeriesNbr> <TimeSeriesSize>"); System.exit(1); } CSVWriter writer = new CSVWriter(new FileWriter(args[0] + "_" + args[1] + "_" + args[2] + ".csv"), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER); for (int i = 1; i < Integer.parseInt(args[1]) + 2; i++) { String[] ts = randomWalk(Integer.parseInt(args[2]) + 1); ts[0] = Integer.toString(i); writer.writeNext(ts); writer.flushQuietly(); } writer.close(); }
From source file:com.alibaba.simpleimage.ScaleSpeedTest.java
public static void main(String[] args) throws Exception { String method = "CSubSample"; String imgName = "large"; int times = 1000; float scale = 0.5f; String imgDir = "/src/test/resources/conf.test/simpleimage/scale"; File rootDir = null;/* w w w . ja va 2 s .c om*/ if (args.length > 0) { rootDir = new File(args[0].trim() + imgDir); } if (args.length > 1) { method = args[1]; } if (args.length > 2) { imgName = args[2]; } if (args.length > 3) { scale = Float.parseFloat(args[3]); } if (args.length > 4) { times = Integer.parseInt(args[4]); } ScaleSpeedTest instance = new ScaleSpeedTest(); if ("JSubSample".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new JSubSampleScaler(), times, scale); } else if ("CSubSample".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new CSubSampleScaler(), times, scale); } else if ("Bicurbe".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new BicurbeScaler(), times, scale); } else if ("Bicurbe2".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new Bicube2Scaler(), times, scale); } else if ("lanczos".equalsIgnoreCase(method)) { instance.doScale(rootDir, imgName, instance.new LanczosScaler(), times, scale); } else { throw new IllegalArgumentException("Unknown alg"); } }
From source file:com.weibo.motan.demo.client.DemoRpcClient.java
public static void main(String[] args) throws Exception { final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics(); int threads = Integer.parseInt(args[0]); DubboBenchmark.BenchmarkMessage msg = prepareArgs(); final byte[] msgBytes = msg.toByteArray(); int n = 1000000; final CountDownLatch latch = new CountDownLatch(n); ExecutorService es = Executors.newFixedThreadPool(threads); final AtomicInteger trans = new AtomicInteger(0); final AtomicInteger transOK = new AtomicInteger(0); ApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "classpath:motan_demo_client.xml" }); MotanDemoService service = (MotanDemoService) ctx.getBean("motanDemoReferer"); long start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { es.submit(() -> {//ww w .j a v a2 s .c o m try { long t = System.currentTimeMillis(); DubboBenchmark.BenchmarkMessage m = testSay(service, msgBytes); t = System.currentTimeMillis() - t; stats.addValue(t); trans.incrementAndGet(); if (m != null && m.getField1().equals("OK")) { transOK.incrementAndGet(); } } finally { latch.countDown(); } }); } latch.await(); start = System.currentTimeMillis() - start; System.out.printf("sent requests : %d\n", n); System.out.printf("received requests : %d\n", trans.get()); System.out.printf("received requests_OK : %d\n", transOK.get()); System.out.printf("throughput (TPS) : %d\n", n * 1000 / start); System.out.printf("mean: %f\n", stats.getMean()); System.out.printf("median: %f\n", stats.getPercentile(50)); System.out.printf("max: %f\n", stats.getMax()); System.out.printf("min: %f\n", stats.getMin()); System.out.printf("99P: %f\n", stats.getPercentile(90)); }
From source file:com.uber.tchannel.ping.PingServer.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("p", "port", true, "Server Port to connect to"); options.addOption("?", "help", false, "Usage"); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("?")) { formatter.printHelp("PingClient", options, true); return;// ww w . j a v a 2s . c o m } int port = Integer.parseInt(cmd.getOptionValue("p", "8888")); System.out.println(String.format("Starting server on port: %d", port)); new PingServer(port).run(); System.out.println("Stopping server..."); }
From source file:client.ComputePi.java
public static void main(String args[]) { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }//w w w . j a v a 2s . c o m try { String name = "Compute"; Registry registry = LocateRegistry.getRegistry(args[0]); Compute comp = (Compute) registry.lookup(name); Pi task = new Pi(Integer.parseInt(args[1])); BigDecimal pi = comp.executeTask(task); System.out.println(pi); } catch (Exception e) { System.err.println("ComputePi exception:"); e.printStackTrace(); } }
From source file:com.gargoylesoftware.htmlunit.general.HostExtractor.java
/** * The entry point.//from w w w .j ava 2 s . co m * @param args optional proxy hostname and port * @throws Exception if an error occurs */ public static void main(final String[] args) throws Exception { final Set<String> set = new HashSet<>(); try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { if (args.length > 1) { final ProxyConfig proxyConfig = new ProxyConfig(args[0], Integer.parseInt(args[1])); proxyConfig.addHostsToProxyBypass("localhost"); webClient.getOptions().setProxyConfig(proxyConfig); } fillMDNWebAPI(webClient, set); fillMDNJavaScriptGlobalObjects(webClient, set); final String testRoot = "src/test/java/"; ensure(new File(testRoot + HostClassNameTest.class.getName().replace('.', '/') + ".java"), set); } }
From source file:hyperheuristics.main.comparisons.CompareHypervolumes.java
public static void main(String[] args) throws IOException, InterruptedException { int[] numberOfObjectivesArray = new int[] { 2, 4 }; String[] problems;/*from www .j a v a 2 s . c om*/ if (args.length == 0) { problems = new String[] { "OO_MyBatis", "OA_AJHsqldb", "OA_AJHotDraw", "OO_BCEL", "OO_JHotDraw", "OA_HealthWatcher", // "OA_TollSystems", "OO_JBoss" }; } else { EXECUTIONS = Integer.parseInt(args[0]); numberOfObjectivesArray = new int[] { Integer.parseInt(args[4]) }; problems = Arrays.copyOfRange(args, 5, args.length); } String[] heuristicFunctions = new String[] { LowLevelHeuristic.CHOICE_FUNCTION, LowLevelHeuristic.MULTI_ARMED_BANDIT, // LowLevelHeuristic.RANDOM }; String[] algorithms = new String[] { "NSGA-II", "SPEA2" }; for (int numberOfObjectives : numberOfObjectivesArray) { // hypervolumeComparison(problems, heuristicFunctions, numberOfObjectives, algorithms); // hypervolumeHyperheuristicsComparison(problems, heuristicFunctions, numberOfObjectives,); // hypervolumeByGeneration(problems, heuristicFunctions, numberOfObjectives); generateTables(problems, heuristicFunctions, numberOfObjectives, algorithms); } }
From source file:com.alibaba.simpleimage.PressureTester.java
public static void main(String[] args) throws Exception { int threads = 1; long tasks = Long.MAX_VALUE; String rootDir = ""; if (args.length >= 1) { rootDir = args[0];//from ww w . jav a 2s.c o m } if (args.length >= 2) { threads = Integer.parseInt(args[1]); } if (args.length >= 3) { tasks = Long.parseLong(args[2]); } if ("null".equalsIgnoreCase(rootDir)) { rootDir = null; } System.out.println("task begin"); new PressureTester(threads, tasks, rootDir).run(); System.out.println("task end"); }
From source file:MonthsInYear.java
public static void main(String[] args) { int year = 0; if (args.length <= 0) { System.out.printf("Usage: MonthsInYear <year>%n"); throw new IllegalArgumentException(); }//from ww w .ja v a2 s . c o m try { year = Integer.parseInt(args[0]); } catch (NumberFormatException nexc) { System.out.printf("%s is not a properly formatted number.%n", args[0]); throw nexc; // Rethrow the exception. } try { Year test = Year.of(year); } catch (DateTimeException exc) { System.out.printf("%d is not a valid year.%n", year); throw exc; // Rethrow the exception. } System.out.printf("For the year %d:%n", year); for (Month month : Month.values()) { YearMonth ym = YearMonth.of(year, month); System.out.printf("%s: %d days%n", month, ym.lengthOfMonth()); } }