List of usage examples for java.lang String equals
public boolean equals(Object anObject)
From source file:com.kotcrab.vis.editor.Main.java
public static void main(String[] args) throws Exception { App.init();//from w ww. ja va 2s.c om if (OsUtils.isMac()) System.setProperty("java.awt.headless", "true"); LaunchConfiguration launchConfig = new LaunchConfiguration(); //TODO: needs some better parser for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.equals("--scale-ui")) { launchConfig.scaleUIEnabled = true; continue; } if (arg.equals("--project")) { if (i + 1 >= args.length) { throw new IllegalStateException("Not enough parameters for --project <project path>"); } launchConfig.projectPath = args[i + 1]; i++; continue; } if (arg.equals("--scene")) { if (i + 1 >= args.length) { throw new IllegalStateException("Not enough parameters for --scene <scene path>"); } launchConfig.scenePath = args[i + 1]; i++; continue; } Log.warn("Unrecognized command line argument: " + arg); } launchConfig.verify(); editor = new Editor(launchConfig); Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); config.setWindowedMode(1280, 720); config.setWindowSizeLimits(1, 1, 9999, 9999); config.useVsync(true); config.setIdleFPS(2); config.setWindowListener(new Lwjgl3WindowAdapter() { @Override public boolean closeRequested() { editor.requestExit(); return false; } }); try { new Lwjgl3Application(editor, config); Log.dispose(); } catch (Exception e) { Log.exception(e); Log.fatal("Uncaught exception occurred, error report will be saved"); Log.flush(); if (App.eventBus != null) App.eventBus.post(new ExceptionEvent(e, true)); try { File crashReport = new CrashReporter(Log.getLogFile().file()).processReport(); if (new File(App.TOOL_CRASH_REPORTER_PATH).exists() == false) { Log.warn("Crash reporting tool not present, skipping crash report sending."); } else { CommandLine cmdLine = new CommandLine(PlatformUtils.getJavaBinPath()); cmdLine.addArgument("-jar"); cmdLine.addArgument(App.TOOL_CRASH_REPORTER_PATH); cmdLine.addArgument(ApplicationUtils.getRestartCommand().replace("\"", "%")); cmdLine.addArgument(crashReport.getAbsolutePath(), false); DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(null, null, null)); executor.execute(cmdLine); } } catch (IOException ex) { ex.printStackTrace(); } Log.dispose(); System.exit(-3); } catch (ExceptionInInitializerError err) { if (OsUtils.isMac() && err.getCause() instanceof IllegalStateException) { if (ExceptionUtils.getStackTrace(err).contains("XstartOnFirstThread")) { System.out.println( "Application was not launched on first thread. Restarting with -XstartOnFirstThread, add VM argument -XstartOnFirstThread to avoid this."); ApplicationUtils.startNewInstance(); } } throw err; } }
From source file:FormLoginDemo.java
public static void main(String[] args) throws Exception { HttpClient client = new HttpClient(); client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http"); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); // 'developer.java.sun.com' has cookie compliance problems // Their session cookie's domain attribute is in violation of the RFC2109 // We have to resort to using compatibility cookie policy GetMethod authget = new GetMethod("/servlet/SessionServlet"); client.executeMethod(authget);/*w w w. j a va 2 s. c om*/ System.out.println("Login form get: " + authget.getStatusLine().toString()); // release any connection resources used by the method authget.releaseConnection(); // See if we got any cookies CookieSpec cookiespec = CookiePolicy.getDefaultSpec(); Cookie[] initcookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies()); System.out.println("Initial set of cookies:"); if (initcookies.length == 0) { System.out.println("None"); } else { for (int i = 0; i < initcookies.length; i++) { System.out.println("- " + initcookies[i].toString()); } } PostMethod authpost = new PostMethod("/servlet/SessionServlet"); // Prepare login parameters NameValuePair action = new NameValuePair("action", "login"); NameValuePair url = new NameValuePair("url", "/index.html"); NameValuePair userid = new NameValuePair("UserId", "userid"); NameValuePair password = new NameValuePair("Password", "password"); authpost.setRequestBody(new NameValuePair[] { action, url, userid, password }); client.executeMethod(authpost); System.out.println("Login form post: " + authpost.getStatusLine().toString()); // release any connection resources used by the method authpost.releaseConnection(); // See if we got any cookies // The only way of telling whether logon succeeded is // by finding a session cookie Cookie[] logoncookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies()); System.out.println("Logon cookies:"); if (logoncookies.length == 0) { System.out.println("None"); } else { for (int i = 0; i < logoncookies.length; i++) { System.out.println("- " + logoncookies[i].toString()); } } // Usually a successful form-based login results in a redicrect to // another url int statuscode = authpost.getStatusCode(); if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) || (statuscode == HttpStatus.SC_MOVED_PERMANENTLY) || (statuscode == HttpStatus.SC_SEE_OTHER) || (statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) { Header header = authpost.getResponseHeader("location"); if (header != null) { String newuri = header.getValue(); if ((newuri == null) || (newuri.equals(""))) { newuri = "/"; } System.out.println("Redirect target: " + newuri); GetMethod redirect = new GetMethod(newuri); client.executeMethod(redirect); System.out.println("Redirect: " + redirect.getStatusLine().toString()); // release any connection resources used by the method redirect.releaseConnection(); } else { System.out.println("Invalid redirect"); System.exit(1); } } }
From source file:ActionsMenuBar.java
public static void main(String args[]) { final JFrame frame = new JFrame("TextAction Usage"); Container contentPane = frame.getContentPane(); final JScrollPane scrollPane = new JScrollPane(); contentPane.add(scrollPane, BorderLayout.CENTER); final JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar);/*from w w w. j av a 2 s.com*/ ActionListener actionListener = new ActionListener() { JTextComponent component; public void actionPerformed(ActionEvent actionEvent) { // Determine which component selected String command = actionEvent.getActionCommand(); if (command.equals("JTextField")) { component = new JTextField(); } else if (command.equals("JPasswordField")) { component = new JPasswordField(); } else if (command.equals("JTextArea")) { component = new JTextArea(); } else if (command.equals("JTextPane")) { component = new JTextPane(); } else { component = new JEditorPane(); } scrollPane.setViewportView(component); // Process action list Action actions[] = component.getActions(); menuBar.removeAll(); menuBar.revalidate(); JMenu menu = null; for (int i = 0, n = actions.length; i < n; i++) { if ((i % 10) == 0) { menu = new JMenu("From " + i); menuBar.add(menu); } menu.add(actions[i]); } menuBar.revalidate(); } }; String components[] = { "JTextField", "JPasswordField", "JTextArea", "JTextPane", "JEditorPane" }; final Container componentsContainer = RadioButtonUtils.createRadioButtonGrouping(components, "Pick to List Actions", actionListener); contentPane.add(componentsContainer, BorderLayout.WEST); frame.setSize(400, 300); frame.setVisible(true); }
From source file:com.buddycloud.channeldirectory.cli.Main.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { JsonElement rootElement = new JsonParser().parse(new FileReader(QUERIES_FILE)); JsonArray rootArray = rootElement.getAsJsonArray(); Map<String, Query> queries = new HashMap<String, Query>(); for (int i = 0; i < rootArray.size(); i++) { JsonObject queryElement = rootArray.get(i).getAsJsonObject(); String queryName = queryElement.get("name").getAsString(); String type = queryElement.get("type").getAsString(); Query query = null;//from w w w . ja v a 2s. c o m if (type.equals("solr")) { query = new QueryToSolr(queryElement.get("agg").getAsString(), queryElement.get("core").getAsString(), queryElement.get("q").getAsString()); } else if (type.equals("dbms")) { query = new QueryToDBMS(queryElement.get("q").getAsString()); } queries.put(queryName, query); } LinkedList<String> queriesNames = new LinkedList<String>(queries.keySet()); Collections.sort(queriesNames); Options options = new Options(); options.addOption(OptionBuilder.isRequired(true).withLongOpt("query").hasArg(true) .withDescription("The name of the query. Possible queries are: " + queriesNames).create('q')); options.addOption(OptionBuilder.isRequired(false).withLongOpt("args").hasArg(true) .withDescription("Arguments for the query").create('a')); options.addOption(new Option("?", "help", false, "Print this message")); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { printHelpAndExit(options); } if (cmd.hasOption("help")) { printHelpAndExit(options); } String queryName = cmd.getOptionValue("q"); String argsCmd = cmd.getOptionValue("a"); Properties configuration = ConfigurationUtils.loadConfiguration(); Query query = queries.get(queryName); if (query == null) { printHelpAndExit(options); } System.out.println(query.exec(argsCmd, configuration)); }
From source file:test.TestJavaService.java
/** * Main. The cmdline arguments either do or don't contain the flag -remote: that's the only supported flag. If it is specified, * we test code on the AWS instance. If it is not, we test code running locally. * The first non-flag argument is the "verb", which (currently) should be one of the verbs set at the top of source file * org.qcert.javasrc.Main. Remaining non-flag arguments are file names. There must be at least one. The number of such * arguments and what they should contain depends on the verb. * @throws Exception/*from www. j a v a 2s.c o m*/ */ public static void main(String[] args) throws Exception { /* Parse command line */ List<String> files = new ArrayList<>(); String loc = "localhost", verb = null; for (String arg : args) { if (arg.equals("-remote")) loc = REMOTE_LOC; else if (arg.startsWith("-")) illegal(); else if (verb == null) verb = arg; else files.add(arg); } /* Simple consistency checks and verb-specific parsing */ if (files.size() == 0) illegal(); String file = files.remove(0); String schema = null; switch (verb) { case "parseSQL": case "serialRule2CAMP": case "sqlSchema2JSON": if (files.size() != 0) illegal(); break; case "techRule2CAMP": if (files.size() != 1) illegal(); schema = files.get(0); break; case "csv2JSON": if (files.size() < 1) illegal(); break; default: illegal(); } /* Assemble information from arguments */ String url = String.format("http://%s:9879?verb=%s", loc, verb); byte[] contents = Files.readAllBytes(Paths.get(file)); String toSend; if ("serialRule2CAMP".equals(verb)) toSend = Base64.getEncoder().encodeToString(contents); else toSend = new String(contents); if ("techRule2CAMP".equals(verb)) toSend = makeSpecialJson(toSend, schema); else if ("csv2JSON".equals(verb)) toSend = makeSpecialJson(toSend, files); HttpClient client = HttpClients.createDefault(); HttpPost post = new HttpPost(url); StringEntity entity = new StringEntity(toSend); entity.setContentType("text/plain"); post.setEntity(entity); HttpResponse resp = client.execute(post); int code = resp.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK) { HttpEntity answer = resp.getEntity(); InputStream s = answer.getContent(); BufferedReader rdr = new BufferedReader(new InputStreamReader(s)); String line = rdr.readLine(); while (line != null) { System.out.println(line); line = rdr.readLine(); } rdr.close(); s.close(); } else System.out.println(resp.getStatusLine()); }
From source file:com.act.lcms.CompareTwoNetCDFAroundMass.java
public static void main(String[] args) throws Exception { if (args.length < 5 || !areNCFiles(Arrays.copyOfRange(args, 3, args.length))) { throw new RuntimeException("Needs: \n" + "(1) mass value, e.g., 132.0772 for debugging, \n" + "(2) how many timepoints to process (-1 for all), \n" + "(3) prefix for .data and rendered .pdf \n" + "(4,5..) 2 or more NetCDF .nc files"); }//from w w w. j ava2 s. c o m String fmt = "pdf"; Double mz = Double.parseDouble(args[0]); Integer numSpectraToProcess = Integer.parseInt(args[1]); String outPrefix = args[2]; String outImg = outPrefix.equals("-") ? null : outPrefix + "." + fmt; String outData = outPrefix.equals("-") ? null : outPrefix + ".data"; CompareTwoNetCDFAroundMass c = new CompareTwoNetCDFAroundMass(); String[] netCDF_fnames = Arrays.copyOfRange(args, 3, args.length); List<List<Pair<Double, Double>>> spectra = c.getSpectraForMass(mz, netCDF_fnames, numSpectraToProcess); // Write data output to outfile PrintStream out = outData == null ? System.out : new PrintStream(new FileOutputStream(outData)); // print out the spectra to outData for (List<Pair<Double, Double>> spectraInFile : spectra) { for (Pair<Double, Double> xy : spectraInFile) { out.format("%.4f\t%.4f\n", xy.getLeft(), xy.getRight()); out.flush(); } // delimit this dataset from the rest out.print("\n\n"); } // find the ymax across all spectra, so that we can have a uniform y scale Double yrange = 0.0; for (List<Pair<Double, Double>> spectraInFile : spectra) { Double ymax = 0.0; for (Pair<Double, Double> xy : spectraInFile) { Double intensity = xy.getRight(); if (ymax < intensity) ymax = intensity; } if (yrange < ymax) yrange = ymax; } if (outData != null) { // if outData is != null, then we have written to .data file // now render the .data to the corresponding .pdf file // first close the .data out.close(); // render outData to outFILE using gnuplo Gnuplotter plotter = new Gnuplotter(); plotter.plot2D(outData, outImg, netCDF_fnames, "time in seconds", yrange, "intensity", fmt); } }
From source file:com.mytutorials.httpclient.FormLoginDemo.java
public static void main(String[] args) throws Exception { HttpClient client = new HttpClient(); client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http"); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); // 'developer.java.sun.com' has cookie compliance problems // Their session cookie's domain attribute is in violation of the // RFC2109// w w w . ja v a2 s .c o m // We have to resort to using compatibility cookie policy GetMethod authget = new GetMethod("/servlet/SessionServlet"); client.executeMethod(authget); System.out.println("Login form get: " + authget.getStatusLine().toString()); // release any connection resources used by the method authget.releaseConnection(); // See if we got any cookies CookieSpec cookiespec = CookiePolicy.getDefaultSpec(); Cookie[] initcookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies()); System.out.println("Initial set of cookies:"); if (initcookies.length == 0) { System.out.println("None"); } else { for (int i = 0; i < initcookies.length; i++) { System.out.println("- " + initcookies[i].toString()); } } PostMethod authpost = new PostMethod("/servlet/SessionServlet"); // Prepare login parameters NameValuePair action = new NameValuePair("action", "login"); NameValuePair url = new NameValuePair("url", "/index.html"); NameValuePair userid = new NameValuePair("UserId", "userid"); NameValuePair password = new NameValuePair("Password", "password"); authpost.setRequestBody(new NameValuePair[] { action, url, userid, password }); client.executeMethod(authpost); System.out.println("Login form post: " + authpost.getStatusLine().toString()); // release any connection resources used by the method authpost.releaseConnection(); // See if we got any cookies // The only way of telling whether logon succeeded is // by finding a session cookie Cookie[] logoncookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies()); System.out.println("Logon cookies:"); if (logoncookies.length == 0) { System.out.println("None"); } else { for (int i = 0; i < logoncookies.length; i++) { System.out.println("- " + logoncookies[i].toString()); } } // Usually a successful form-based login results in a redicrect to // another url int statuscode = authpost.getStatusCode(); if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) || (statuscode == HttpStatus.SC_MOVED_PERMANENTLY) || (statuscode == HttpStatus.SC_SEE_OTHER) || (statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) { Header header = authpost.getResponseHeader("location"); if (header != null) { String newuri = header.getValue(); if ((newuri == null) || (newuri.equals(""))) { newuri = "/"; } System.out.println("Redirect target: " + newuri); GetMethod redirect = new GetMethod(newuri); client.executeMethod(redirect); System.out.println("Redirect: " + redirect.getStatusLine().toString()); // release any connection resources used by the method redirect.releaseConnection(); } else { System.out.println("Invalid redirect"); System.exit(1); } } }
From source file:org.acme.insurance.policyquote.test.WorkServiceMain.java
public static void main(String... args) throws Exception { serverHostname = System.getProperty("serverHostname", serverHostname); Set<String> policies = new HashSet<String>(); for (String arg : args) { arg = Strings.trimToNull(arg);//ww w . ja v a2 s . c o m if (arg != null) { if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) { policies.add(arg); } else { LOGGER.error(MAVEN_USAGE); throw new Exception(MAVEN_USAGE); } } } if (policies.contains(HELP)) { LOGGER.info(MAVEN_USAGE); } else { final String scheme; final int port; if (policies.contains(CONFIDENTIALITY)) { LOGGER.info("Invoking service via SSL..."); scheme = "https"; port = 443; SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, null, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); Scheme https = new Scheme(scheme, port, sf); SchemeRegistry sr = new SchemeRegistry(); sr.register(https); } else { scheme = "http"; port = 8080; } Element assertion = policies.contains(CLIENT_AUTHENTICATION) ? getAssertion() : null; invokeWorkService(scheme, port, assertion); } }
From source file:SequentialPersonalizedPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(/* w w w .ja v a 2 s . c om*/ OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); options.addOption(OptionBuilder.withArgName("node").hasArg() .withDescription("source node (i.e., destination of the random jump)").create(SOURCE)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(SOURCE)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPersonalizedPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); final String source = cmdline.getOptionValue(SOURCE); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); if (!graph.containsVertex(source)) { System.err.println("Error: source node not found in the graph!"); System.exit(-1); } WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute personalized PageRank. PageRankWithPriors<String, Integer> ranker = new PageRankWithPriors<String, Integer>(graph, new Transformer<String, Double>() { @Override public Double transform(String vertex) { return vertex.equals(source) ? 1.0 : 0; } }, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }
From source file:com.tonygalati.sprites.SpriteGenerator.java
public static void main(String[] args) throws IOException { // if (args.length != 3) // {//from ww w .j a va 2 s. co m // System.out.print("Usage: com.tonygalati.sprites.SpriteGenerator {path to images} {margin between images in px} {output file}\n"); // System.out.print("Note: The max height should only be around 32,767px due to Microsoft GDI using a 16bit signed integer to store dimensions\n"); // System.out.print("going beyond this dimension is possible with this tool but the generated sprite image will not work correctly with\n"); // System.out.print("most browsers.\n\n"); // return; // } // Integer margin = Integer.parseInt(args[1]); Integer margin = Integer.parseInt("1"); String spriteFile = "icons-" + RandomStringUtils.randomAlphanumeric(10) + ".png"; SpriteCSSGenerator cssGenerator = new SpriteCSSGenerator(); ClassLoader classLoader = SpriteGenerator.class.getClassLoader(); URL folderPath = classLoader.getResource(NAIC_SMALL_ICON); if (folderPath != null) { File imageFolder = new File(folderPath.getPath()); // Read images ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>(); Integer yCoordinate = null; for (File f : imageFolder.listFiles()) { if (f.isFile()) { String fileName = f.getName(); String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); if (ext.equals("png")) { System.out.println("adding file " + fileName); BufferedImage image = ImageIO.read(f); imageList.add(image); if (yCoordinate == null) { yCoordinate = 0; } else { yCoordinate += (image.getHeight() + margin); } // add to cssGenerator cssGenerator.addSpriteCSS(fileName.substring(0, fileName.indexOf(".")), 0, yCoordinate); } } } // Find max width and total height int maxWidth = 0; int totalHeight = 0; for (BufferedImage image : imageList) { totalHeight += image.getHeight() + margin; if (image.getWidth() > maxWidth) maxWidth = image.getWidth(); } System.out.format("Number of images: %s, total height: %spx, width: %spx%n", imageList.size(), totalHeight, maxWidth); // Create the actual sprite BufferedImage sprite = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB); int currentY = 0; Graphics g = sprite.getGraphics(); for (BufferedImage image : imageList) { g.drawImage(image, 0, currentY, null); currentY += image.getHeight() + margin; } System.out.format("Writing sprite: %s%n", spriteFile); ImageIO.write(sprite, "png", new File(spriteFile)); File cssFile = cssGenerator.getFile(spriteFile); System.out.println(cssFile.getAbsolutePath() + " created"); } else { System.err.println("Could not find folder: " + NAIC_SMALL_ICON); } }