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

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

Introduction

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

Prototype

public static int countMatches(String str, String sub) 

Source Link

Document

Counts how many times the substring appears in the larger String.

Usage

From source file:org.pentaho.pms.mql.MappedQueryTest.java

/**
 * This test will make sure that the creation of the display query will not accidentally screw up the validity of the
 * query. <br/>/*from  www .  java 2 s .com*/
 * BISERVER-2881 was caused by a string replace of COL1 accidentally replacing COL10, COL11, COL12 (etc).
 */
@SuppressWarnings("deprecation")
public void testGetDisplayQuery() {
    // Get the display query based on the SAMPLE1 set of parameters
    final MappedQuery mappedQuery = new MappedQuery(SAMPLE1_SQL, SAMPLE1_MAP, null);
    final String result = mappedQuery.getDisplayQuery();

    // Each item in the map should be found once (and only once) in the resulting query
    for (String columnName : SAMPLE1_MAP.values()) {
        assertEquals("Error translating [" + columnName + "]", 1, StringUtils.countMatches(result, columnName));
    }
}

From source file:org.piwigo.remotesync.generator.WSJavaAPIWriter.java

protected void writeFile(String filePath, String transformed) throws IOException {
    BufferedReader reader = null;
    BufferedWriter writer = null;
    try {/*from  www .jav a 2s . c  o m*/
        reader = new BufferedReader(new StringReader(transformed));
        writer = new BufferedWriter(new FileWriter(getGenJavaFile(filePath)));
        String line = null;
        boolean CRLF = false;
        int level = 0;
        while ((line = reader.readLine()) != null) {
            level += StringUtils.countMatches(line, "{");
            level -= StringUtils.countMatches(line, "}");
            if (line.trim().length() == 0) {
                if (!CRLF & level < 2)
                    writer.newLine();
                CRLF = true;
            } else {
                CRLF = false;
                writer.write(line);
                writer.newLine();
            }
        }
        writer.flush();
    } catch (Exception e) {
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(writer);
    }
}

From source file:org.polymap.core.data.feature.lucene.LuceneQueryParser.java

protected Query processIsLike(PropertyIsLike predicate) {
    String literal = predicate.getLiteral();
    PropertyName prop = (PropertyName) predicate.getExpression();

    // value / type
    String fieldname = prop.getPropertyName();
    Class valueType = schema.getDescriptor(prop.getPropertyName()).getType().getBinding();
    Fieldable field = ValueCoder.encode(fieldname, literal, valueType, Field.Store.NO, true);
    String value = field.stringValue();

    value = StringUtils.replace(value, predicate.getWildCard(), "*");
    value = StringUtils.replace(value, predicate.getSingleChar(), "?");

    if (value.endsWith("*") && StringUtils.countMatches(value, "*") == 1
            && StringUtils.countMatches(value, "?") == 0) {
        return new PrefixQuery(new Term(fieldname, value.substring(0, value.length() - 1)));
    } else {//from   ww  w  .j a  va2s  .  c o m
        return new WildcardQuery(new Term(fieldname, value));
    }
}

From source file:org.polymap.core.runtime.recordstore.lucene.NumberValueCoder.java

public Query searchQuery(QueryExpression exp) {
    // EQUALS//from ww w  .j av  a  2 s .  c o m
    if (exp instanceof QueryExpression.Equal) {
        Equal equalExp = (QueryExpression.Equal) exp;

        if (equalExp.value instanceof String) {
            return new TermQuery(new Term(equalExp.key, (String) equalExp.value));
        } else if (equalExp.value instanceof Integer) {
            String formatted = nf.format(equalExp.value);
            return new TermQuery(new Term(equalExp.key, formatted));
        }
    }
    // MATCHES
    else if (exp instanceof QueryExpression.Match) {
        Match matchExp = (Match) exp;

        if (matchExp.value instanceof String) {
            String value = (String) matchExp.value;

            // FIXME properly substitute wildcard chars
            if (value.endsWith("*") && StringUtils.countMatches(value, "*") == 1
                    && StringUtils.countMatches(value, "?") == 0) {
                return new PrefixQuery(new Term(matchExp.key, value.substring(0, value.length() - 1)));
            } else {
                return new WildcardQuery(new Term(matchExp.key, value));
            }
        }
    }
    return null;
}

