List of usage examples for org.apache.commons.lang3 StringUtils countMatches
public static int countMatches(final CharSequence str, final char ch)
Counts how many times the char appears in the given string.
A null or empty ("") String input returns 0 .
StringUtils.countMatches(null, *) = 0 StringUtils.countMatches("", *) = 0 StringUtils.countMatches("abba", 0) = 0 StringUtils.countMatches("abba", 'a') = 2 StringUtils.countMatches("abba", 'b') = 2 StringUtils.countMatches("abba", 'x') = 0
From source file:org.force66.vobase.ValueObjectBaseTest.java
@Test public void testToStringPopulatedObject() throws Exception { String objString = populatedVO.toString(); // System.out.println(objString); Assert.assertEquals(70, StringUtils.countMatches(objString, "=")); Assert.assertTrue(objString.contains("testPublicObjectChar=" + populatedVO.testPublicObjectChar)); }
From source file:org.geoserver.test.NestedElementsFilteringTest.java
@Test public void testWfsGetFeatureWithAdvancedNestedFilter() throws Exception { // execute the WFS 2.0 request MockHttpServletResponse response = postAsServletResponse("wfs", readResource("/test-data/stations/nestedElements/requests/wfs_get_feature_1.xml")); // check that station 1 was returned String content = response.getContentAsString(); assertThat(content, containsString("gml:id=\"ins.1\"")); assertThat(StringUtils.countMatches(content, "<wfs:member>"), is(1)); }
From source file:org.h819.commons.file.MyPDFUtilss.java
/** * ?pdf???/* w w w.j ava2s . co m*/ * <p> * javaScript ???? javaScript ? * </p> * * @param srcPdfFileDir ? * @param descPdfFileDir * @param startDate ? "2011,01,01" * @param alerDays ??? * @param expiredDays ????? * @throws java.io.IOException */ public static void setExpireDateWithJavaScript(File srcPdfFileDir, File descPdfFileDir, String startDate, int alerDays, int expiredDays) throws IOException { // ?? if (alerDays >= expiredDays) { logger.info(" ' ' " + alerDays + " '' " + expiredDays); return; } // ??? ? if (StringUtils.countMatches(startDate, ",") != 2) { logger.info(startDate + " ?? '2011,01,01' ?"); return; } if (!isEnoughtSpace(srcPdfFileDir, descPdfFileDir)) return; File listFiles[] = srcPdfFileDir.listFiles(); if (listFiles.length == 0) { logger.info("srcPdfFileDir has not file. " + srcPdfFileDir.getAbsolutePath()); return; } // ?? // String[] resources = new String[]{"/pdfexpiration.js"}; File resPath = MyFileUtils.copyResourceFileFromJarLibToTmpDir("/pdfexpiration.js"); //???? // ? String jsStr = FileUtils.readFileToString(resPath); /** ? js ? */ // ? jsStr = StringUtils.replace(jsStr, "2011,01,01", startDate); // ? jsStr = StringUtils.replace(jsStr, "alertDays = 355", "alertDays = " + Integer.toString(alerDays)); // ? jsStr = StringUtils.replace(jsStr, "expiredDays = 365", "expiredDays = " + Integer.toString(expiredDays)); System.out.println(jsStr); // logger.info(descPdfFileDir.getAbsolutePath()); for (File f : listFiles) { String fileName = f.getName(); String extensiion = FilenameUtils.getExtension(fileName).toLowerCase(); if (f.isFile()) { if (extensiion.equals("pdf")) { PdfReader reader = getPdfReader(f); File fileDesc = new File(descPdfFileDir.getAbsolutePath() + File.separator + fileName); try { PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(fileDesc)); // Get the writer (to add actions and annotations) PdfWriter writer = stamper.getWriter(); PdfAction action = PdfAction.javaScript(jsStr, writer, true); // javaScript ? stamper.setPageAction(PdfWriter.PAGE_OPEN, action, 1); // Close the stamper stamper.close(); reader.close(); logger.info(fileDesc.getAbsolutePath() + " ? !"); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else continue; } // end if f.isFile else if (f.isDirectory()) { setExpireDateWithJavaScript(f, new File(descPdfFileDir.getAbsolutePath() + File.separator + fileName), startDate, alerDays, expiredDays); } // end if f.isDirectory else continue; } // end for }
From source file:org.homelinux.tapiri.jei.essem.AutoFitTextView.java
private int getOriginalLineCount() { String fullText = this.getText().toString(); String eol = System.getProperty("line.separator"); int count = StringUtils.countMatches(fullText, eol) + 1; return count; }
From source file:org.jamwiki.parser.jflex.ParagraphTag.java
/** * Paragraph syntax is dependent on newlines, so determine how many * newlines to count in the current raw text for paragraph parsing * purposes./*from w w w.j av a 2s . c o m*/ */ private int paragraphNewlineCount(JAMWikiLexer jamwikiLexer, String raw) { int newlineCount = 0; if (raw != null) { if (jamwikiLexer.isStartOfFile()) { // if the topic starts with blank lines that weren't automatically // trimmed then treat the file open as a blank line. newlineCount += 2; } newlineCount += StringUtils.countMatches(raw, "\n"); } return newlineCount; }
From source file:org.javabeanstack.util.Strings.java
/** * Devuelve la cantidad de ocurrencias de "seachExpr" dentro de "exprIn" * @param searchExpr cadena buscada.//from w ww . ja va 2s . c o m * @param exprIn cadena dentro de la cual es buscada "searchExpr" * @return cantidad de ocurrencias si los hubiere. */ public static int occurs(String searchExpr, String exprIn) { return StringUtils.countMatches(exprIn, searchExpr); }
From source file:org.jboss.as.test.integration.management.cli.CliVariablesTestCase.java
/** * Tests variable chaining: set var2=$var1 * @throws Exception/*w w w . j av a 2 s. c o m*/ */ @Test public void testVariableChaining() throws Exception { final String VAR1_NAME = "variable_1"; final String VAR2_NAME = "variable_2"; final String VAR1_VALUE = "value_1"; final String VAR2_VALUE = "$" + VAR1_NAME; final ByteArrayOutputStream cliOut = new ByteArrayOutputStream(); final CommandContext ctx = CLITestUtil.getCommandContext(cliOut); ctx.handle("set " + VAR1_NAME + "=" + VAR1_VALUE); ctx.handle("set " + VAR2_NAME + "=" + VAR2_VALUE); cliOut.reset(); ctx.handle("echo $" + VAR1_NAME); ctx.handle("echo $" + VAR2_NAME); String echoResult = cliOut.toString(); assertTrue(echoResult.contains(VAR1_VALUE)); assertFalse(echoResult.contains(VAR2_VALUE)); assertTrue(StringUtils.countMatches(echoResult, VAR1_VALUE) == 2); cliOut.reset(); ctx.handle("set"); //print all variables String setResult = cliOut.toString(); assertTrue(setResult.contains(VAR1_NAME + "=" + VAR1_VALUE)); assertTrue(setResult.contains(VAR2_NAME + "=" + VAR1_VALUE)); assertTrue(ctx.getExitCode() == 0); }
From source file:org.jboss.forge.test.roaster.model.util.RefactoryTest.java
private void assertHashCodeForMultipleLongFields(MethodSource<JavaClassSource> hashcode) { assertEquals("hashCode", hashcode.getName()); assertEquals(0, hashcode.getParameters().size()); assertEquals("int", hashcode.getReturnType().getName()); assertThat(hashcode.getBody()).contains("long temp;"); assertEquals(1, StringUtils.countMatches(hashcode.getBody(), "long temp;")); assertThat(hashcode.getBody()).contains("temp=Double.doubleToLongBits(firstDouble);"); assertThat(hashcode.getBody()).contains("temp=Double.doubleToLongBits(secondDouble);"); assertThat(hashcode.getBody()).contains("prime * result + (int)(temp ^ (temp >>> 32));"); assertEquals(2,//www. java 2 s . c om StringUtils.countMatches(hashcode.getBody(), "prime * result + (int)(temp ^ (temp >>> 32));")); }
From source file:org.jboss.qa.jenkins.test.executor.utils.unpack.UnPacker.java
protected static int countRootFolders(List<String> fileNames) { String prefix = StringUtils.getCommonPrefix(fileNames.toArray(new String[fileNames.size()])); if (!prefix.endsWith(File.separator)) { prefix = prefix.substring(0, prefix.lastIndexOf(File.separator) + 1); }//from w ww .j a v a 2s.com // The first found prefix can match only directory: // root/ (will be removed) // root/a (will be removed) // root/a/a/file.txt (root/a/ is the prefix) // root/abreak;/b/file.txt if (fileNames.remove(prefix)) { return countRootFolders(fileNames); } return StringUtils.countMatches(prefix, File.separator); }
From source file:org.jsweet.test.transpiler.TranspilerTests.java
private SourcePosition getPosition(File f, String codeSnippet) { try {//from ww w . j a v a 2 s . co m String s1 = FileUtils.readFileToString(f); int index = s1.indexOf(codeSnippet); if (index == -1) { System.out.println("DO NOT FIND: " + codeSnippet); System.out.println(s1); } String s = s1.substring(0, index); return new SourcePosition(f, null, StringUtils.countMatches(s, "\n") + 1, s.length() - s.lastIndexOf("\n") - 1); } catch (Exception e) { throw new RuntimeException(e); } }