List of usage examples for org.apache.commons.lang StringUtils countMatches
public static int countMatches(String str, String sub)
Counts how many times the substring appears in the larger String.
From source file:org.sonar.server.measure.custom.ws.SearchActionTest.java
@Test public void search_with_pagination() throws Exception { for (int i = 0; i < 10; i++) { MetricDto metric = insertCustomMetric(i); insertCustomMeasure(i, metric);//from w w w. ja va 2 s .c om } String response = newRequest().setParam(SearchAction.PARAM_PROJECT_KEY, DEFAULT_PROJECT_KEY) .setParam(WebService.Param.PAGE, "3").setParam(WebService.Param.PAGE_SIZE, "4").execute() .outputAsString(); assertThat(StringUtils.countMatches(response, "text-value")).isEqualTo(2); }
From source file:org.sonar.server.metric.ws.ListActionTest.java
@Test public void list_metrics_with_pagination() throws Exception { insertNewCustomMetric("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); WsTester.Result result = newRequest().setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "4").execute(); assertThat(StringUtils.countMatches(result.outputAsString(), "custom-key")).isEqualTo(2); }
From source file:org.sonar.server.metric.ws.SearchActionTest.java
@Test public void search_metrics_with_pagination() throws Exception { insertNewCustomMetric("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); WsTester.Result result = newRequest().setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "4").execute(); assertThat(StringUtils.countMatches(result.outputAsString(), "custom-key")).isEqualTo(2); }
From source file:org.sonar.server.project.ws.GhostsActionTest.java
@Test public void ghost_projects_with_correct_pagination() throws Exception { OrganizationDto organization = db.organizations().insert(); for (int i = 1; i <= 10; i++) { int count = i; insertGhostProject(organization, dto -> dto.setKey("ghost-key-" + count)); }/* w w w . ja v a2 s. c o m*/ userSessionRule.logIn().addPermission(ADMINISTER, organization); TestResponse result = underTest.newRequest().setParam("organization", organization.getKey()) .setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "4").execute(); String json = result.getInput(); assertJson(json).isSimilarTo("{" + " \"p\": 3," + " \"ps\": 4," + " \"total\": 10" + "}"); assertThat(StringUtils.countMatches(json, "ghost-key-")).isEqualTo(2); }
From source file:org.sonar.server.project.ws.ProvisionedActionTest.java
@Test public void provisioned_projects_with_correct_pagination() throws Exception { OrganizationDto org = db.organizations().insert(); for (int i = 1; i <= 10; i++) { db.components().insertComponent(newProvisionedProject(org, String.valueOf(i))); }/*ww w.java 2s . co m*/ userSessionRule.logIn().addPermission(PROVISION_PROJECTS, org); TestRequest request = underTest.newRequest().setParam(PARAM_ORGANIZATION, org.getKey()) .setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "4"); String jsonOutput = request.execute().getInput(); assertThat(StringUtils.countMatches(jsonOutput, "provisioned-uuid-")).isEqualTo(2); }
From source file:org.sonar.squid.recognizer.ContainsDetector.java
@Override public int scan(String line) { String lineWithoutWhitespaces = StringUtils.deleteWhitespace(line); int matchers = 0; for (String str : strs) { matchers += StringUtils.countMatches(lineWithoutWhitespaces, str); }/*from w w w . j a va2s . c om*/ return matchers; }
From source file:org.springframework.ide.eclipse.beans.ui.livegraph.model.LiveBean.java
public String getDisplayName() { // compute the display name the first time it's needed if (displayName == null) { // truncate Class names and name with multiple segments if ((getBeanType() != null && beanId.contains(getBeanType())) || StringUtils.countMatches(beanId, ".") > 1) { int index = beanId.lastIndexOf('.'); if (index >= 0) { displayName = beanId.substring(index + 1, beanId.length()); }//w w w .j a va 2s. com } if (displayName == null) { displayName = beanId; } } return displayName; }
From source file:org.terrier.indexing.PDFDocument.java
/** * Returns the reader of text, which is suitable for parsing terms out of, * and which is created by converting the file represented by * parameter docStream. This method involves running the stream * through the PDFParser etc provided in the org.pdfbox library. * On error, it returns null, and sets EOD to true, so no terms * can be read from this document.//from w ww .j a v a 2 s . c o m * @param is the input stream that represents the document's file. * @return Reader a reader that is fed to an indexer. */ protected Reader getReader(InputStream is) { if ((Files.length(filename) / 1048576) > 300) { logger.info("Skipping document " + filename + " because it's size exceeds 300Mb"); return new StringReader(""); } PDDocument pdfDocument = null; Reader rtr = null; try { pdfDocument = PDDocument.load(is); if (pdfDocument.isEncrypted()) { //Just try using the default password and move on pdfDocument.decrypt(""); } //create a writer where to append the text content. StringWriter writer = new StringWriter(); PDFTextStripper stripper = new PDFTextStripper(); stripper.writeText(pdfDocument, writer); String contents = writer.getBuffer().toString(); int spaceCount = StringUtils.countMatches(contents, " "); for (char badChar : new char[] { '\u00A0', '\u2029', '#' }) { final int count = StringUtils.countMatches(contents, "" + badChar); if (count > spaceCount / 2) { contents = contents.replace(badChar, ' '); spaceCount += count; } } rtr = new StringReader(contents); PDDocumentInformation info = pdfDocument.getDocumentInformation(); if (info != null && USE_PDF_TITLE) { setProperty("title", info.getTitle()); } else { setProperty("title", new java.io.File(super.filename).getName()); } } catch (CryptographyException e) { throw new RuntimeException("Error decrypting PDF document: " + e); } catch (InvalidPasswordException e) { //they didn't suppply a password and the default of "" was wrong. throw new RuntimeException("Error: The PDF document is encrypted and will not be indexed."); } catch (Exception e) { throw new RuntimeException("Error extracting PDF document", e); } finally { if (pdfDocument != null) { try { pdfDocument.close(); } catch (IOException ioe) { } } } return rtr; }
From source file:org.twinkql.result.PropertySetter.java
/** * Adjust for collection.// ww w . j a v a 2 s .c o m * * @param target the target * @param property the property * @return the string */ private String adjustForCollection(Object target, String property) { if (StringUtils.countMatches(property, "[]") > 1) { throw new MappingException( "Cannot have more than one Collection Indicator ('[]') in a 'property' attribute."); } String[] parts = StringUtils.split(property, '.'); for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (StringUtils.endsWith(part, "[]")) { String propertySoFar = StringUtils .removeEnd(StringUtils.join(ArrayUtils.subarray(parts, 0, i + 1), '.'), "[]"); Collection<?> collection = (Collection<?>) BeanUtil.getSimplePropertyForced(target, propertySoFar, true); int index = collection.size(); parts[i] = StringUtils.replace(part, "[]", "[" + index + "]"); } } return StringUtils.join(parts, '.'); }
From source file:org.wso2.carbon.esb.mediators.callout.CARBON15119DuplicateSOAPActionHeader.java
@Test(groups = "wso2.esb", description = "Test to check whether there are duplicate SOAPAction headers in the request to the service from callout mediator") public void testCheckForDuplicateSOAPActionHeaders() throws Exception { String proxyServiceUrl = getProxyServiceURL("DuplicateSOAPActionHeader"); String requestPayload = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' >" + "<soapenv:Body xmlns:ser='http://services.samples' xmlns:xsd='http://services.samples/xsd'> " + "<ser:getQuote> <ser:request> <xsd:symbol>WSO2</xsd:symbol> </ser:request> </ser:getQuote> " + "</soapenv:Body></soapenv:Envelope> "; Map<String, String> headers = new HashMap<String, String>(); headers.put("Soapaction", "urn:getQuote"); HttpRequestUtil.doPost(new URL(proxyServiceUrl), requestPayload, headers); String capturedMsg = wireMonitorServer.getCapturedMessage(); int matchesCount = StringUtils.countMatches(capturedMsg.toLowerCase(), "soapaction"); Assert.assertTrue(matchesCount == 1); }