List of usage examples for java.lang String length
public int length()
From source file:TasteOfThingsV1.java
public static void main(String args[]) throws Exception { prepareData();/*from ww w . j ava2s . co m*/ HashBag myBag = new HashBag(testMap.values()); System.err.println("How many Boxes? " + myBag.getCount("Boxes")); myBag.add("Boxes", 5); System.err.println("How many Boxes now? " + myBag.getCount("Boxes")); Method method = testBean.getClass().getDeclaredMethod("getTestMap", new Class[0]); HashMap reflectionMap = (HashMap)method.invoke(testBean, new Object[0]); System.err.println("The value of the 'squ' key using reflection: " + reflectionMap.get("squ")); String squ = BeanUtils.getMappedProperty(testBean, "testMap", "squ"); squ = StringUtils.capitalize(squ); PropertyUtils.setMappedProperty(testBean, "testMap", "squ", squ); System.err.println("The value of the 'squ' key is: " + BeanUtils.getMappedProperty(testBean, "testMap", "squ")); String box = (String)testMap.get("box"); String caps = Character.toTitleCase(box.charAt(0)) + box.substring(1, box.length()); System.err.println("Capitalizing boxes by Java: " + caps); }
From source file:com.sm.store.server.grizzly.GZClusterServer.java
public static void main(String[] args) { String[] opts = new String[] { "-host", "-configPath", "-dataPath", "-port", "replicaPort", "-start", "-freq" }; String[] defaults = new String[] { "", "", "", "0", "0", "true", "10" }; String[] paras = getOpts(args, opts, defaults); String configPath = paras[1]; if (configPath.length() == 0) { logger.error("missing config path"); throw new RuntimeException("missing -configPath"); }//from w w w. jav a 2s . c om System.setProperty("configPath", configPath); NodeConfig nodeConfig = getNodeConfig(configPath + "/node.properties"); //int clusterNo = Integer.valueOf( paras[0]); String dataPath = paras[2]; if (dataPath.length() == 0) { dataPath = "./data"; } int port = Integer.valueOf(paras[3]); int replicaPort = Integer.valueOf(paras[4]); //get from command line, if not form nodeConfig if (port == 0) port = nodeConfig.getPort(); if (port == 0) { throw new RuntimeException("port is 0"); } else { if (replicaPort == 0) replicaPort = port + 1; } boolean start = Boolean.valueOf(paras[5]); String host = paras[0]; //get from command line, if not form nodeConfig or from getHost if (host.length() == 0) host = nodeConfig.getHost(); if (host.length() == 0) host = getLocalHost(); int freq = Integer.valueOf(paras[6]); logger.info("read clusterNode and storeConfig from " + configPath); BuildClusterNodes bcn = new BuildClusterNodes(configPath + "/clusters.xml"); //BuildStoreConfig bsc = new BuildStoreConfig(configPath+"/stores.xml"); BuildRemoteConfig brc = new BuildRemoteConfig(configPath + "/stores.xml"); List<ClusterNodes> clusterNodesList = bcn.build(); short clusterNo = findClusterNo(host + ":" + port, clusterNodesList); logger.info("create cluster server config for cluster " + clusterNo + " host " + host + " port " + port + " replica port " + replicaPort); ClusterServerConfig serverConfig = new ClusterServerConfig(clusterNodesList, brc.build().getConfigList(), clusterNo, dataPath, configPath, port, replicaPort, host); serverConfig.setFreq(freq); logger.info("create cluster server"); GZClusterStoreServer cs = new GZClusterStoreServer(serverConfig, new HessianSerializer()); // start replica server cs.startReplicaServer(); logger.info("hookup jvm shutdown process"); cs.hookShutdown(); if (start) { logger.info("server is starting " + cs.getServerConfig().toString()); cs.start(); } else logger.warn("server is staged and wait to be started"); List list = new ArrayList(); //add jmx metric List<String> stores = cs.getAllStoreNames(); for (String store : stores) { list.add(cs.getStore(store)); } list.add(cs); stores.add("ClusterServer"); JmxService jms = new JmxService(list, stores); try { logger.info("Read from console and wait ...."); int c = System.in.read(); } catch (IOException e) { logger.warn("Error reading " + e.getMessage()); } logger.warn("Exiting from System.in.read()"); }
From source file:Main.java
public static void main(String argv[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String testStr = "Paste text here."; JTextArea wrapArea = new JTextArea(testStr, 20, 40); wrapArea.setLineWrap(true);//w w w. j a v a 2 s.c o m wrapArea.setWrapStyleWord(true); wrapArea.setCaretPosition(testStr.length()); frame.add(new JScrollPane(wrapArea)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:ReflectionTest.java
public static void main(String[] args) { // read class name from command line args or user input String name;//from ww w . ja v a2 s . c o m if (args.length > 0) name = args[0]; else { Scanner in = new Scanner(System.in); System.out.println("Enter class name (e.g. java.util.Date): "); name = in.next(); } try { // print class name and superclass name (if != Object) Class cl = Class.forName(name); Class supercl = cl.getSuperclass(); String modifiers = Modifier.toString(cl.getModifiers()); if (modifiers.length() > 0) System.out.print(modifiers + " "); System.out.print("class " + name); if (supercl != null && supercl != Object.class) System.out.print(" extends " + supercl.getName()); System.out.print("\n{\n"); printConstructors(cl); System.out.println(); printMethods(cl); System.out.println(); printFields(cl); System.out.println("}"); } catch (ClassNotFoundException e) { e.printStackTrace(); } System.exit(0); }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase413RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine;/*from w w w. j a v a 2 s . c o m*/ Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args); commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } System.out.println( "%%%%%%%%% csv ?, ?, ?(ms)," + new Date().getTime()); for (int i = csvFileStart; i <= csvFileEnd; i++) { new TestCase413RemoteMultiThreads(i).start(); } }
From source file:org.eclipse.swt.snippets.Snippet320.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 320"); shell.setLayout(new GridLayout()); final Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); text.setLayoutData(new GridData(150, SWT.DEFAULT)); shell.pack();/*from w w w .j a v a2 s.co m*/ shell.open(); final Shell popupShell = new Shell(display, SWT.ON_TOP); popupShell.setLayout(new FillLayout()); final Table table = new Table(popupShell, SWT.SINGLE); for (int i = 0; i < 5; i++) { new TableItem(table, SWT.NONE); } text.addListener(SWT.KeyDown, event -> { switch (event.keyCode) { case SWT.ARROW_DOWN: int index = (table.getSelectionIndex() + 1) % table.getItemCount(); table.setSelection(index); event.doit = false; break; case SWT.ARROW_UP: index = table.getSelectionIndex() - 1; if (index < 0) index = table.getItemCount() - 1; table.setSelection(index); event.doit = false; break; case SWT.CR: if (popupShell.isVisible() && table.getSelectionIndex() != -1) { text.setText(table.getSelection()[0].getText()); popupShell.setVisible(false); } break; case SWT.ESC: popupShell.setVisible(false); break; } }); text.addListener(SWT.Modify, event -> { String string = text.getText(); if (string.length() == 0) { popupShell.setVisible(false); } else { TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { items[i].setText(string + '-' + i); } Rectangle textBounds = display.map(shell, null, text.getBounds()); popupShell.setBounds(textBounds.x, textBounds.y + textBounds.height, textBounds.width, 150); popupShell.setVisible(true); } }); table.addListener(SWT.DefaultSelection, event -> { text.setText(table.getSelection()[0].getText()); popupShell.setVisible(false); }); table.addListener(SWT.KeyDown, event -> { if (event.keyCode == SWT.ESC) { popupShell.setVisible(false); } }); Listener focusOutListener = event -> display.asyncExec(() -> { if (display.isDisposed()) return; Control control = display.getFocusControl(); if (control == null || (control != text && control != table)) { popupShell.setVisible(false); } }); table.addListener(SWT.FocusOut, focusOutListener); text.addListener(SWT.FocusOut, focusOutListener); shell.addListener(SWT.Move, event -> popupShell.setVisible(false)); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase411RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine;//from w w w . j a v a 2 s . co m Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args); commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } System.out.println( "%%%%%%%%% csv ?, ?, ?(ms)," + new Date().getTime()); for (int i = csvFileStart; i <= csvFileEnd; i++) { new TestCase411RemoteMultiThreads(i).start(); } }
From source file:Main.java
public static void main(String[] args) throws IOException { String s = "from java2s.com!"; StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); bw.write(s, 0, 5);//from ww w.j av a 2 s . com bw.newLine(); bw.write(s, 6, s.length() - 6); bw.flush(); System.out.print(sw.getBuffer()); }
From source file:SyntaxColoring.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER); final String PUNCTUATION = "(){}"; styledText.addExtendedModifyListener(new ExtendedModifyListener() { public void modifyText(ExtendedModifyEvent event) { int end = event.start + event.length - 1; if (event.start <= end) { String text = styledText.getText(event.start, end); java.util.List ranges = new java.util.ArrayList(); for (int i = 0, n = text.length(); i < n; i++) { if (PUNCTUATION.indexOf(text.charAt(i)) > -1) { ranges.add(new StyleRange(event.start + i, 1, display.getSystemColor(SWT.COLOR_BLUE), null, SWT.BOLD)); }/*from ww w .ja v a2 s .c o m*/ } if (!ranges.isEmpty()) { styledText.replaceStyleRanges(event.start, event.length, (StyleRange[]) ranges.toArray(new StyleRange[0])); } } } }); styledText.setBounds(10, 10, 500, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:dkpro.similarity.algorithms.vsm.store.convert.ConvertLuceneToVectorIndex.java
public static void main(String[] args) throws Exception { File inputPath = new File(args[0]); File outputPath = new File(args[1]); deleteQuietly(outputPath);//w w w . j av a 2 s .c o m outputPath.mkdirs(); boolean ignoreNumerics = true; boolean ignoreCardinal = true; boolean ignoreMonetary = true; int minTermLength = 3; int minDocFreq = 5; System.out.println("Quality criteria"); System.out.println("Minimum term length : " + minTermLength); System.out.println("Minimum document frequency : " + minDocFreq); System.out.println("Ignore numeric tokens : " + ignoreNumerics); System.out.println("Ignore cardinal numeric tokens : " + ignoreNumerics); System.out.println("Ignore money values : " + ignoreMonetary); System.out.print("Fetching terms list... "); IndexReader reader = IndexReader.open(FSDirectory.open(inputPath)); TermEnum termEnum = reader.terms(); Set<String> terms = new HashSet<String>(); int ignoredTerms = 0; while (termEnum.next()) { String term = termEnum.term().text(); if (((minTermLength > 0) && (term.length() < minTermLength)) || (ignoreCardinal && isCardinal(term)) || (ignoreMonetary && isMonetary(term)) || (ignoreNumerics && isNumericSpace(term)) || ((minDocFreq > 0) && (termEnum.docFreq() < minDocFreq))) { ignoredTerms++; continue; } terms.add(term); } reader.close(); System.out.println(terms.size() + " terms found. " + ignoredTerms + " terms ignored."); System.out.println("Opening source ESA index " + inputPath); VectorReader source = new LuceneVectorReader(inputPath); System.out.println("Opening destination ESA index " + inputPath); VectorIndexWriter esaWriter = new VectorIndexWriter(outputPath, source.getConceptCount()); ProgressMeter p = new ProgressMeter(terms.size()); for (String term : terms) { Vector vector = source.getVector(term); esaWriter.put(term, vector); p.next(); System.out.println("[" + term + "] " + p); } esaWriter.close(); }