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

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

Introduction

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

Prototype

public static int lastIndexOfAny(String str, String[] searchStrs) 

Source Link

Document

Find the latest index of any of a set of potential substrings.

Usage

From source file:com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider.java

private static String getLastWordWithArithmeticOperation(String word) {
    if (!word.contains("'")) {
        int operationIdx = StringUtils.lastIndexOfAny(word, ARITHMETIC_OPERATIONS);
        if (operationIdx >= 0 && operationIdx < word.length()) {
            return word.substring(operationIdx + 1);
        }//from   w  w  w . j  a v  a 2s . com
    }
    return word;
}

From source file:com.processpuzzle.application.configuration.domain.ParametrizedConfigurationPropertyHandler.java

private void determineSelectorSegments() {
    int positionOfComparisonOperator = StringUtils.indexOfAny(parametrizedSelector, COMPARISON_OPERATORS);
    int positionOfConditionBegin = StringUtils.lastIndexOfAny(
            StringUtils.substring(parametrizedSelector, 0, positionOfComparisonOperator),
            ANY_SELECTOR_SEGMENT_DELIMITER);
    int positionOfConditionEnd = StringUtils.indexOfAny(
            StringUtils.substring(parametrizedSelector, positionOfComparisonOperator + 1),
            ANY_SELECTOR_SEGMENT_DELIMITER) + positionOfComparisonOperator + 1;

    conditionSegment = StringUtils.substring(parametrizedSelector, positionOfConditionBegin + 1,
            positionOfConditionEnd);//from www .j  av  a 2s.c  om
    selectorBeforeCondition = StringUtils.substring(parametrizedSelector, 0, positionOfConditionBegin);
    selectorAfterCondition = StringUtils.substring(parametrizedSelector, positionOfConditionEnd + 1);
    conditionPropery = StringUtils.substring(conditionSegment, 0,
            positionOfComparisonOperator - positionOfConditionBegin - 1);
    if (conditionPropery.contains(PropertyContext.ATTRIBUTE_SIGNER))
        conditionPropery = PropertyContext.ATTRIBUTE_BEGIN + conditionPropery + PropertyContext.ATTRIBUTE_END;

    conditionValue = StringUtils.substring(conditionSegment,
            positionOfComparisonOperator - positionOfConditionBegin);
    if (conditionValue.startsWith("'") || conditionValue.startsWith("\""))
        ;
    conditionValue = StringUtils.substring(conditionValue, 1, conditionValue.length() - 1);
}

From source file:adalid.commons.velocity.Writer.java

private void checkPropertyName(String name, File file) {
    String pattern = "invalid property name \"{0}\" at file \"{1}\"";
    String message = MessageFormat.format(pattern, StringUtils.trimToEmpty(name), file);
    if (StringUtils.isBlank(name)) {
        throw new RuntimeException(message);
    }//w  w  w  . ja v a2 s .c o  m
    String low = name.toLowerCase();
    if (StringUtils.endsWithAny(low, DOT_SUFFIXES)) {
        int endIndex = StringUtils.lastIndexOfAny(low, DOT_SUFFIXES);
        if (endIndex == 0) {
            throw new RuntimeException(message);
        }
    }
}

From source file:org.apache.rat.document.impl.guesser.GuessUtils.java

/**
 * Converts name to upper case and strips any path.
 * @param name not null/*  w ww . j  a v  a  2 s  .  com*/
 * @return not null
 */
public static final String normalise(final String name) {
    String result = name.toUpperCase(Locale.US);
    final int lastSeparatorIndex = StringUtils.lastIndexOfAny(result, SEPARATORS);
    final int length = result.length();
    if (lastSeparatorIndex >= 0 && lastSeparatorIndex < length) {
        result = result.substring(lastSeparatorIndex + 1);
    }
    return result;
}

From source file:org.apache.torque.ColumnImpl.java

/**
 * Constructor which tries to guess schema, table and column names from
 * an SQL expression. If a schema name can be identified in the
 * SQL expression, it is removed from the SQL expression in the column.
 *
 * @param sqlExpression the SQL expression, not null, not blank.
 *
 * @throws NullPointerException if sqlExpression is null.
 * @throws IllegalArgumentException if table or column name cannot be
 *         guessed from sqlExpression.//w w  w .j a  v  a  2s  .  c om
 */
public ColumnImpl(String sqlExpression) {
    setSqlExpression(sqlExpression);

    // Find Table.Column
    int dotIndex = sqlExpression.lastIndexOf(DOT);
    if (dotIndex == -1) {
        if (StringUtils.contains(sqlExpression, "*")) {
            return;
        }
        if (StringUtils.indexOfAny(sqlExpression, FUNCTION_DELIMITERS) != -1) {
            throw new IllegalArgumentException("sqlExpression " + sqlExpression
                    + " is unparseable, it does not contain a dot (.) " + " but function delimiters.");
        }
        setColumnName(sqlExpression);
        return;
    }
    String pre = sqlExpression.substring(0, dotIndex);
    String post = sqlExpression.substring(dotIndex + 1, sqlExpression.length());
    if (StringUtils.isBlank(pre)) {
        throw new IllegalArgumentException("sqlExpression " + sqlExpression + " is blank before the dot (.)");
    }
    int startIndex = StringUtils.lastIndexOfAny(pre, FUNCTION_DELIMITERS);
    int endIndex = StringUtils.indexOfAny(post, FUNCTION_DELIMITERS);
    if (endIndex < 0) {
        endIndex = sqlExpression.length();
    } else {
        // relative to sqlExpression not to post
        endIndex += dotIndex + 1;
    }

    if (startIndex + 1 == dotIndex) {
        throw new IllegalArgumentException(
                "sqlExpression " + sqlExpression + " is blank between the last function delimiter ("
                        + StringUtils.join(FUNCTION_DELIMITERS) + ") and the dot");
    }
    setColumnName(sqlExpression.substring(dotIndex + 1, endIndex));
    // if startIndex == -1 the formula is correct
    String fullTableName = sqlExpression.substring(startIndex + 1, dotIndex);
    setTableName(fullTableName);
    if (fullTableName.contains(DOT)) {
        int fullTableNameDotIndex = fullTableName.lastIndexOf(DOT);
        String extractedSchemaName = fullTableName.substring(0, fullTableNameDotIndex);
        setSchemaName(extractedSchemaName);
        StringBuilder sqlExpressionBuilder = new StringBuilder();
        if (startIndex != -1) {
            sqlExpressionBuilder.append(sqlExpression.substring(0, startIndex + 1));
        }
        sqlExpressionBuilder.append(getTableName()).append(DOT).append(post);
        setSqlExpression(sqlExpressionBuilder.toString());
    }
}