From source file:org.polymap.core.runtime.recordstore.lucene.StringValueCoder.java

public Query searchQuery(QueryExpression exp) {
    // EQUALS//from   w  w  w . j a  va 2s . c  om
    if (exp instanceof QueryExpression.Equal) {
        Equal equalExp = (QueryExpression.Equal) exp;

        if (equalExp.value instanceof String) {
            return new TermQuery(new Term(equalExp.key, (String) equalExp.value));
        }
    }
    // MATCHES
    else if (exp instanceof QueryExpression.Match) {
        Match matchExp = (Match) exp;

        if (matchExp.value instanceof String) {
            String value = (String) matchExp.value;

            // XXX properly substitute wildcard chars
            if (value.endsWith("*") && StringUtils.countMatches(value, "*") == 1
                    && StringUtils.countMatches(value, "?") == 0) {
                return new PrefixQuery(new Term(matchExp.key, value.substring(0, value.length() - 1)));
            } else {
                return new WildcardQuery(new Term(matchExp.key, value));
            }
        }
    }
    return null;
}

From source file:org.projectforge.business.user.UserXmlPreferencesDao.java

private String getSourceClassName(String xml) {
    String[] elements = xml.split("\n");
    if (elements.length > 0) {
        String result = elements[0].replace("<", "").replace(">", "");
        if (StringUtils.countMatches(result, ".") > 1) {
            return result;
        }//  w w  w.j a  va 2s  .c om
    }
    return null;
}

From source file:org.protozoo.device.internal.Activator.java

@Override
public void start(BundleContext context) {

    String version = context.getBundle().getVersion().toString();
    // if the version string contains a qualifier, remove it!
    if (StringUtils.countMatches(version, ".") == 3) {
        version = StringUtils.substringBeforeLast(version, ".");
    }//from w  ww. jav  a  2 s .co m

    PingerFactory pf = new PingerFactory();
    pf.register(context);

    /*
            ca = context.getService(context.getServiceReference(ConfigurationAdmin.class));
            if (ca != null) {
    try {
        Configuration c = ca.createFactoryConfiguration(Pinger.class.getName());
        Hashtable props = new Hashtable();
        props.put("Frequency", 2.0f);
        c.update(props);
        System.out.println("Properties: " + c.getProperties());
    } catch (IOException ex) {
        java.util.logging.Logger.getLogger(Activator.class.getName()).log(Level.SEVERE, null, ex);
    }
            } else {
    System.out.println("ConfigAdmin = null");
            }
    */
    logger.info("Protozoo device runtime started (v{}).", version);

}

From source file:org.protozoo.driver.internal.Activator.java

@Override
public void start(BundleContext context) {

    String version = context.getBundle().getVersion().toString();
    // if the version string contains a qualifier, remove it!
    if (StringUtils.countMatches(version, ".") == 3) {
        version = StringUtils.substringBeforeLast(version, ".");
    }/* ww w  .  j  a v  a2 s .co m*/

    driver = new PingerDriver();
    driver.register(context);

    logger.info("Protozoo drivers started (v{}).", version);

}

From source file:org.protozoo.services.model.internal.Activator.java

@Override
public void start(BundleContext context) throws Exception {
    String version = context.getBundle().getVersion().toString();
    // if the version string contains a qualifier, remove it!
    if (StringUtils.countMatches(version, ".") == 3) {
        version = StringUtils.substringBeforeLast(version, ".");
    }//from   ww  w .  j a v  a  2  s. c  o  m

    logger.info("Protozoa model services started (v{}).", version);
}

From source file:org.protozoo.system.event.internal.Activator.java

@Override
public void start(BundleContext context) throws Exception {

    String version = context.getBundle().getVersion().toString();
    // if the version string contains a qualifier, remove it!
    if (StringUtils.countMatches(version, ".") == 3) {
        version = StringUtils.substringBeforeLast(version, ".");
    }/*from www  . j a va  2s . co m*/

    logger.info("Protozoo event runtime started (v{}).", version);

}