Example usage for org.apache.commons.lang3 StringUtils countMatches

List of usage examples for org.apache.commons.lang3 StringUtils countMatches

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils countMatches.

Prototype

public static int countMatches(final CharSequence str, final char ch) 

Source Link

Document

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 

Usage

From source file:logfilegenerator.loglineanalyser.modules.Cluster.java

public Cluster(int clusterCount, String cluster) {
    super();//  w  w w  . j  a va 2 s .  co m
    this.setClusterID(clusterCount);
    this.setDescr(cluster);
    this.setRegex(generateRegexFromDescription(cluster));
    this.setClusterValue(calculateClusterValue(cluster));
    this.logLines = new LogLineManager();
    this.mostAccurateLogLines = new LogLineManager();
    this.timeStampDistribution = new ArrayList<Long>();
    this.numberOfWildcards = StringUtils.countMatches(this.getDescr(), "<*");
}

From source file:net.sf.dynamicreports.report.builder.chart.SeriesOrderByNamesComparator.java

@Override
public int compare(String o1, String o2) {
    String row1;//from w  w  w. j  a v a2 s.  c  om
    String row2;
    if (StringUtils.countMatches(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY) == 1
            && StringUtils.countMatches(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY) == 1) {
        String group1 = StringUtils.substringBefore(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
        String group2 = StringUtils.substringBefore(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
        int compare = group1.compareTo(group2);
        if (compare != 0) {
            return compare;
        }
        row1 = StringUtils.substringAfter(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
        row2 = StringUtils.substringAfter(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
    } else {
        row1 = o1;
        row2 = o2;
    }
    int index1 = seriesNames.indexOf(row1);
    int index2 = seriesNames.indexOf(row2);
    if (index1 < 0 && index2 < 0) {
        return row1.compareTo(row2);
    }
    if (index1 == index2) {
        return 0;
    }
    if (index1 < 0) {
        return index1 * -1;
    }
    if (index2 < 0) {
        return index2;
    }
    return index1 - index2;
}

From source file:de.knightsoftnet.mtwidgets.client.ui.widget.oracle.PhoneNumberCommonRestOracle.java

@Override
protected boolean needSuggest(final String pentry) {
    return StringUtils.isNotEmpty(pentry)
            && (pentry.charAt(0) != '0' && StringUtils.countMatches(pentry, " ") < 2
                    || pentry.charAt(0) == '0' && !StringUtils.contains(pentry, '/'));
}

From source file:de.knightsoftnet.mtwidgets.client.ui.widget.oracle.PhoneNumberDin5008RestOracle.java

@Override
protected boolean needSuggest(final String pentry) {
    return StringUtils.isNotEmpty(pentry)
            && (pentry.charAt(0) != '0' && StringUtils.countMatches(pentry, " ") < 2
                    || pentry.charAt(0) == '0' && !StringUtils.contains(pentry, ' '));
}

From source file:com.monarchapis.driver.authentication.JwtClaimsProcessor.java

@Override
public ObjectNode getClaims(HttpServletRequest request) {
    if (StringUtils.isBlank(jwtKey)) {
        return null;
    }/*from   w  ww .  j a  va 2  s.com*/

    String authorization = request.getHeader("Authorization");

    if (authorization != null && StringUtils.startsWithIgnoreCase(authorization, "Bearer ")) {
        String jwt = authorization.substring(7).trim();

        if (StringUtils.countMatches(jwt, ".") == 2) {
            try {
                return getClaims(jwt);
            } catch (Exception e) {
                logger.warn("Could not parse JWT token", e);
            }
        }
    }

    return null;
}

From source file:com.voodoodyne.hattery.test.AppEngineTest.java

/** */
@Test/*from w ww  .ja v  a  2 s  .  c  o m*/
public void timesOutAndRetries() throws Exception {
    configSystemOutForTest();
    HttpRequest request = null;

    try {
        request = transport.request().url("http://voodoodyne0.appspot.com/timeout").param("time", "4")
                .timeout(1000).retries(5);
        request.fetch().as(Foo.class);
        assertThat(true, equalTo(false)); //Should fail if gets here
    } catch (IORException e) {
        assertThat(StringUtils.countMatches(outContent.toString(), "Timeout error, retrying"), equalTo(5));
    } finally {
        resetSystemOutTest();
    }
}

From source file:br.com.fidias.chance4j.text.ParagraphTest.java

@Test
public void randomParagraphFiveSentences() throws ChanceException {
    final int numSentences = 5;
    for (int i = 0; i < 1000; i++) {
        paragraph = chance.paragraph(numSentences);
        String replaceChars = StringUtils.replaceChars(paragraph, PUNCTUATION, replaceSymbols);
        int countMatches = StringUtils.countMatches(replaceChars, '_');
        assertTrue("random paragraph 5 sentences", countMatches == 5);
    }/*  w ww  .j  a v  a2  s  .  com*/
}

From source file:it.cnr.ilc.latmorphwebapp.ProxyHandler.java

private String addContextPath(FacesContext context, String url) {
    final HttpServletRequest request = ((HttpServletRequest) context.getExternalContext().getRequest());
    String result = url;/*from w w  w .  j a  v  a2s  .  c o  m*/
    if (url.startsWith("/")) {
        int subpath = StringUtils.countMatches(getPath(request), "/") - 1;
        String pathPrefix = "";
        if (subpath > 0) {
            while (subpath > 0) {
                pathPrefix += "/..";
                subpath--;
            }
            pathPrefix = StringUtils.removeStart(pathPrefix, "/");
        }
        result = pathPrefix + result;
    }
    log.debug("addContextPath: = " + result);
    return result;
}

From source file:de.uni.bremen.monty.moco.ast.expression.literal.StringLiteral.java

/** @param value
 * @return *///from w  w  w  .  j  ava 2s.  c  o  m
public static int getStrLiteralLength(String value) {
    // every backslash is followed by two numbers, but those three characters
    // represent only one char in the IR string literal
    return value.length() - (StringUtils.countMatches(value, "\\") * 2);
}

From source file:com.ibm.util.merge.web.rest.servlet.handler.GetMergeOutputHtmlResourceHandler.java

@Override
public Result handle(RequestData rd) {
    Long start = System.currentTimeMillis();
    HashMap<String, String[]> parameterMap = new HashMap<String, String[]>(rd.getParameterMap());

    // add trailing "." to create full name when needed
    String fullname = rd.getPathParts().get(1);
    if (StringUtils.countMatches(fullname, ".") < 1) {
        fullname += ".";
    }//from  www  . j a v a2  s  .  c o  m
    if (StringUtils.countMatches(fullname, ".") < 2) {
        fullname += ".";
    }
    parameterMap.put("DragonFlyFullName", new String[] { fullname });

    // Perform the merge
    try {
        String result = tf.getMergeOutput(parameterMap);
        long elapsed = System.currentTimeMillis() - start;
        log.warn(String.format("Merge completed in %d milliseconds", elapsed));
        return new HtmlResult(result);
    } catch (MergeException e) {
        return new HtmlErrorResult(e, tf, errTemplate);
    }
}