List of usage examples for java.lang String lastIndexOf
public int lastIndexOf(String str)
From source file:ShowComponent.java
public static void main(String[] args) { // Process the command line to get the components to display Vector components = getComponentsFromArgs(args); // Create a frame (a window) to display them in JFrame frame = new JFrame("ShowComponent"); // Handle window close requests by exiting the VM frame.addWindowListener(new WindowAdapter() { // Anonymous inner class public void windowClosing(WindowEvent e) { System.exit(0);// w w w. j a v a 2s . c o m } }); // Set up a menu system that allows the user to select the // look-and-feel of the component from a list of installed PLAFs JMenuBar menubar = new JMenuBar(); // Create a menubar frame.setJMenuBar(menubar); // Tell the frame to display it JMenu plafmenu = createPlafMenu(frame); // Create a menu menubar.add(plafmenu); // Add the menu to the menubar // Create a JTabbedPane to display each of the components JTabbedPane pane = new JTabbedPane(); // Now add each component as a tab of the tabbed pane // Use the unqualified component classname as the tab text for (int i = 0; i < components.size(); i++) { Component c = (Component) components.elementAt(i); String classname = c.getClass().getName(); String tabname = classname.substring(classname.lastIndexOf('.') + 1); pane.addTab(tabname, c); } // Add the tabbed pane to the frame. Note the call to getContentPane() // This is required for JFrame, but not for most Swing components frame.getContentPane().add(pane); // Set the frame size and pop it up frame.pack(); // Make frame as big as its kids need frame.setVisible(true); // Make the frame visible on the screen // The main() method exits now but the Java VM keeps running because // all AWT programs automatically start an event-handling thread. }
From source file:Main.java
public static void main(String[] args) { String strOrig = "A B C A"; int intIndex = strOrig.indexOf("B"); if (intIndex == -1) { System.out.println("not found"); } else {/*from w ww . j a va2 s. c om*/ System.out.println("Found " + intIndex); } int positionIndex = strOrig.indexOf("A", 2); System.out.println("after 2 is " + positionIndex); int lastIndex = strOrig.lastIndexOf("A"); System.out.println("Last index " + lastIndex); }
From source file:edu.msu.cme.rdp.graph.sandbox.KmerStartsFromKnown.java
public static void main(String[] args) throws Exception { final KmerStartsWriter out; final boolean translQuery; final int wordSize; final int translTable; try {// w ww.ja v a 2 s. c o m CommandLine cmdLine = new PosixParser().parse(options, args); args = cmdLine.getArgs(); if (args.length < 2) { throw new Exception("Unexpected number of arguments"); } if (cmdLine.hasOption("out")) { out = new KmerStartsWriter(cmdLine.getOptionValue("out")); } else { out = new KmerStartsWriter(System.out); } if (cmdLine.hasOption("transl-table")) { translTable = Integer.valueOf(cmdLine.getOptionValue("transl-table")); } else { translTable = 11; } translQuery = cmdLine.hasOption("transl-kmer"); wordSize = Integer.valueOf(args[0]); } catch (Exception e) { new HelpFormatter().printHelp("KmerStartsFromKnown <word_size> [name=]<ref_file> ...", options); System.err.println(e.getMessage()); System.exit(1); throw new RuntimeException("Stupid jvm"); //While this will never get thrown it is required to make sure javac doesn't get confused about uninitialized variables } long startTime = System.currentTimeMillis(); /* * if (args.length == 4) { maxThreads = Integer.valueOf(args[3]); } else * { */ //} System.err.println("Starting kmer mapping at " + new Date()); System.err.println("* References: " + Arrays.asList(args)); System.err.println("* Kmer length: " + wordSize); for (int index = 1; index < args.length; index++) { String refName; String refFileName = args[index]; if (refFileName.contains("=")) { String[] lexemes = refFileName.split("="); refName = lexemes[0]; refFileName = lexemes[1]; } else { String tmpName = new File(refFileName).getName(); if (tmpName.contains(".")) { refName = tmpName.substring(0, tmpName.lastIndexOf(".")); } else { refName = tmpName; } } File refFile = new File(refFileName); if (SeqUtils.guessSequenceType(refFile) != SequenceType.Nucleotide) { throw new Exception("Reference file " + refFile + " contains " + SeqUtils.guessFileFormat(refFile) + " sequences but expected nucleotide sequences"); } SequenceReader seqReader = new SequenceReader(refFile); Sequence seq; while ((seq = seqReader.readNextSequence()) != null) { if (seq.getSeqName().startsWith("#")) { continue; } ModelPositionKmerGenerator kmers = new ModelPositionKmerGenerator(seq.getSeqString(), wordSize, SequenceType.Nucleotide); for (char[] charmer : kmers) { int pos = kmers.getModelPosition() - 1; if (translQuery) { if (pos % 3 != 0) { continue; } else { pos /= 3; } } String kmer = new String(charmer); out.write(new KmerStart(refName, seq.getSeqName(), seq.getSeqName(), kmer, 1, pos, translQuery, (translQuery ? ProteinUtils.getInstance().translateToProtein(kmer, true, translTable) : null))); } } seqReader.close(); } out.close(); }
From source file:jhc.redsniff.generation.PackageScanningGenerator.java
public static void main(String[] args) throws Exception { if (args.length != 5) { System.err.println("Args: source-dir package-class-filter parent-class generated-class output-dir"); System.err.println(""); System.err.println(" source-dir : Path to Java source containing matchers to generate sugar for."); System.err.println(" May contain multiple paths, separated by commas."); System.err.println(" e.g. src/java,src/more-java"); System.err.println(// www . j a v a 2s . com " package-class-filter : base of package to look for classes with methods, eg jhc.selenium.matchers"); System.err.println(""); System.err.println( "parent-class : Full name of parent class type to examine - eg org.hamcrest.Matcher, jhc.selenium.seeker.Seeker"); System.err.println(" e.g. org.myproject.MyMatchers"); System.err.println("generated-class : Full name of class to generate."); System.err.println(" e.g. org.myproject.MyMatchers"); System.err.println(""); System.err.println(" output-dir : Where to output generated code (package subdirs will be"); System.err.println(" automatically created)."); System.err.println(" e.g. build/generated-code"); System.exit(-1); } String srcDirs = args[0]; String package_name_prefix = args[1]; String parentClassName = args[2]; String fullClassName = args[3]; File outputDir = new File(args[4]); String fileName = fullClassName.replace('.', File.separatorChar) + ".java"; int dotIndex = fullClassName.lastIndexOf("."); String packageName = dotIndex == -1 ? "" : fullClassName.substring(0, dotIndex); String shortClassName = fullClassName.substring(dotIndex + 1); if (!outputDir.isDirectory()) { System.err.println("Output directory not found : " + outputDir.getAbsolutePath()); System.exit(-1); } Class<?> parentClass = Class.forName(parentClassName); File outputFile = new File(outputDir, fileName); outputFile.getParentFile().mkdirs(); File tmpFile = new File(outputDir, fileName + ".tmp"); SugarGenerator sugarGenerator = new SugarGenerator(); try { sugarGenerator .addWriter(new SeleniumFactoryWriter(packageName, shortClassName, new FileWriter(tmpFile))); sugarGenerator.addWriter(new QuickReferenceWriter(System.out)); PackageScanningGenerator pkgScanningGenerator = new PackageScanningGenerator(sugarGenerator, PackageScanningGenerator.class.getClassLoader(), parentClass); if (srcDirs.trim().length() > 0) { for (String srcDir : srcDirs.split(",")) { pkgScanningGenerator.addSourceDir(new File(srcDir)); } } // could add use of xml just to list filter expressions // pkgScanningGenerator.load(new InputSource(configFile)); pkgScanningGenerator.addClasses(package_name_prefix); System.out.println("Generating " + fullClassName); sugarGenerator.generate(); sugarGenerator.close(); outputFile.delete(); FileUtils.moveFile(tmpFile, outputFile); } finally { tmpFile.delete(); sugarGenerator.close(); } }
From source file:mil.tatrc.physiology.biogears.verification.ScenarioPlotTool.java
public static void main(String[] args) { if (args.length < 1) { Log.fatal("Expected inputs : [results file path] [result in results file NOT to plot] "); return;// w ww.j a v a 2 s. c o m } File f = new File(args[0]); if (!f.exists()) { Log.fatal("Input file cannot be found"); return; } String reportDir = "./graph_results/" + f.getName(); reportDir = reportDir.substring(0, reportDir.lastIndexOf(".")) + "/"; ScenarioPlotTool t = new ScenarioPlotTool(); t.graphResults(args[0], reportDir); }
From source file:importer.handler.post.stages.Splitter.java
/** test and commandline utility */ public static void main(String[] args) { if (args.length >= 1) { try {//from www. ja v a 2s . co m int i = 0; int fileIndex = 0; // see if the user supplied a conf file String textConf = Discriminator.defaultConf; while (i < args.length) { if (args[i].equals("-c") && i < args.length - 1) { textConf = readConfig(args[i + 1]); i += 2; } else { fileIndex = i; i++; } } File f = new File(args[fileIndex]); char[] data = new char[(int) f.length()]; FileReader fr = new FileReader(f); fr.read(data); JSONObject config = (JSONObject) JSONValue.parse(textConf); Splitter split = new Splitter(config); Map<String, String> map = split.split(new String(data)); Set<String> keys = map.keySet(); String rawFileName = args[fileIndex]; int pos = rawFileName.lastIndexOf("."); if (pos != -1) rawFileName = rawFileName.substring(0, pos); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String key = iter.next(); String fName = rawFileName + "-" + key + ".xml"; File g = new File(fName); if (g.exists()) g.delete(); FileOutputStream fos = new FileOutputStream(g); fos.write(map.get(key).getBytes("UTF-8")); fos.close(); } } catch (Exception e) { e.printStackTrace(System.out); } } else System.out.println("usage: java -jar split.jar [-c json-config] <tei-xml>\n"); }
From source file:mil.tatrc.physiology.utilities.csv.plots.CSVPlotTool.java
public static void main(String[] args) { if (args.length < 1) { Log.fatal("Expected inputs : [results file path]"); return;//from ww w . j a va2 s . c o m } File f = new File(args[0]); if (!f.exists()) { Log.fatal("Input file cannot be found"); return; } String reportDir = "./graph_results/" + f.getName(); reportDir = reportDir.substring(0, reportDir.lastIndexOf(".")) + "/"; CSVPlotTool t = new CSVPlotTool(); t.graphResults(args[0], reportDir); }
From source file:ca.uqac.dim.net.verify.NetworkChecker.java
/** * Main loop. Processes command line arguments, loads the network, builds and * sends a file to NuSMV and handles its response. * @param args Command-line arguments//from ww w . ja va 2 s.co m */ public static void main(String[] args) { // Configuration variables boolean opt_show_file = false, opt_show_messages = true, opt_show_stats = false; // Create and parse command line options Option opt = null; Options options = new Options(); options.addOption("f", "file", false, "Output NuSMV file to stdout"); options.addOption("s", "time", false, "Display statistics"); options.addOption("h", "help", false, "Show usage information"); options.addOption("q", "quiet", false, "Do not display any message or explanation"); opt = new Option("i", "file", true, "Input directory"); opt.setRequired(true); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error parsing command line arguments"); showUsage(options); System.exit(1); } if (cmd == null) { System.err.println("Error parsing command line arguments"); showUsage(options); System.exit(1); } // Get options assert cmd != null; opt_show_file = cmd.hasOption("f"); opt_show_messages = !cmd.hasOption("q"); opt_show_stats = cmd.hasOption("s"); if (opt_show_messages) System.err.println( "Distributed anomaly verifier\n(C) 2012 Sylvain Hall, Universit du Qubec Chicoutimi\n"); // Get input directory and blob assert cmd.hasOption("i"); String slash = System.getProperty("file.separator"); String input_dir = cmd.getOptionValue("i"); int loc = input_dir.lastIndexOf(slash); String dir_name = "", blob = ""; if (loc == -1) { dir_name = ""; blob = input_dir; } else { dir_name = input_dir.substring(0, loc); blob = input_dir.substring(loc + 1); } // Load network Network net = null; try { net = loadNetworkFromDirectory(dir_name, blob, slash); } catch (FileNotFoundException e) { System.err.print("Error reading "); System.err.println(e.getMessage()); System.exit(1); } catch (IOException e) { System.err.println(e); System.exit(1); } // Build NuSMV file assert net != null; StringBuilder sb = new StringBuilder(); if (opt_show_file) { sb.append("-- File auto-generated by DistributedChecker\n"); sb.append("-- (C) 2012 Sylvain Hall, Universit du Qubec Chicoutimi\n\n"); } sb.append(net.toSmv(opt_show_file)); // Simple shadowing String f_shadowing = "G (frozen -> !(interval_l <= rule_interval_l & interval_r >= rule_interval_r & decision != rule_decision))"; sb.append("\n\nLTLSPEC\n").append(f_shadowing); // Run NuSMV and parse its return value if (opt_show_file) { System.out.println(sb); System.exit(0); } RuntimeInfos ri = null; try { ri = runNuSMV(sb.toString()); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(1); } catch (InterruptedException e) { System.err.println(e.getMessage()); System.exit(1); } assert ri != null; // If requested, compute and show an explanation from NuSMV's returned contents if (opt_show_messages) { ExplanationTrace t = null; try { t = net.explain(ri.m_return_contents); } catch (NuSmvParseException e) { System.err.println("Error reading NuSMV's answer"); System.exit(1); } if (t == null) { // No explanation => no anomaly found System.out.println("No anomaly found"); } else System.out.println(t); } // If requested, show runtime statistics if (opt_show_stats) { StringBuilder out = new StringBuilder(); out.append(net.getNodeSize()).append(","); out.append(net.getFirewallRuleSize()).append(","); out.append(net.getRoutingTableSize()).append(","); out.append(ri.m_runtime); System.out.println(out); } System.exit(0); }
From source file:com.gson.util.HttpKit.java
public static void main(String[] args) { String fname = "dsasdas.mp4"; String s = fname.substring(0, fname.lastIndexOf(".")); String f = fname.substring(s.length() + 1); System.out.println(f);// w ww . j a va 2 s .c om }
From source file:com.jwm123.loggly.reporter.AppLauncher.java
public static void main(String args[]) throws Exception { try {//from w w w . j a v a 2s . c om CommandLine cl = parseCLI(args); try { config = new Configuration(); } catch (Exception e) { e.printStackTrace(); System.err.println("ERROR: Failed to read in persisted configuration."); } if (cl.hasOption("h")) { HelpFormatter help = new HelpFormatter(); String jarName = AppLauncher.class.getProtectionDomain().getCodeSource().getLocation().getFile(); if (jarName.contains("/")) { jarName = jarName.substring(jarName.lastIndexOf("/") + 1); } help.printHelp("java -jar " + jarName + " [options]", opts); } if (cl.hasOption("c")) { config.update(); } if (cl.hasOption("q")) { Client client = new Client(config); client.setQuery(cl.getOptionValue("q")); if (cl.hasOption("from")) { client.setFrom(cl.getOptionValue("from")); } if (cl.hasOption("to")) { client.setTo(cl.getOptionValue("to")); } List<Map<String, Object>> report = client.getReport(); if (report != null) { List<Map<String, String>> reportContent = new ArrayList<Map<String, String>>(); ReportGenerator generator = null; if (cl.hasOption("file")) { generator = new ReportGenerator(new File(cl.getOptionValue("file"))); } byte reportFile[] = null; if (cl.hasOption("g")) { System.out.println("Search results: " + report.size()); Set<Object> values = new TreeSet<Object>(); Map<Object, Integer> counts = new HashMap<Object, Integer>(); for (String groupBy : cl.getOptionValues("g")) { for (Map<String, Object> result : report) { if (mapContains(result, groupBy)) { Object value = mapGet(result, groupBy); values.add(value); if (counts.containsKey(value)) { counts.put(value, counts.get(value) + 1); } else { counts.put(value, 1); } } } System.out.println("For key: " + groupBy); for (Object value : values) { System.out.println(" " + value + ": " + counts.get(value)); } } if (cl.hasOption("file")) { Map<String, String> reportAddition = new LinkedHashMap<String, String>(); reportAddition.put("Month", MONTH_FORMAT.format(new Date())); reportContent.add(reportAddition); for (Object value : values) { reportAddition = new LinkedHashMap<String, String>(); reportAddition.put(value.toString(), "" + counts.get(value)); reportContent.add(reportAddition); } reportAddition = new LinkedHashMap<String, String>(); reportAddition.put("Total", "" + report.size()); reportContent.add(reportAddition); } } else { System.out.println("The Search [" + cl.getOptionValue("q") + "] yielded " + report.size() + " results."); if (cl.hasOption("file")) { Map<String, String> reportAddition = new LinkedHashMap<String, String>(); reportAddition.put("Month", MONTH_FORMAT.format(new Date())); reportContent.add(reportAddition); reportAddition = new LinkedHashMap<String, String>(); reportAddition.put("Count", "" + report.size()); reportContent.add(reportAddition); } } if (cl.hasOption("file")) { reportFile = generator.build(reportContent); File reportFileObj = new File(cl.getOptionValue("file")); FileUtils.writeByteArrayToFile(reportFileObj, reportFile); if (cl.hasOption("e")) { ReportMailer mailer = new ReportMailer(config, cl.getOptionValues("e"), cl.getOptionValue("s"), reportFileObj.getName(), reportFile); mailer.send(); } } } } } catch (IllegalArgumentException e) { System.err.println(e.getMessage()); System.exit(1); } }