List of usage examples for java.lang String compareToIgnoreCase
public int compareToIgnoreCase(String str)
From source file:Main.java
public static void main(String[] argv) throws Exception { String s1 = "s1", s3 = "s3"; int i = s1.compareToIgnoreCase(s3); // -1 if (i < 0) { System.out.println("s1 precedes s3"); } else if (i > 0) { System.out.println("s1 follows s3"); } else {/*w w w . j a v a2 s . c o m*/ System.out.println("s1 equals s3"); } }
From source file:Main.java
public static void main(String[] argv) { String str = "Java2s.com"; String str2 = "java2s.com"; System.out.println(str.compareToIgnoreCase(str2)); }
From source file:Main.java
public static void main(String[] args) { String[] strings = { "Here", "are", "some", "sample", "strings", "to", "be", "sorted" }; Arrays.sort(strings, new Comparator<String>() { public int compare(String s1, String s2) { int c = s2.length() - s1.length(); if (c == 0) c = s1.compareToIgnoreCase(s2); return c; }//w w w .j av a 2s .c o m }); for (String s : strings) System.out.print(s + " "); }
From source file:edu.usc.leqa.Main.java
/** * The main method for LEQA./*from ww w . j a v a 2s .co m*/ * * @param args the command line arguments * @throws IOException */ public static void main(String[] args) throws IOException { long start, actual = 0, estimated = 0; // args = "-f ../sample_inputs/fabric.xml-t ../sample_inputs/tech.xml -i ../sample_inputs/tfc/8bitadder.tfc".split("\\s"); parseInputs(args); // -s 0.001 /* * Parsing inputs: fabric, tech & qasm files * LEQA uses parsers of QSPR */ System.out.println("Parsing technology and fabric files..."); start = System.currentTimeMillis(); layout = LayoutParser.parse(techFileAddr, fabricFileAddr); /* Converting TFC to QASM if TFC is provided. */ String inputExtension = inputFileAddr.substring(inputFileAddr.lastIndexOf('.') + 1); if (inputExtension.compareToIgnoreCase("TFC") == 0) { System.out.println("TFC file is provided. Converting to QASM..."); String qasmFileAddr = inputFileAddr.substring(0, inputFileAddr.lastIndexOf('.')) + ".qasm"; if (TFCParser.parse(inputFileAddr, qasmFileAddr) == false) { System.err.println("Failed to convert " + inputFileAddr + " to QASM format."); System.exit(-1); } inputFileAddr = qasmFileAddr; } else if (inputExtension.compareToIgnoreCase("QASM") != 0) { System.err .println("Extension " + inputExtension + " is not supported! Only qasm and tfc are supported."); System.exit(-1); } /* Parsing the QASM file */ System.out.println("Parsing QASM file..."); qasm = QASMParser.QASMParser(inputFileAddr, layout); if (qasm == null || layout == null) System.exit(-1); parseRuntime = (System.currentTimeMillis() - start) / 1000.0; /* * Invoking LEQA for estimating the latency */ System.out.println("Invoking LEQA..."); start = System.currentTimeMillis(); estimated = LEQA.leqa(qasm, layout, speed); leqaRuntime = (System.currentTimeMillis() - start) / 1000.0; /* * Invoking HL-QSPR for calculating the actual latency * This is for comparison only. It can be commented out */ if (!RuntimeConfig.SKIP) { System.out.println("Invoking QSPR..."); start = System.currentTimeMillis(); actual = QSPR.center(eds, layout, qasm); QSPRRuntime = (System.currentTimeMillis() - start) / 1000.0; } /* * Printing the results */ int separatorLength = 30; System.out.println(); System.out.println(StringUtils.center("Results", separatorLength)); System.out.println(StringUtils.repeat('-', separatorLength)); System.out.println("Estimated value:\t" + estimated); if (!RuntimeConfig.SKIP) { System.out.println("Actual value:\t\t" + actual); System.out.printf("Error:\t\t\t%.2f%%" + lineSeparator, (Math.abs(estimated - actual) * 100.0 / actual)); } System.out.println(StringUtils.repeat('-', separatorLength)); System.out.println("Parsing overhead:\t" + parseRuntime + "s"); System.out.println("LEQA runtime:\t\t" + leqaRuntime + "s"); if (!RuntimeConfig.SKIP) { System.out.println("QSPR time:\t\t" + QSPRRuntime + "s"); System.out.printf("Speed up:\t\t%.2f" + lineSeparator, QSPRRuntime / leqaRuntime); } }
From source file:com.datazuul.iiif.presentation.api.ManifestGenerator.java
public static void main(String[] args) throws ParseException, JsonProcessingException, IOException, URISyntaxException { Options options = new Options(); options.addOption("d", true, "Absolute file path to the directory containing the image files."); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("d")) { String imageDirectoryPath = cmd.getOptionValue("d"); Path imageDirectory = Paths.get(imageDirectoryPath); final List<Path> files = new ArrayList<>(); try {/*from w ww . j a va2s . c o m*/ Files.walkFileTree(imageDirectory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory()) { // TODO there must be a more elegant solution for filtering jpeg files... if (file.getFileName().toString().endsWith("jpg")) { files.add(file); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } Collections.sort(files, new Comparator() { @Override public int compare(Object fileOne, Object fileTwo) { String filename1 = ((Path) fileOne).getFileName().toString(); String filename2 = ((Path) fileTwo).getFileName().toString(); try { // numerical sorting Integer number1 = Integer.parseInt(filename1.substring(0, filename1.lastIndexOf("."))); Integer number2 = Integer.parseInt(filename2.substring(0, filename2.lastIndexOf("."))); return number1.compareTo(number2); } catch (NumberFormatException nfe) { // alpha-numerical sorting return filename1.compareToIgnoreCase(filename2); } } }); generateManifest(imageDirectory.getFileName().toString(), files); } else { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ManifestGenerator", options); } }
From source file:ca.uqac.dim.mapreduce.ltl.LTLValidation.java
/** * Program entry point.// ww w .jav a 2s . c o m * @param args Command-line arguments */ @SuppressWarnings("static-access") public static void main(String[] args) { // Define and process command line arguments Options options = new Options(); HelpFormatter help_formatter = new HelpFormatter(); Option opt; options.addOption("h", "help", false, "Show help"); opt = OptionBuilder.withArgName("property").hasArg() .withDescription("Property to verify, enclosed in double quotes").create("p"); options.addOption(opt); opt = OptionBuilder.withArgName("filename").hasArg().withDescription("Input filename").create("i"); options.addOption(opt); opt = OptionBuilder.withArgName("x").hasArg() .withDescription("Set verbosity level to x (default: 0 = quiet)").create("v"); options.addOption(opt); opt = OptionBuilder.withArgName("ParserType").hasArg().withDescription("Parser type (Dom or Sax)") .create("t"); options.addOption(opt); opt = OptionBuilder.withLongOpt("redirection").withArgName("x").hasArg() .withDescription("Set the redirection file for the System.out").create("r"); options.addOption(opt); CommandLine c_line = parseCommandLine(options, args); String redirectionFile = ""; //Contains a redirection file for the output if (c_line.hasOption("redirection")) { try { redirectionFile = c_line.getOptionValue("redirection"); PrintStream ps; ps = new PrintStream(redirectionFile); System.setOut(ps); } catch (FileNotFoundException e) { System.out.println("Redirection error !!!"); e.printStackTrace(); } } if (!c_line.hasOption("p") || !c_line.hasOption("i") | c_line.hasOption("h")) { help_formatter.printHelp(app_name, options); System.exit(1); } assert c_line.hasOption("p"); assert c_line.hasOption("i"); String trace_filename = c_line.getOptionValue("i"); String trace_format = getExtension(trace_filename); String property_str = c_line.getOptionValue("p"); String ParserType = ""; if (c_line.hasOption("t")) { ParserType = c_line.getOptionValue("t"); } else { System.err.println("No Parser Type in Arguments"); System.exit(ERR_ARGUMENTS); } if (c_line.hasOption("v")) m_verbosity = Integer.parseInt(c_line.getOptionValue("v")); // Obtain the property to verify and break into subformulas Operator property = null; try { int preset = Integer.parseInt(property_str); property = new Edoc2012Presets().property(preset); } catch (NumberFormatException e) { try { property = Operator.parseFromString(property_str); } catch (Operator.ParseException pe) { System.err.println("ERROR: parsing"); System.exit(1); } } Set<Operator> subformulas = property.getSubformulas(); // Initialize first collector depending on input file format int max_loops = property.getDepth(); int max_tuples_total = 0, total_tuples_total = 0; long time_begin = System.nanoTime(); TraceCollector initial_collector = null; { File in_file = new File(trace_filename); if (trace_format.compareToIgnoreCase(".txt") == 0) { initial_collector = new CharacterTraceCollector(in_file, subformulas); } else if (trace_format.compareToIgnoreCase(".xml") == 0) { if (ParserType.equals("Dom")) { initial_collector = new XmlDomTraceCollector(in_file, subformulas); } else if (ParserType.equals("Sax")) { initial_collector = new XmlSaxTraceCollector(in_file, subformulas); } else { initial_collector = new XmlSaxTraceCollector(in_file, subformulas); } } } if (initial_collector == null) { System.err.println("ERROR: unrecognized input format"); System.exit(1); } // Start workflow int trace_len = initial_collector.getTraceLength(); InCollector<Operator, LTLTupleValue> loop_collector = initial_collector; print(System.out, property.toString(), 2); print(System.out, loop_collector.toString(), 3); for (int i = 0; i < max_loops; i++) { print(System.out, "Loop " + i, 2); LTLSequentialWorkflow w = new LTLSequentialWorkflow(new LTLMapper(subformulas), new LTLReducer(subformulas, trace_len), loop_collector); loop_collector = w.run(); max_tuples_total += w.getMaxTuples(); total_tuples_total += w.getTotalTuples(); if (m_verbosity >= 3) { print(System.out, loop_collector.toString(), 3); } } boolean result = getVerdict(loop_collector, property); long time_end = System.nanoTime(); if (result) print(System.out, "Formula is true", 1); else print(System.out, "Formula is false", 1); long time_total = (time_end - time_begin) / 1000000; System.out.println(trace_len + "," + max_tuples_total + "," + total_tuples_total + "," + time_total); }
From source file:ca.uqac.dim.mapreduce.ltl.ParaLTLValidation.java
/** * Program entry point.//from w w w. j ava2 s. c o m * @param args Command-line arguments */ @SuppressWarnings("static-access") public static void main(String[] args) { // Define and process command line arguments Options options = new Options(); HelpFormatter help_formatter = new HelpFormatter(); Option opt; options.addOption("h", "help", false, "Show help"); opt = OptionBuilder.withArgName("property").hasArg() .withDescription("Property to verify, enclosed in double quotes").create("p"); options.addOption(opt); opt = OptionBuilder.withArgName("filename").hasArg().withDescription("Input filename").create("i"); options.addOption(opt); opt = OptionBuilder.withArgName("x").hasArg() .withDescription("Set verbosity level to x (default: 0 = quiet)").create("v"); options.addOption(opt); opt = OptionBuilder.withArgName("ParserType").hasArg().withDescription("Parser type (Dom or Sax)") .create("t"); options.addOption(opt); opt = OptionBuilder.withLongOpt("redirection").withArgName("x").hasArg() .withDescription("Set the redirection file for the System.out").create("r"); options.addOption(opt); opt = OptionBuilder.withLongOpt("mapper").withArgName("x").hasArg() .withDescription("Set the number of mapper").create("m"); options.addOption(opt); opt = OptionBuilder.withLongOpt("reducer").withArgName("x").hasArg() .withDescription("Set the number of reducer").create("n"); options.addOption(opt); CommandLine c_line = parseCommandLine(options, args); String redirectionFile = ""; //Contains a redirection file for the output if (c_line.hasOption("redirection")) { try { redirectionFile = c_line.getOptionValue("redirection"); PrintStream ps; ps = new PrintStream(redirectionFile); System.setOut(ps); } catch (FileNotFoundException e) { System.out.println("Redirection error !!!"); e.printStackTrace(); } } if (!c_line.hasOption("p") || !c_line.hasOption("i") | c_line.hasOption("h")) { help_formatter.printHelp(app_name, options); System.exit(1); } assert c_line.hasOption("p"); assert c_line.hasOption("i"); String trace_filename = c_line.getOptionValue("i"); String trace_format = getExtension(trace_filename); String property_str = c_line.getOptionValue("p"); String ParserType = ""; int MapperNum = 0; int ReducerNum = 0; //Contains a parser type if (c_line.hasOption("t")) { ParserType = c_line.getOptionValue("t"); } else { System.err.println("No Parser Type in Arguments"); System.exit(ERR_ARGUMENTS); } //Contains a mapper number if (c_line.hasOption("m")) { MapperNum = Integer.parseInt(c_line.getOptionValue("m")); } else { System.err.println("No Mapper Number in Arguments"); System.exit(ERR_ARGUMENTS); } //Contains a reducer number if (c_line.hasOption("n")) { ReducerNum = Integer.parseInt(c_line.getOptionValue("n")); } else { System.err.println("No Reducer Number in Arguments"); System.exit(ERR_ARGUMENTS); } if (c_line.hasOption("v")) m_verbosity = Integer.parseInt(c_line.getOptionValue("v")); // Obtain the property to verify and break into subformulas Operator property = null; try { int preset = Integer.parseInt(property_str); property = new Edoc2012Presets().property(preset); } catch (NumberFormatException e) { try { property = Operator.parseFromString(property_str); } catch (Operator.ParseException pe) { System.err.println("ERROR: parsing"); System.exit(1); } } Set<Operator> subformulas = property.getSubformulas(); // Initialize first collector depending on input file format int max_loops = property.getDepth(); int max_tuples_total = 0, total_tuples_total = 0; long time_begin = System.nanoTime(); TraceCollector initial_collector = null; { File in_file = new File(trace_filename); if (trace_format.compareToIgnoreCase(".txt") == 0) { initial_collector = new CharacterTraceCollector(in_file, subformulas); } else if (trace_format.compareToIgnoreCase(".xml") == 0) { if (ParserType.equals("Dom")) { initial_collector = new XmlDomTraceCollector(in_file, subformulas); } else if (ParserType.equals("Sax")) { initial_collector = new XmlSaxTraceCollector(in_file, subformulas); } else { initial_collector = new XmlSaxTraceCollector(in_file, subformulas); } } } if (initial_collector == null) { System.err.println("ERROR: unrecognized input format"); System.exit(1); } // Start workflow int trace_len = initial_collector.getTraceLength(); InCollector<Operator, LTLTupleValue> loop_collector = initial_collector; print(System.out, property.toString(), 2); print(System.out, loop_collector.toString(), 3); for (int i = 0; i < max_loops; i++) { print(System.out, "Loop " + i, 2); LTLParallelWorkflow w = new LTLParallelWorkflow(new LTLMapper(subformulas), new LTLReducer(subformulas, trace_len), loop_collector, new ResourceManager<Operator, LTLTupleValue>(MapperNum), new ResourceManager<Operator, LTLTupleValue>(ReducerNum)); loop_collector = w.run(); max_tuples_total += w.getMaxTuples(); total_tuples_total += w.getTotalTuples(); if (m_verbosity >= 3) { print(System.out, loop_collector.toString(), 3); } } boolean result = getVerdict(loop_collector, property); long time_end = System.nanoTime(); if (result) print(System.out, "Formula is true", 1); else print(System.out, "Formula is false", 1); long time_total = (time_end - time_begin) / 1000000; System.out.println(trace_len + "," + max_tuples_total + "," + total_tuples_total + "," + time_total); }
From source file:ca.uqac.lif.bullwinkle.BullwinkleCli.java
/** * @param args/*from w w w .ja va2s . co m*/ */ public static void main(String[] args) { // Setup parameters int verbosity = 1; String output_format = "xml", grammar_filename = null, filename_to_parse = null; // Parse command line arguments Options options = setupOptions(); CommandLine c_line = setupCommandLine(args, options); assert c_line != null; if (c_line.hasOption("verbosity")) { verbosity = Integer.parseInt(c_line.getOptionValue("verbosity")); } if (verbosity > 0) { showHeader(); } if (c_line.hasOption("version")) { System.err.println("(C) 2014 Sylvain Hall et al., Universit du Qubec Chicoutimi"); System.err.println("This program comes with ABSOLUTELY NO WARRANTY."); System.err.println("This is a free software, and you are welcome to redistribute it"); System.err.println("under certain conditions. See the file LICENSE-2.0 for details.\n"); System.exit(ERR_OK); } if (c_line.hasOption("h")) { showUsage(options); System.exit(ERR_OK); } if (c_line.hasOption("f")) { output_format = c_line.getOptionValue("f"); } // Get grammar file @SuppressWarnings("unchecked") List<String> remaining_args = c_line.getArgList(); if (remaining_args.isEmpty()) { System.err.println("ERROR: no grammar file specified"); System.exit(ERR_ARGUMENTS); } grammar_filename = remaining_args.get(0); // Get file to parse, if any if (remaining_args.size() >= 2) { filename_to_parse = remaining_args.get(1); } // Read grammar file BnfParser parser = null; try { parser = new BnfParser(new File(grammar_filename)); } catch (InvalidGrammarException e) { System.err.println("ERROR: invalid grammar"); System.exit(ERR_GRAMMAR); } catch (IOException e) { System.err.println("ERROR reading grammar " + grammar_filename); System.exit(ERR_IO); } assert parser != null; // Read input file BufferedReader bis = null; if (filename_to_parse == null) { // Read from stdin bis = new BufferedReader(new InputStreamReader(System.in)); } else { // Read from file try { bis = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename_to_parse)))); } catch (FileNotFoundException e) { System.err.println("ERROR: file not found " + filename_to_parse); System.exit(ERR_IO); } } assert bis != null; String str; StringBuilder input_file = new StringBuilder(); try { while ((str = bis.readLine()) != null) { input_file.append(str).append("\n"); } } catch (IOException e) { System.err.println("ERROR reading input"); System.exit(ERR_IO); } String file_contents = input_file.toString(); // Parse contents of file ParseNode p_node = null; try { p_node = parser.parse(file_contents); } catch (ca.uqac.lif.bullwinkle.BnfParser.ParseException e) { System.err.println("ERROR parsing input\n"); e.printStackTrace(); System.exit(ERR_PARSE); } if (p_node == null) { System.err.println("ERROR parsing input\n"); System.exit(ERR_PARSE); } assert p_node != null; // Output parse node to desired format PrintStream output = System.out; OutputFormatVisitor out_vis = null; if (output_format.compareToIgnoreCase("xml") == 0) { // Output to XML out_vis = new XmlVisitor(); } else if (output_format.compareToIgnoreCase("dot") == 0) { // Output to DOT out_vis = new GraphvizVisitor(); } else if (output_format.compareToIgnoreCase("txt") == 0) { // Output to indented plain text out_vis = new IndentedTextVisitor(); } else if (output_format.compareToIgnoreCase("json") == 0) { // Output to JSON } if (out_vis == null) { System.err.println("ERROR: unknown output format " + output_format); System.exit(ERR_ARGUMENTS); } assert out_vis != null; p_node.prefixAccept(out_vis); output.print(out_vis.toOutputString()); // Terminate without error System.exit(ERR_OK); }
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T extends Enum> boolean compareEnum(final Object src, final Object tgt) throws Exception { String name = ((T) src).name(); if (name.compareToIgnoreCase((String) tgt) == 0) return true; return false; }
From source file:Main.java
/** determines if the passed string contains the keywords for special values * @param value a binary string or a string containing POSITIVEINFINITY,NEGATIVEINFINITY,POSITIVEZERO,NEGATIVEZERO,QNAN,SNAN * @return the proper binary string if value contains special values, or value itself if the string is not special*/ public static String parseKeywords(String value) { if (value.compareToIgnoreCase("POSITIVEINFINITY") == 0) { return PLUSINFINITY; } else if (value.compareToIgnoreCase("NEGATIVEINFINITY") == 0) { return MINUSINFINITY; } else if (value.compareToIgnoreCase("POSITIVEZERO") == 0) { return PLUSZERO; } else if (value.compareToIgnoreCase("NEGATIVEZERO") == 0) { return MINUSZERO; } else if (value.compareToIgnoreCase("QNAN") == 0) { return QNAN_NEW; } else if (value.compareToIgnoreCase("SNAN") == 0) { return SNAN_NEW; }//from w w w . j a va 2s . co m return value; }