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.bazaarvoice.jolt.shiftr.spec.ShiftrSpec.java
public static List<PathElement> parse(String key) { if (key.contains("@")) { return Arrays.<PathElement>asList(new AtPathElement(key)); } else if (key.contains("$")) { return Arrays.<PathElement>asList(new DollarPathElement(key)); } else if (key.contains("[")) { if (StringUtils.countMatches(key, "[") != 1 || StringUtils.countMatches(key, "]") != 1) { throw new SpecException("Invalid key:" + key + " has too many [] references."); }/*w w w. j a v a2s .co m*/ // is canonical array? if (key.charAt(0) == '[' && key.charAt(key.length() - 1) == ']') { return Arrays.<PathElement>asList(new ArrayPathElement(key)); } // Split syntactic sugar of "photos[]" --> [ "photos", "[]" ] // or "bob-&(3,1)-smith[&0]" --> [ "bob-&(3,1)-smith", "[&(0,0)]" ] String canonicalKey = key.replace("[", ".["); String[] subkeys = canonicalKey.split("\\."); List<PathElement> subElements = parse(subkeys); // at this point each sub key should be a valid key, so just recall parse for (int index = 0; index < subElements.size() - 1; index++) { PathElement v = subElements.get(index); if (v instanceof ArrayPathElement) { throw new SpecException("Array [..] must be the last thing in the key, was:" + key); } } return subElements; } else if (key.contains("&")) { if (key.contains("*")) { throw new SpecException("Can't mix * with & ) "); } return Arrays.<PathElement>asList(new AmpPathElement(key)); } else if ("*".equals(key)) { return Arrays.<PathElement>asList(new StarAllPathElement(key)); } else if (StringUtils.countMatches(key, "*") == 1) { return Arrays.<PathElement>asList(new StarSinglePathElement(key)); } else if (key.contains("*")) { return Arrays.<PathElement>asList(new StarRegexPathElement(key)); } else { return Arrays.<PathElement>asList(new LiteralPathElement(key)); } }
From source file:com.sec.ose.airs.service.protex.ProtexIdentificationInfoService.java
public String extractIdentificationInfoStringFromComment(String comment) { // minimum validation if (comment.contains(listDelimiter) && StringUtils.countMatches(comment, ProtexIdentificationInfo.SPDX_IDENTIFIED_DELIMETER) > 6) return comment.substring(0, comment.indexOf(listDelimiter)).trim(); return null;//from w ww. j av a 2 s.c om }
From source file:ai.grakn.test.graql.printer.GraqlPrinterTest.java
@Test public void whenGettingOutputForRelation_TheResultShouldHaveCommasBetweenRolePlayers() { Printer printer = Printers.graql(true); MatchQuery query = rule.graph().graql().match(var("r").isa("has-cluster")); Relation relation = query.get("r").iterator().next().asRelation(); int numRolePlayers = relation.rolePlayers().size(); int numCommas = numRolePlayers - 1; String relationString = printer.graqlString(relation); assertEquals(relationString + " should have " + numCommas + " commas separating role-players", numCommas, StringUtils.countMatches(relationString, ",")); }
From source file:ai.grakn.graql.internal.printer.GraqlPrinterTest.java
@Test public void whenGettingOutputForRelation_TheResultShouldHaveCommasBetweenRolePlayers() { Printer printer = Printers.graql(true); MatchQuery query = rule.graph().graql().match(var("r").isa("has-cluster")); Relation relation = query.get("r").iterator().next().asRelation(); long numRolePlayers = relation.rolePlayers().count(); long numCommas = numRolePlayers - 1; String relationString = printer.graqlString(relation); assertEquals(relationString + " should have " + numCommas + " commas separating role-players", numCommas, StringUtils.countMatches(relationString, ",")); }
From source file:de.fhg.iais.asc.transformer.jdom.handler.XmlFieldStripperTest.java
@Test public void testSampler2() throws Exception { Document xdoc = XmlProcessor.buildDocumentFrom(XML2); XmlFieldStripper s = new XmlFieldStripper(FIELDPATTERN, CONTENTPATTERN); xdoc = transform(s, xdoc);/* ww w . j a va 2 s . c o m*/ String output = XmlUtils.elementToString(true, xdoc.getRootElement()); System.out.println(output); final int p = StringUtils.countMatches(output, "MYTEXT"); Assert.assertTrue("Expected 1 strings 'MYTEXT', found " + p, p == 1); }
From source file:hudson.cli.DisablePluginCommandTest.java
@Test @Issue("JENKINS-27177") @WithPlugin({ "depender-0.0.2.hpi", "dependee-0.0.2.hpi", "mandatory-depender-0.0.2.hpi" }) public void canDisablePluginWithDependentsDisabledStrategyNone() throws IOException { disablePlugin("mandatory-depender"); CLICommandInvoker.Result result = disablePluginsCLiCommand("-strategy", "NONE", "dependee"); assertThat(result, succeeded());/*from w w w . j a va2 s .c o m*/ assertEquals("Disabling only dependee", 1, StringUtils.countMatches(result.stdout(), "Disabling")); assertPluginDisabled("dependee"); }
From source file:musite.ProteinsUtil.java
/** * * @param proteins// w w w . j a va 2s . co m * @param ptm * @param enzyme * @return */ public static int countSites(Proteins proteins, Set<AminoAcid> aminoAcids, PTM ptm, Set<String> enzymes) { if (proteins == null || aminoAcids == null || aminoAcids.isEmpty()) throw new IllegalArgumentException(); int count = 0; if (ptm == null) { // residue Iterator<Protein> it = proteins.proteinIterator(); Set<Character> aas = AminoAcid.oneLetters(aminoAcids); while (it.hasNext()) { Protein protein = it.next(); String proteinSeq = protein.getSequence().toUpperCase(); for (char aa : aas) { count += StringUtils.countMatches(proteinSeq, "" + aa); } } } else { Iterator<Protein> it = proteins.proteinIterator(); while (it.hasNext()) { Set<Integer> sites = PTMAnnotationUtil.getSites(it.next(), ptm, aminoAcids, enzymes); if (sites != null && !sites.isEmpty()) { count += sites.size(); } } } return count; }
From source file:com.jayway.jsonpath.JsonPath.java
public JsonPath(String jsonPath, Filter[] filters) { if (jsonPath == null || jsonPath.trim().length() == 0 || jsonPath.matches("[^\\?\\+\\=\\-\\*\\/\\!]\\(")) { throw new InvalidPathException("Invalid path"); }//from w w w .ja v a 2 s . c o m int filterCountInPath = StringUtils.countMatches(jsonPath, "[?]"); isTrue(filterCountInPath == filters.length, "Filters in path ([?]) does not match provided filters."); this.tokenizer = new PathTokenizer(jsonPath); this.filters = new LinkedList<Filter>(); this.filters.addAll(asList(filters)); }
From source file:loaders.LoadQueryTransformerTest.java
@Test public void testParamReordering() throws Exception { String query = "select id as id from user where id = ${param1} or id = ${param2} and id > ${param1}"; HashMap<String, Object> params = new HashMap<String, Object>(); AbstractDbDataLoader.QueryPack queryPack = prepareQuery(query, new BandData(""), params); System.out.println(queryPack.getQuery()); Assert.assertFalse(queryPack.getQuery().contains("${")); writeParams(queryPack);/*from w ww . jav a 2 s . c om*/ params.put("param1", "param1"); params.put("param2", "param2"); queryPack = prepareQuery(query, new BandData(""), params); System.out.println(queryPack.getQuery()); Assert.assertEquals(3, StringUtils.countMatches(queryPack.getQuery(), "?")); writeParams(queryPack); Assert.assertEquals("param1", queryPack.getParams()[0].getValue()); Assert.assertEquals("param2", queryPack.getParams()[1].getValue()); Assert.assertEquals("param1", queryPack.getParams()[2].getValue()); }
From source file:dpfmanager.shell.core.util.TextAreaAppender.java
@Override public void append(LogEvent event) { if (textArea != null) { Layout layout = this.getLayout(); Platform.runLater(new Runnable() { @Override/*from w ww. j a v a 2 s .c o m*/ public void run() { String message = new String(layout.toByteArray(event)); int count = StringUtils.countMatches(textArea.getText(), "\n"); if (count < maxLines && maxLines != 0) { textArea.appendText(message); } else { textArea.clear(); textArea.autosize(); textArea.appendText(message); } } }); } }