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:org.rythmengine.internal.TemplateParser.java

public TemplateParser(CodeBuilder cb) {
    this.template = cb.template();
    totalLines = StringUtils.countMatches(template, "\n") + 1;
    this.cb = cb;
    this.engine = cb.engine();
    this.conf = this.engine.conf();
    this.compactMode = this.conf.compactModeEnabled();
    pushCodeType(cb.templateDefLang);/*  w w w . ja v a  2 s . com*/
}

From source file:org.rythmengine.internal.TemplateParser.java

@Override
public int currentLine() {
    if (null == template)
        return -1; // for testing purpose only
    if (cursor >= template.length())
        return totalLines;
    //return template.substring(0, cursor).split("(\\r\\n|\\n|\\r)").length;
    return StringUtils.countMatches(template.substring(0, cursor), "\n") + 1;
}

From source file:org.search.system.calc.RangCalc.java

public static long calc(String keyword, String description) {
    long count = StringUtils.countMatches(keyword, description);
    long words = description.split(" ").length;
    return (long) count / words;
}

From source file:org.segrada.util.FlexibleDateParser.java

/**
 * Parse input to Julian Day number//  w  w w  . ja  va 2s  .c o m
 * @param input string
 * @param type calendar type, e.g. "G" or "J"
 * @param high true to get last instance of parsed time, first otherwise
 * @return julian day number
 */
public Long inputToJd(@Nullable String input, String type, boolean high) {
    // sanity check
    if (input == null || "".equals(input))
        return high ? Long.MAX_VALUE : Long.MIN_VALUE;

    try {
        DateTime date = inputFormatter.withChronology(getChronologyFromType(type))
                .withLocale(Locale.getDefault()).withZoneUTC().parseDateTime(input);

        // get last time instance of the input
        if (high) {
            // guess input pattern by counting character occurences
            int count = Math.max(StringUtils.countMatches(input, "."),
                    Math.max(StringUtils.countMatches(input, "/"), StringUtils.countMatches(input, "-")));

            if (count == 0) // year only
                date = date.withMonthOfYear(12).withDayOfMonth(31);
            else if (count == 1) { // year/month
                date = date.withDayOfMonth(date.dayOfMonth().getMaximumValue());
            } // day/month/year as is
        }

        return DateTimeUtils.toJulianDayNumber(date.getMillis());
    } catch (Exception e) {
        logger.warn("Could not parse to DateTime: " + input + " (type = " + type + ")", e);
    }
    return null;
}

From source file:org.semanticscience.narf.structures.parts.Sequence.java

/**
 * The GC Content for the nucleotide sequence
 * @return the gc constant value//from   w w w.ja v a  2  s  .c  om
 */
public double getGCContent() {
    double g = StringUtils.countMatches(this.getSequenceString(), "G") * 1.0;
    double c = StringUtils.countMatches(this.getSequenceString(), "C") * 1.0;
    double t = StringUtils.countMatches(this.getSequenceString(), "T") * 1.0;
    double u = StringUtils.countMatches(this.getSequenceString(), "U") * 1.0;
    double a = StringUtils.countMatches(this.getSequenceString(), "A") * 1.0;

    if (u == 0) {//if dna
        double q = a + t + g + c;
        double s = t / q;
        return s * 100;
    } else if (t == 0) {//if rna
        return ((g + c) / (a + g + u + c)) * 100;
    } else {
        return ((g + c) / (a + g + u + t + c)) * 100;
    }
}

From source file:org.semanticscience.narf.structures.parts.Sequence.java

public int getGuanineCount() {
    return StringUtils.countMatches(this.getSequenceString(), "G");
}

From source file:org.semanticscience.narf.structures.parts.Sequence.java

public int getCytosineCount() {
    return StringUtils.countMatches(this.getSequenceString(), "C");
}

From source file:org.semanticscience.narf.structures.parts.Sequence.java

public int getAdenineCount() {
    return StringUtils.countMatches(this.getSequenceString(), "A");
}

From source file:org.semanticscience.narf.structures.parts.Sequence.java

public int getUracilCount() {
    return StringUtils.countMatches(this.getSequenceString(), "U");
}

From source file:org.semanticscience.narf.structures.parts.Sequence.java

public int getThymineCount() {
    return StringUtils.countMatches(this.getSequenceString(), "T");
}