From source file:org.apache.torque.util.SQLBuilder.java

/**
 * Removes a possible function name or clause from a column name
 *
 * @param  name  The column name, possibly containing a clause
 *
 * @return  The column name/* www.j a v a 2  s  .  c  o m*/
 *
 * @throws  TorqueException  If the column name was malformed
 */
private static String removeSQLFunction(final String name) throws TorqueException {
    // Empty name => return it
    if (StringUtils.isEmpty(name)) {
        return name;
    }

    // Find Table.Column
    int dotIndex = name.indexOf('.');
    if (dotIndex == -1) {
        dotIndex = name.indexOf("*");
    }
    if (dotIndex == -1) {
        throw new TorqueException("removeSQLFunction() : Column name " + name + " does not contain a . or a *");
    }
    String pre = name.substring(0, dotIndex);
    String post = name.substring(dotIndex + 1, name.length());
    int startIndex = StringUtils.lastIndexOfAny(pre, DELIMITERS);
    int endIndex = StringUtils.indexOfAny(post, DELIMITERS);
    if (startIndex < 0 && endIndex < 0) {
        return name;
    } else {
        if (endIndex < 0) {
            endIndex = post.length();
        }
        // if startIndex == -1 the formula is correct
        return name.substring(startIndex + 1, dotIndex + 1 + endIndex);
    }
}

From source file:org.codice.ddf.persistence.PersistentItem.java

public static Map<String, Object> stripSuffixes(Map<String, Object> inMap) {
    Map<String, Object> outMap = new HashMap<>();
    for (Map.Entry<String, Object> entry : inMap.entrySet()) {
        int index = StringUtils.lastIndexOfAny(entry.getKey(), SUFFIXES);
        if (index > 0) {
            String newKey = entry.getKey().substring(0, index);
            outMap.put(newKey, entry.getValue());
        } else { // should this ever be executed?
            outMap.put(entry.getKey(), entry.getValue());
        }//w w w.  j  a v  a  2 s . c om
    }

    return outMap;
}

From source file:org.codice.solr.query.SchemaFieldResolver.java

public SchemaField getSchemaField(String propertyName, boolean isSearchedAsExactValue) {
    SchemaField schemaField = null;/*  ww  w . j  a va  2s. c o m*/
    LukeRequest luke = new LukeRequest();
    LukeResponse rsp;
    try {
        rsp = luke.process(solr);
        Map<String, FieldInfo> fieldsInfo = rsp.getFieldInfo();
        if (fieldsInfo != null && !fieldsInfo.isEmpty()) {
            LOGGER.info("got fieldsInfo for {} fields", fieldsInfo.size());

            for (Map.Entry<String, FieldInfo> entry : fieldsInfo.entrySet()) {

                // See if any fieldName startsWith(propertyName)
                // if it does, then see if remainder of fieldName matches any expected suffix
                // if suffix matches, then get type of field and cache it
                if (entry.getKey().startsWith(propertyName)
                        && StringUtils.endsWithAny(entry.getKey(), FORMAT_SUFFIXES)) {
                    String fieldType = entry.getValue().getType();
                    int index = StringUtils.lastIndexOfAny(entry.getKey(), FORMAT_SUFFIXES);
                    String suffix = entry.getKey().substring(index);
                    if (!isSearchedAsExactValue) {
                        suffix = getSpecialIndexSuffix(suffix);
                        fieldType += suffix;
                    }
                    LOGGER.info("field {} has type {}", entry.getKey(), fieldType);
                    schemaField = new SchemaField(entry.getKey(), fieldType);
                    schemaField.setSuffix(suffix);
                    return schemaField;
                }
            }
        } else {
            LOGGER.info("fieldsInfo from LukeRequest are either null or empty");
        }

    } catch (SolrServerException e) {
        LOGGER.info("SolrServerException while processing LukeRequest", e);
    } catch (IOException e) {
        LOGGER.info("IOException while processing LukeRequest", e);
    }

    LOGGER.info("Did not find SchemaField for property {}", propertyName);

    return schemaField;
}

From source file:org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java

/**
 * Returns the short name of fully qualified class name, or same name for simple type name.
 * //from   w  w w .ja  va2  s. co  m
 * <pre>
  * CodeUtils.getShortClass("javax.swing.JPanel")  = "JPanel"
  * CodeUtils.getShortClass("test.MyPanel$Inner")  = "Inner"
  * CodeUtils.getShortClass("boolean")             = "boolean"
  * </pre>
 * 
 * @param className
 *          the fully qualified class name.
 * 
 * @return the short name of given class name.
 */
public static String getShortClass(String className) {
    int index = StringUtils.lastIndexOfAny(className, new String[] { ".", "$" });
    if (index != -1) {
        return className.substring(index + 1);
    }
    return className;
}