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:com.jkoolcloud.tnt4j.streams.format.FactNameValueFormatterTest.java
@Test public void testFormat() { FactNameValueFormatter formatter = new FactNameValueFormatter(); Map<String, Object> properties = new HashMap<>(); properties.put("PathLevelAttributes", "StartTime;Severity"); formatter.setConfiguration(properties); ConfigFactory configFactory = DefaultConfigFactory.getInstance(); Tracker tracker = new DefaultTrackerFactory() .getInstance(configFactory.getConfig(getClass().getName()).build()); TrackingActivity activity = tracker.newActivity(OpLevel.INFO, "TestName"); String result = formatter.format(activity); System.out.println(result);// ww w. j a v a2s. co m assertNotNull(result); assertTrue(result.startsWith("OBJ:Streams")); assertTrue(result.contains("Activities")); assertTrue(StringUtils.countMatches(result, ",") == 14); }
From source file:com.h3xstream.findbugs.test.BaseDetectorTest.java
public String getClassFilePath(String path) { //Convert dot class name to path if (StringUtils.countMatches(path, ".") > 1 && !path.endsWith(".jar")) { path = path.replaceAll("\\.", "/"); }/* w w w. jav a 2s. c om*/ return classFileLocator.getClassFilePath(path); }
From source file:com.bazaarvoice.jolt.cardinality.CardinalitySpec.java
public static List<PathElement> parse(String key) { if (key.contains("@")) { return Arrays.<PathElement>asList(new AtPathElement(key)); } else if ("*".equals(key)) { return Arrays.<PathElement>asList(new StarAllPathElement(key)); } else if (key.contains("*")) { if (StringUtils.countMatches(key, "*") == 1) { return Arrays.<PathElement>asList(new StarSinglePathElement(key)); } else {// w ww . java2 s. co m return Arrays.<PathElement>asList(new StarRegexPathElement(key)); } } else { return Arrays.<PathElement>asList(new LiteralPathElement(key)); } }
From source file:net.pixomania.crawler.W3C.parser.rules.editors.EditorsRule8.java
@Override public ArrayList<Person> run(String url, Document doc) { ArrayList<Person> editorList = new ArrayList<>(); Elements editors = doc.select("h4:contains(Editor) ~ blockquote"); if (editors.size() == 0) return null; boolean skip = false; for (Element editor : editors) { Element prev = editor.previousElementSibling(); if (prev.tagName().equals("h4")) { if ((!prev.text().trim().toLowerCase().startsWith("editor") && !prev.text().trim().toLowerCase().startsWith("edition editor")) || prev.text().trim().toLowerCase().endsWith("version:") || prev.text().trim().toLowerCase().endsWith("draft:")) { skip = true;//from w w w .ja v a 2 s. c o m } } if (skip) { Element next = editor.nextElementSibling(); if (next != null) { if (next.text().trim().toLowerCase().startsWith("editor") || next.text().trim().toLowerCase().contains("edition editor")) { skip = false; continue; } } continue; } if (StringUtils.countMatches(editor.text(), " - ") > 2) { Log.log("warning", "This editor may be a list of editors separated by - "); EditorsRule5 ed5 = new EditorsRule5(); return ed5.run(url, doc); } String[] splitted = editor.html().split("<br />|<br clear=\"none\" />"); if (splitted.length < 2) { if (editor.text().toLowerCase().startsWith("(in alphabetic") || editor.text().toLowerCase().startsWith("see acknowl") || editor.text().toLowerCase().startsWith("the w3") || editor.text().toLowerCase().startsWith("(see ac") || editor.text().toLowerCase().startsWith("see participants") || editor.text().toLowerCase().contains("note:")) { Log.log("warning", "Spec " + url + " may refer to a different section!"); continue; } if (editor.text().equals("WHATWG:") || editor.text().equals("W3C:")) continue; Person result = NameParser.parse(editor.text()); if (result == null) continue; for (int i = 0; i < editor.select("a").size(); i++) { if (!editor.select("a").get(i).attr("href").isEmpty()) { if (editor.select("a").get(i).attr("href").contains("@")) { result.setEmail(editor.select("a").get(i).attr("href").replace("mailto:", "")); } else { result.addWebsite(editor.select("a").get(i).attr("href")); } } } editorList.add(result); } else { for (String split : splitted) { if (!split.isEmpty()) { if (split.toLowerCase().startsWith("(in alphabetic") || split.toLowerCase().startsWith("see acknowl") || split.toLowerCase().startsWith("the w3") || split.toLowerCase().startsWith("(see ac") || split.toLowerCase().startsWith("see participants") || split.toLowerCase().contains("note:")) { Log.log("warning", "Spec " + url + " may refer to a different section!"); continue; } if (split.equals("WHATWG:") || split.equals("W3C:")) continue; Document newdoc = Jsoup.parse(split.replaceAll("\n", "")); Person result = NameParser.parse(newdoc.text()); if (result == null) continue; for (int i = 0; i < newdoc.select("a").size(); i++) { if (!newdoc.select("a").get(i).attr("href").isEmpty()) { if (newdoc.select("a").get(i).attr("href").contains("@")) { result.setEmail(newdoc.select("a").get(i).attr("href").replace("mailto:", "")); } else { result.addWebsite(newdoc.select("a").get(i).attr("href")); } } } editorList.add(result); } } } Element next = editor.nextElementSibling(); if (next != null) if (next.tag().getName().equals("h4")) break; } if (editorList.size() == 0) return null; return editorList; }
From source file:jetbrick.tools.chm.style.Javadoc8Style.java
@Override public String getMethodFullName(String url) { String name = StringUtils.substringAfter(url, "#"); int count = StringUtils.countMatches(name, "-"); name = StringUtils.replaceOnce(name, "-", "("); for (int i = 0; i < count - 2; i++) { name = StringUtils.replaceOnce(name, "-", ", "); }/*w ww .java 2 s . c o m*/ name = StringUtils.replaceOnce(name, "-", ")"); name = StringUtils.replace(name, ":A", "[]"); return name; }
From source file:net.pixomania.crawler.W3C.parser.rules.editors.EditorsRule2.java
@Override public ArrayList<Person> run(String url, Document doc) { ArrayList<Person> editorList = new ArrayList<>(); Elements editors = doc.select("dt:contains(Editor) ~ dd, dt:contains(Edition Editor) ~ dd"); if (editors.size() == 0) return null; boolean skip = false; for (Element editor : editors) { Element prev = editor.previousElementSibling(); if (prev.tagName().equals("dt")) { if ((!prev.text().trim().toLowerCase().startsWith("editor") && !prev.text().trim().toLowerCase().startsWith("edition editor")) || prev.text().trim().toLowerCase().contains("version") || prev.text().trim().toLowerCase().endsWith("draft:")) { skip = true;/*ww w .j a v a 2s . com*/ } } if (skip) { Element next = editor.nextElementSibling(); if (next != null) { if (next.text().trim().toLowerCase().startsWith("editor") || next.text().trim().toLowerCase().contains("edition editor")) { skip = false; continue; } } continue; } if (StringUtils.countMatches(editor.text(), " - ") > 2) { Log.log("warning", "This editor may be a list of editors separated by - "); EditorsRule5 ed5 = new EditorsRule5(); return ed5.run(url, doc); } String[] splitted = editor.html().split("<br />|<br clear=\"none\" />"); if (splitted.length < 2) { if (editor.text().toLowerCase().startsWith("(in alphabetic") || editor.text().toLowerCase().startsWith("see acknowl") || editor.text().toLowerCase().startsWith("the w3") || editor.text().toLowerCase().startsWith("(see ac") || editor.text().toLowerCase().startsWith("see participants") || editor.text().toLowerCase().contains("note:")) { Log.log("warning", "Spec " + url + " may refer to a different section!"); continue; } if (editor.text().equals("WHATWG:") || editor.text().equals("W3C:")) continue; Person result = NameParser.parse(editor.text()); if (result == null) continue; for (int i = 0; i < editor.select("a").size(); i++) { if (!editor.select("a").get(i).attr("href").isEmpty()) { if (editor.select("a").get(i).attr("href").contains("@")) { result.setEmail(editor.select("a").get(i).attr("href").replace("mailto:", "")); } else { result.addWebsite(editor.select("a").get(i).attr("href")); } } } editorList.add(result); } else { for (String split : splitted) { if (!split.isEmpty()) { if (split.toLowerCase().startsWith("(in alphabetic") || split.toLowerCase().startsWith("see acknowl") || split.toLowerCase().startsWith("the w3") || split.toLowerCase().startsWith("(see ac") || split.toLowerCase().startsWith("see participants") || split.toLowerCase().contains("note:")) { Log.log("warning", "Spec " + url + " may refer to a different section!"); continue; } if (split.equals("WHATWG:") || split.equals("W3C:")) continue; Document newdoc = Jsoup.parse(split.replaceAll("\n", "")); Person result = NameParser.parse(newdoc.text()); if (result == null) continue; for (int i = 0; i < newdoc.select("a").size(); i++) { if (!newdoc.select("a").get(i).attr("href").isEmpty()) { if (newdoc.select("a").get(i).attr("href").contains("@")) { result.setEmail(newdoc.select("a").get(i).attr("href").replace("mailto:", "")); } else { result.addWebsite(newdoc.select("a").get(i).attr("href")); } } } editorList.add(result); } } } Element next = editor.nextElementSibling(); if (next != null) if (next.tag().getName().equals("dt")) break; } if (editorList.size() == 0) return null; return editorList; }
From source file:edu.utah.further.core.xml.UTestGenericJaxbMapAdapter.java
@Test public void marshallTransferObjectWithMap() throws JAXBException { final Map<String, String> map = CollectionUtil.newMap(); map.put("1", "One"); map.put("2", "Two"); final TransferObjectWithMap transferObjectWithMap = new TransferObjectWithMap(); transferObjectWithMap.setProperties(map); final XmlService xmlService = new XmlServiceImpl(); final String marshalled = xmlService.marshal(transferObjectWithMap); assertThat(new Integer(StringUtils.countMatches(marshalled, "<entry>")), is(new Integer(2))); assertThat(new Integer(StringUtils.countMatches(marshalled, "<key")), is(new Integer(2))); assertThat(new Integer(StringUtils.countMatches(marshalled, "<value")), is(new Integer(2))); assertThat(marshalled, containsString("One")); assertThat(marshalled, containsString("Two")); }
From source file:hudson.plugins.mantis.MantisLinkAnnotatorTest.java
/** * Test method for/*from ww w . j a va 2s .c om*/ * {@link hudson.plugins.mantis.MantisLinkAnnotator}. * @throws java.io.IOException */ @Test public void testAnnotator() throws IOException { MantisSite s = new MantisSite(new URL("http://bacons.ddo.jp/mantis/"), "V120", "jenkinsci", "jenkinsci", null, null); MantisProjectProperty.DESCRIPTOR.addSite(s); FreeStyleProject job = new FreeStyleProject(Jenkins.getInstance(), "testJob"); MantisProjectProperty mantisProp = new MantisProjectProperty(null, 0, null, null, "(?:issue |M#)([0-9,]+)", true); job.addProperty(mantisProp); job.save(); Build b = new FreeStyleBuild(job); b.addAction(new MantisBuildAction(Pattern.compile("(?:issue |M#)([0-9,]+)"), new MantisIssue[] { new MantisIssue(12345, "summary") })); b.save(); MarkupText mtext = new MarkupText( "mantis test M#0022560,0022540" + "M#0022560" + "blah blah blah blahhhh M#0022540 blah blah blah" + "blah blah blah blahhhh M#0022560,0022540 blah blah blah" + "issue 0022560,0022540" + "issue 0022560" + "blah blah blah blahhhh issue 0022540 blah blah blah" + "blah blah blah blahhhh issue 0022560,0022540 blah blah blah 123456 123457,14786"); MantisLinkAnnotator annotator = new MantisLinkAnnotator(); annotator.annotate(b, null, mtext); assertEquals(StringUtils.countMatches(mtext.toString(false), "href"), 12); assertEquals(StringUtils.countMatches(mtext.toString(false), "tooltip"), 12); }
From source file:com.edgenius.wiki.render.filter.NewlineFilter.java
@Override public void replace(StringBuffer buffer, MatchResult matchResult, RenderContext context) { String all = matchResult.group(0); // space, \t \r etc. String prefix = matchResult.group(1); //remove all \r but keep space or \t etc prefix = prefix.replaceAll("\\r", ""); buffer.append(prefix);/*from w ww . j a v a 2s . c o m*/ int count = StringUtils.countMatches(all, NEWLINE); if (buffer.length() >= WikiConstants.UUID_KEY_SIZE - 1 && context .isUniqueKey(buffer.substring(buffer.length() - WikiConstants.UUID_KEY_SIZE + 1) + "\n")) { if (count == 1) { buffer.append(all); return; } else { buffer.append("\n"); count--; } } //TODO: bug: if before newline, there is a region, which will be replaced to a string. how to detect isEndByBlockHtmlTag()? //if it is after a block HTML, such as after Hr, page needn't append the first br. //if following tag is Block html tag or not, it does not matter if there are br or not. //I checked in FF3, the Block HTML tag will ignore its the first <br> before it. if (RenderUtil.isEndByBlockHtmlTag(buffer)) { count--; //TinyMCE eat "\n" //but, keep this "\n" information to render text, it is useful in RichTag render buffer.append(NEWLINE_HIDDEN_TAG).append("</span>"); } int para = count / 2; for (int idx = 0; idx < para; idx++) { if (buffer.length() == 0) { //for any empty new lines on the beginning of content, use <br> instead <p> //The reason do so, is, in rich to markup convert, first <p> at text begin will be ignore buffer.append(NEWLINE_TAG).append(NEWLINE_TAG); } else { //can not user <p class="xxx"/> to replace <p class="xxx"></p>, at least FF show wrong if use <p/> buffer.append(PARAGRAPH_TAG); } } int br = count % 2; if (br > 0) buffer.append(NEWLINE_TAG); }
From source file:com.sap.prd.mobile.ios.ota.lib.LibUtils.java
public static String replaceLast(String string, String searchString, String replaceString) { if (string == null || searchString == null || replaceString == null) { throw new NullPointerException(); }//from www . j a va2 s . c o m if (StringUtils.isEmpty(searchString)) { return string; } if (StringUtils.countMatches(string, searchString) <= 1) { return string.replace(searchString, replaceString); } else { int idx = string.lastIndexOf(searchString); return string.substring(0, idx) + string.substring(idx).replace(searchString, replaceString); } }