List of usage examples for java.lang String equals
public boolean equals(Object anObject)
From source file:Main.java
public static void main(String[] args) { ArrayList aList = new ArrayList(); aList.add("1"); aList.add("2"); aList.add("3"); aList.add("4"); aList.add("java2 s .com"); System.out.println("ArrayList: "); System.out.println(aList);/*from w ww . java 2 s . co m*/ Iterator itr = aList.iterator(); String strElement = ""; while (itr.hasNext()) { strElement = (String) itr.next(); if (strElement.equals("2")) { itr.remove(); break; } } System.out.println("ArrayList after removal : "); System.out.println(aList); }
From source file:Main.java
public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); String oeStartDateStr = "04/01/2015"; String oeEndDateStr = "11/14/2015"; Calendar cal = Calendar.getInstance(); Integer year = cal.get(Calendar.YEAR); oeStartDateStr = oeStartDateStr.concat(year.toString()); oeEndDateStr = oeEndDateStr.concat(year.toString()); Date startDate = sdf.parse(oeStartDateStr); Date endDate = sdf.parse(oeEndDateStr); Date d = new Date(); String currDt = sdf.format(d); if ((d.after(startDate) && (d.before(endDate))) || (currDt.equals(sdf.format(startDate)) || currDt.equals(sdf.format(endDate)))) { System.out.println("Date is between 1st april to 14th nov..."); } else {//from w w w . ja v a 2 s . c o m System.out.println("Date is not between 1st april to 14th nov..."); } }
From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveKeyKryoValue.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0];/*from ww w .jav a 2s. c om*/ //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions //Package of your value serializer class. Use com.axiomine.bigcollections.functions String KPACKAGE = args[2]; //Class name (no packages) of the Key class Ex. String //Class name (no packages) of the value class Ex. Integer String K = args[3]; //Specify if you are using a KryoTemplate to generate your classes //If true the template used to generate the class is KryoBasedMapTemplte, if false the JavaLangBasedMapTemplate is used //You can customize the name of the class generated String kCls = K; if (kCls.equals("byte[]")) { kCls = "BytesArray"; } String CLASS_NAME = kCls + "KryoV" + "Map"; //Default //String templatePath = args[5]; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/PrimitiveKeyKryoValueMapTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#K#", K); program = program.replaceAll("#KCLS#", kCls); program = program.replaceAll("#KPACKAGE#", KPACKAGE); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:com.vaadin.buildhelpers.FetchReleaseNotesTickets.java
public static void main(String[] args) throws IOException { String version = System.getProperty("vaadin.version"); if (version == null || version.equals("")) { usage();//from w ww .j a v a2 s . c o m } URL url = new URL(queryURL.replace("@version@", version)); URLConnection connection = url.openConnection(); InputStream urlStream = connection.getInputStream(); @SuppressWarnings("unchecked") List<String> tickets = IOUtils.readLines(urlStream); for (String ticket : tickets) { String[] fields = ticket.split("\t"); if ("id".equals(fields[0])) { // This is the header continue; } System.out.println(ticketTemplate.replace("@ticket@", fields[0]).replace("@description@", fields[1])); } urlStream.close(); }
From source file:com.axiomine.largecollections.generator.GeneratorKryoKPrimitiveValue.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0];/*from w ww. ja v a 2 s.c o m*/ //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions //Package of your value serializer class. Use com.axiomine.bigcollections.functions String VPACKAGE = args[2]; //Class name (no packages) of the Key class Ex. String //Class name (no packages) of the value class Ex. Integer String V = args[3]; //Specify if you are using a KryoTemplate to generate your classes //If true the template used to generate the class is KryoBasedMapTemplte, if false the JavaLangBasedMapTemplate is used //You can customize the name of the class generated String vCls = V; if (vCls.equals("byte[]")) { vCls = "BytesArray"; } String CLASS_NAME = "KryoK" + vCls + "Map"; //Default //String templatePath = args[5]; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/KryoKeyPrimitiveValueMapTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#V#", V); program = program.replaceAll("#VPACKAGE#", VPACKAGE); program = program.replaceAll("#VCLS#", vCls); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:SWTToolBar.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setSize(300, 200);/* w w w . j a v a 2s . co m*/ ToolBar toolbar = new ToolBar(shell, SWT.NONE); ToolItem item1 = new ToolItem(toolbar, SWT.PUSH); item1.setText("Now"); ToolItem item2 = new ToolItem(toolbar, SWT.PUSH); item2.setText("is"); ToolItem item3 = new ToolItem(toolbar, SWT.PUSH); item3.setText("the"); ToolItem item4 = new ToolItem(toolbar, SWT.PUSH); item4.setText("time"); toolbar.setBounds(0, 0, 200, 70); final Text text = new Text(shell, SWT.BORDER); text.setBounds(0, 100, 200, 25); Listener listener = new Listener() { public void handleEvent(Event event) { ToolItem item = (ToolItem) event.widget; String string = item.getText(); if (string.equals("Now")) text.setText("You selected: Now"); else if (string.equals("is")) text.setText("You selected: is"); else if (string.equals("the")) text.setText("You selected: the"); else if (string.equals("time")) text.setText("You selected: time"); } }; item1.addListener(SWT.Selection, listener); item2.addListener(SWT.Selection, listener); item3.addListener(SWT.Selection, listener); item4.addListener(SWT.Selection, listener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ToolItemSelectionListenerAdding.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3;//w w w . j a v a2s. com shell.setLayout(gridLayout); ToolBar toolbar = new ToolBar(shell, SWT.NONE); ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH); itemBack.setText("Back"); ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH); itemForward.setText("Forward"); ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH); itemStop.setText("Stop"); ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH); itemRefresh.setText("Refresh"); ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH); itemGo.setText("Go"); GridData data = new GridData(); data.horizontalSpan = 3; toolbar.setLayoutData(data); Listener listener = new Listener() { public void handleEvent(Event event) { ToolItem item = (ToolItem) event.widget; String string = item.getText(); if (string.equals("Back")) System.out.println("Back"); else if (string.equals("Forward")) System.out.println("Forward"); else if (string.equals("Stop")) System.out.println("Stop"); else if (string.equals("Refresh")) System.out.println("Refresh"); else if (string.equals("Go")) System.out.println("Go"); } }; itemBack.addListener(SWT.Selection, listener); itemForward.addListener(SWT.Selection, listener); itemStop.addListener(SWT.Selection, listener); itemRefresh.addListener(SWT.Selection, listener); itemGo.addListener(SWT.Selection, listener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:RegExTest.java
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter pattern: "); String patternString = in.nextLine(); Pattern pattern = null;//from w w w . j ava2s. c o m try { pattern = Pattern.compile(patternString); } catch (PatternSyntaxException e) { System.out.println("Pattern syntax error"); System.exit(1); } while (true) { System.out.println("Enter string to match: "); String input = in.nextLine(); if (input == null || input.equals("")) return; Matcher matcher = pattern.matcher(input); if (matcher.matches()) { System.out.println("Match"); int g = matcher.groupCount(); if (g > 0) { for (int i = 0; i < input.length(); i++) { for (int j = 1; j <= g; j++) if (i == matcher.start(j)) System.out.print('('); System.out.print(input.charAt(i)); for (int j = 1; j <= g; j++) if (i + 1 == matcher.end(j)) System.out.print(')'); } System.out.println(); } } else System.out.println("No match"); } }
From source file:org.eclipse.swt.snippets.Snippet216.java
public static void main(String[] args) { Display display = new Display(); final Color[] colors = { display.getSystemColor(SWT.COLOR_RED), display.getSystemColor(SWT.COLOR_GREEN), display.getSystemColor(SWT.COLOR_BLUE), }; final Rectangle[] rects = { new Rectangle(10, 10, 30, 30), new Rectangle(20, 45, 25, 35), new Rectangle(80, 80, 10, 10), }; final Shell shell = new Shell(display); shell.setText("Snippet 216"); Listener mouseListener = event -> { switch (event.type) { case SWT.MouseEnter: case SWT.MouseMove: for (int i = 0; i < rects.length; i++) { if (rects[i].contains(event.x, event.y)) { String text = "ToolTip " + i; if (!(text.equals(shell.getToolTipText()))) { shell.setToolTipText("ToolTip " + i); }//from w w w . j a v a 2 s . c o m return; } } shell.setToolTipText(null); break; } }; shell.addListener(SWT.MouseMove, mouseListener); shell.addListener(SWT.MouseEnter, mouseListener); shell.addListener(SWT.Paint, event -> { GC gc = event.gc; for (int i = 0; i < rects.length; i++) { gc.setBackground(colors[i]); gc.fillRectangle(rects[i]); gc.drawRectangle(rects[i]); } }); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:com.pinterest.secor.main.ZookeeperClientMain.java
public static void main(String[] args) { try {//from ww w. ja v a2 s . c om CommandLine commandLine = parseArgs(args); String command = commandLine.getOptionValue("command"); if (!command.equals("delete_committed_offsets")) { throw new IllegalArgumentException("command has to be one of \"delete_committed_offsets\""); } SecorConfig config = SecorConfig.load(); ZookeeperConnector zookeeperConnector = new ZookeeperConnector(config); String topic = commandLine.getOptionValue("topic"); if (commandLine.hasOption("partition")) { int partition = ((Number) commandLine.getParsedOptionValue("partition")).intValue(); TopicPartition topicPartition = new TopicPartition(topic, partition); zookeeperConnector.deleteCommittedOffsetPartitionCount(topicPartition); } else { zookeeperConnector.deleteCommittedOffsetTopicCount(topic); } } catch (Throwable t) { LOG.error("Zookeeper client failed", t); System.exit(1); } }