List of usage examples for java.lang Integer parseInt
public static int parseInt(String s) throws NumberFormatException
From source file:edu.asu.ca.kaushik.algorithms.twostage.TwoStageDensity.java
/** * @param args/* w w w.j a v a2s .c o m*/ * @throws IOException */ public static void main(String[] args) throws IOException { int t = 0, k1 = 0, k2 = 0, v = 0, times = 0, f = 0, s = 0; if (args.length == 7) { t = Integer.parseInt(args[0]); v = Integer.parseInt(args[1]); k1 = Integer.parseInt(args[2]); k2 = Integer.parseInt(args[3]); times = Integer.parseInt(args[4]); f = Integer.parseInt(args[5]); s = Integer.parseInt(args[6]); } else { System.err.println("Need seven arguments- t, v, kStart, kEnd, times, firstStage and slack percent"); System.exit(1); } List<CAGenAlgo> algoList = new ArrayList<CAGenAlgo>(); algoList.add(new TwoStageDensity(times, f, s)); OutputFormatter formatter = new TableOutputFormatter("data\\out\\tables\\two-stage", "two-stage-density-" + times + "-times"); Runner runner = new Runner(formatter); runner.setParam(t, v, k1, k2); runner.setAlgos(algoList); runner.run(); }
From source file:monitor.java
public static void main(String argv[]) { if (argv.length != 5) { System.out.println("Usage: monitor <host> <user> <password> <mbox> <freq>"); System.exit(1);//from w ww. j a v a 2 s. com } System.out.println("\nTesting monitor\n"); try { Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); // session.setDebug(true); // Get a Store object Store store = session.getStore("imap"); // Connect store.connect(argv[0], argv[1], argv[2]); // Open a Folder Folder folder = store.getFolder(argv[3]); if (folder == null || !folder.exists()) { System.out.println("Invalid folder"); System.exit(1); } folder.open(Folder.READ_WRITE); // Add messageCountListener to listen for new messages folder.addMessageCountListener(new MessageCountAdapter() { public void messagesAdded(MessageCountEvent ev) { Message[] msgs = ev.getMessages(); System.out.println("Got " + msgs.length + " new messages"); // Just dump out the new messages for (int i = 0; i < msgs.length; i++) { try { System.out.println("-----"); System.out.println("Message " + msgs[i].getMessageNumber() + ":"); msgs[i].writeTo(System.out); } catch (IOException ioex) { ioex.printStackTrace(); } catch (MessagingException mex) { mex.printStackTrace(); } } } }); // Check mail once in "freq" MILLIseconds int freq = Integer.parseInt(argv[4]); boolean supportsIdle = false; try { if (folder instanceof IMAPFolder) { IMAPFolder f = (IMAPFolder) folder; f.idle(); supportsIdle = true; } } catch (FolderClosedException fex) { throw fex; } catch (MessagingException mex) { supportsIdle = false; } for (;;) { if (supportsIdle && folder instanceof IMAPFolder) { IMAPFolder f = (IMAPFolder) folder; f.idle(); System.out.println("IDLE done"); } else { Thread.sleep(freq); // sleep for freq milliseconds // This is to force the IMAP server to send us // EXISTS notifications. folder.getMessageCount(); } } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:cz.muni.fi.crocs.JeeTool.Main.java
/** * @param args the command line arguments *//*from ww w . java 2 s . c om*/ public static void main(String[] args) { System.out.println("JeeTool \n"); checkDependencies(); Options options = OptionsMain.createOptions(); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException ex) { System.err.println("cannot parse parameters"); OptionsMain.printHelp(options); System.err.println(ex.toString()); return; } boolean silent = cmd.hasOption("s"); boolean verbose = cmd.hasOption("v"); //help if (cmd.hasOption("h")) { OptionsMain.printHelp(options); return; } String filepath; //path to config list of nodes if (cmd.hasOption("a")) { filepath = cmd.getOptionValue("a"); } else { filepath = "/opt/motePaths.txt"; } //create motelist MoteList moteList = new MoteList(filepath); if (verbose) { moteList.setVerbose(); } if (silent) { moteList.setSilent(); } if (verbose) { System.out.println("reading motelist from file " + filepath); } if (cmd.hasOption("i")) { List<Integer> ids = new ArrayList<Integer>(); String arg = cmd.getOptionValue("i"); String[] IdArgs = arg.split(","); for (String s : IdArgs) { if (s.contains("-")) { int start = Integer.parseInt(s.substring(0, s.indexOf("-"))); int end = Integer.parseInt(s.substring(s.indexOf("-") + 1, s.length())); for (int i = start; i <= end; i++) { ids.add(i); } } else { ids.add(Integer.parseInt(s)); } } moteList.setIds(ids); } moteList.readFile(); if (cmd.hasOption("d")) { //only detect nodes return; } //if make if (cmd.hasOption("m") || cmd.hasOption("c") || cmd.hasOption("u")) { UploadMain upload = new UploadMain(moteList, cmd); upload.runMake(); } }
From source file:mover.java
public static void main(String argv[]) { int start = 1; int end = -1; int optind;/*from w w w . j av a 2 s .c o m*/ for (optind = 0; optind < argv.length; optind++) { if (argv[optind].equals("-T")) { // protocol protocol = argv[++optind]; } else if (argv[optind].equals("-H")) { // host host = argv[++optind]; } else if (argv[optind].equals("-U")) { // user user = argv[++optind]; } else if (argv[optind].equals("-P")) { // password password = argv[++optind]; } else if (argv[optind].equals("-L")) { url = argv[++optind]; } else if (argv[optind].equals("-s")) { // Source mbox src = argv[++optind]; } else if (argv[optind].equals("-d")) { // Destination mbox dest = argv[++optind]; } else if (argv[optind].equals("-x")) { // Expunge ? expunge = true; } else if (argv[optind].equals("--")) { optind++; break; } else if (argv[optind].startsWith("-")) { System.out.println("Usage: mover [-T protocol] [-H host] [-U user] [-P password] [-L url] [-v]"); System.out.println("\t[-s source mbox] [-d destination mbox] [-x] [msgnum1] [msgnum2]"); System.out.println("\t The -x option => EXPUNGE deleted messages"); System.out.println("\t msgnum1 => start of message-range; msgnum2 => end of message-range"); System.exit(1); } else { break; } } if (optind < argv.length) start = Integer.parseInt(argv[optind++]); // start msg if (optind < argv.length) end = Integer.parseInt(argv[optind++]); // end msg try { // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); // Get a Store object Store store = null; if (url != null) { URLName urln = new URLName(url); store = session.getStore(urln); store.connect(); } else { if (protocol != null) store = session.getStore(protocol); else store = session.getStore(); // Connect if (host != null || user != null || password != null) store.connect(host, user, password); else store.connect(); } // Open source Folder Folder folder = store.getFolder(src); if (folder == null || !folder.exists()) { System.out.println("Invalid folder: " + src); System.exit(1); } folder.open(Folder.READ_WRITE); int count = folder.getMessageCount(); if (count == 0) { // No messages in the source folder System.out.println(folder.getName() + " is empty"); // Close folder, store and return folder.close(false); store.close(); return; } // Open destination folder, create if reqd Folder dfolder = store.getFolder(dest); if (!dfolder.exists()) dfolder.create(Folder.HOLDS_MESSAGES); if (end == -1) end = count; // Get the message objects to copy Message[] msgs = folder.getMessages(start, end); System.out.println("Moving " + msgs.length + " messages"); if (msgs.length != 0) { folder.copyMessages(msgs, dfolder); folder.setFlags(msgs, new Flags(Flags.Flag.DELETED), true); // Dump out the Flags of the moved messages, to insure that // all got deleted for (int i = 0; i < msgs.length; i++) { if (!msgs[i].isSet(Flags.Flag.DELETED)) System.out.println("Message # " + msgs[i] + " not deleted"); } } // Close folders and store folder.close(expunge); store.close(); } catch (MessagingException mex) { Exception ex = mex; do { System.out.println(ex.getMessage()); if (ex instanceof MessagingException) ex = ((MessagingException) ex).getNextException(); else ex = null; } while (ex != null); } }
From source file:gpframework.RunExperiment.java
/** * Application's entry point.//from www . j a va 2 s .c o m * * @param args * @throws ParseException * @throws ParameterException */ public static void main(String[] args) throws ParseException, ParameterException { // Failsafe parameters if (args.length == 0) { args = new String[] { "-f", "LasSortednessFunction", "-n", "5", "-ff", "JoinFactory", "-tf", "SortingElementFactory", "-pf", "SortingProgramFactory", "-s", "SMOGPSelection", "-a", "SMOGP", "-t", "50", "-e", "1000000000", "-mf", "SingleMutationFactory", "-d", "-bn", "other" }; } // Create options Options options = new Options(); setupOptions(options); // Read options from the command line CommandLineParser parser = new PosixParser(); CommandLine cmd; // Print help if parameter requirements are not met try { cmd = parser.parse(options, args); } // If some parameters are missing, print help catch (MissingOptionException e) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar GPFramework \n", options); System.out.println(); System.out.println("Missing parameters: " + e.getMissingOptions()); return; } // Re-initialize PRNG long seed = System.currentTimeMillis(); Utils.random = new Random(seed); // Set the problem size int problemSize = Integer.parseInt(cmd.getOptionValue("n")); // Set debug mode and cluster mode Utils.debug = cmd.hasOption("d"); RunExperiment.cluster = cmd.hasOption("c"); // Initialize fitness function and some factories FitnessFunction fitnessFunction = fromName(cmd.getOptionValue("f"), problemSize); MutationFactory mutationFactory = fromName(cmd.getOptionValue("mf")); Selection selectionCriterion = fromName(cmd.getOptionValue("s")); FunctionFactory functionFactory = fromName(cmd.getOptionValue("ff")); TerminalFactory terminalFactory = fromName(cmd.getOptionValue("tf"), problemSize); ProgramFactory programFactory = fromName(cmd.getOptionValue("pf"), functionFactory, terminalFactory); // Initialize algorithm Algorithm algorithm = fromName(cmd.getOptionValue("a"), mutationFactory, selectionCriterion); algorithm.setParameter("evaluationsBudget", cmd.getOptionValue("e")); algorithm.setParameter("timeBudget", cmd.getOptionValue("t")); // Initialize problem Problem problem = new Problem(programFactory, fitnessFunction); Program solution = algorithm.solve(problem); Utils.debug("Population results: "); Utils.debug(algorithm.getPopulation().toString()); Utils.debug(algorithm.getPopulation().parse()); Map<String, Object> entry = new HashMap<String, Object>(); // Copy algorithm setup for (Object o : options.getRequiredOptions()) { Option option = options.getOption(o.toString()); entry.put(option.getLongOpt(), cmd.getOptionValue(option.getOpt())); } entry.put("seed", seed); // Copy results entry.put("bestProgram", solution.toString()); entry.put("bestSolution", fitnessFunction.normalize(solution)); // Copy all statistics entry.putAll(algorithm.getStatistics()); Utils.debug("Maximum encountered population size: " + algorithm.getStatistics().get("maxPopulationSizeToCompleteFront")); Utils.debug("Maximum encountered tree size: " + algorithm.getStatistics().get("maxProgramComplexityToCompleteFront")); Utils.debug("Solution complexity: " + solution.complexity() + "/" + (2 * problemSize - 1)); }
From source file:fr.tpt.s3.mcdag.generator.MainGenerator.java
/** * Main method for the generator: it launches a given number of threads with the parameters * given/*from w w w . jav a2 s. co m*/ * @param args */ public static void main(String[] args) { /* ============================ Command line ================= */ Options options = new Options(); Option o_hi = new Option("mu", "max_utilization", true, "Upper bound utilization"); o_hi.setRequired(true); options.addOption(o_hi); Option o_tasks = new Option("nt", "nb_tasks", true, "Number of tasks for the system"); o_tasks.setRequired(true); options.addOption(o_tasks); Option o_eprob = new Option("e", "eprobability", true, "Probability of edges"); o_eprob.setRequired(true); options.addOption(o_eprob); Option o_levels = new Option("l", "levels", true, "Number of criticality levels"); o_levels.setRequired(true); options.addOption(o_levels); Option o_para = new Option("p", "parallelism", true, "Max parallelism for the DAGs"); o_para.setRequired(true); options.addOption(o_para); Option o_nbdags = new Option("nd", "num_dags", true, "Number of DAGs"); o_nbdags.setRequired(true); options.addOption(o_nbdags); Option o_nbfiles = new Option("nf", "num_files", true, "Number of files"); o_nbfiles.setRequired(true); options.addOption(o_nbfiles); Option o_rfactor = new Option("rf", "reduc_factor", true, "Reduction factor for criticality modes"); o_rfactor.setRequired(false); options.addOption(o_rfactor); Option o_out = new Option("o", "output", true, "Output file for the DAG"); o_out.setRequired(true); options.addOption(o_out); Option graphOpt = new Option("g", "graphviz", false, "Generate a graphviz DOT file"); graphOpt.setRequired(false); options.addOption(graphOpt); Option debugOpt = new Option("d", "debug", false, "Enabling debug"); debugOpt.setRequired(false); options.addOption(debugOpt); Option jobsOpt = new Option("j", "jobs", true, "Number of jobs"); jobsOpt.setRequired(false); options.addOption(jobsOpt); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("DAG Generator", options); System.exit(1); return; } double maxU = Double.parseDouble(cmd.getOptionValue("max_utilization")); int edgeProb = Integer.parseInt(cmd.getOptionValue("eprobability")); int levels = Integer.parseInt(cmd.getOptionValue("levels")); int nbDags = Integer.parseInt(cmd.getOptionValue("num_dags")); int nbFiles = Integer.parseInt(cmd.getOptionValue("num_files")); int para = Integer.parseInt(cmd.getOptionValue("parallelism")); int nbTasks = Integer.parseInt(cmd.getOptionValue("nb_tasks")); boolean graph = cmd.hasOption("graphviz"); boolean debug = cmd.hasOption("debug"); String output = cmd.getOptionValue("output"); int nbJobs = 1; if (cmd.hasOption("jobs")) nbJobs = Integer.parseInt(cmd.getOptionValue("jobs")); double rfactor = 2.0; if (cmd.hasOption("reduc_factor")) rfactor = Double.parseDouble(cmd.getOptionValue("reduc_factor")); /* ============================= Generator parameters ============================= */ if (nbFiles < 0 || nbDags < 0 || nbJobs < 0) { System.err.println("[ERROR] Generator: Number of files & DAGs need to be positive."); formatter.printHelp("DAG Generator", options); System.exit(1); return; } Thread threads[] = new Thread[nbJobs]; int nbFilesCreated = 0; int count = 0; while (nbFilesCreated != nbFiles) { int launched = 0; for (int i = 0; i < nbJobs && count < nbFiles; i++) { String outFile = output.substring(0, output.lastIndexOf('.')).concat("-" + count + ".xml"); GeneratorThread gt = new GeneratorThread(maxU, nbTasks, edgeProb, levels, para, nbDags, rfactor, outFile, graph, debug); threads[i] = new Thread(gt); threads[i].setName("GeneratorThread-" + i); launched++; count++; threads[i].start(); } for (int i = 0; i < launched; i++) { try { threads[i].join(); nbFilesCreated++; } catch (InterruptedException e) { e.printStackTrace(); } } } }
From source file:clientpaxos.ClientPaxos.java
/** * @param args the command line arguments *///ww w . j a va 2 s. com public static void main(String[] args) throws IOException, InterruptedException, Exception { // TODO code application logic here String host = ""; int port = 0; try (BufferedReader br = new BufferedReader(new FileReader("ipserver.txt"))) { StringBuilder sb = new StringBuilder(); String line = br.readLine(); if (line != null) { host = line; line = br.readLine(); if (line != null) { port = Integer.parseInt(line); } } } scanner = new Scanner(System.in); //System.out.print("Input server IP hostname : "); //host = scan.nextLine(); //System.out.print("Input server Port : "); //port = scan.nextInt(); //scan.nextLine(); tcpSocket = new Socket(host, port); System.out.println("Connected"); Thread t = new Thread(new StringGetter()); t.start(); while (true) { sleep(100); if (!voteInput) { System.out.print("COMMAND : "); } //send msg to server String msg = scanner.next(); //if ((day && isAlive == 1) || (!day && role.equals("werewolf") && isAlive == 1)) { ParseCommand(msg); //} } }