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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

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  w w w .ja  v a2s  .  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:gtu._work.etc.SqlReplacerUI.java

private void initGUI() {
    try {/*from w w  w .  jav a2s  . c  o  m*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(387, 246));
                    {
                        jTextArea1 = new JTextArea();
                        jScrollPane1.setViewportView(jTextArea1);
                        jTextArea1.setText("");
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                FlowLayout jPanel2Layout = new FlowLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("jPanel2", null, jPanel2, null);
                {
                    replaceFromText = new JTextField();
                    jPanel2.add(replaceFromText);
                    replaceFromText.setPreferredSize(new java.awt.Dimension(266, 22));
                }
                {
                    replaceToText = new JTextField();
                    jPanel2.add(replaceToText);
                    replaceToText.setPreferredSize(new java.awt.Dimension(266, 22));
                }
                {
                    execute = new JButton();
                    jPanel2.add(execute);
                    execute.setText("execute");
                    execute.setPreferredSize(new java.awt.Dimension(149, 42));
                    execute.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                String text = jTextArea1.getText();
                                if (StringUtils.isBlank(text)) {
                                    JCommonUtil._jOptionPane_showMessageDialog_error("area empty!");
                                    return;
                                }

                                String fromTxt = replaceFromText.getText();
                                String toTxt = StringUtils.defaultString(replaceToText.getText());
                                if (StringUtils.isBlank(fromTxt)) {
                                    JCommonUtil._jOptionPane_showMessageDialog_error("fromTxt empty!");
                                    return;
                                }

                                StringBuffer sb = new StringBuffer();
                                Pattern ptn = Pattern.compile("(.){0,1}" + fromTxt + "(.){0,1}",
                                        Pattern.CASE_INSENSITIVE);
                                Matcher mth = null;

                                String[] scopeStrs = { ",", " ", "(", ")", "[", "]" };
                                BufferedReader reader = new BufferedReader(new StringReader(text));

                                for (String line = null; (line = reader.readLine()) != null;) {
                                    mth = ptn.matcher(line);
                                    while (mth.find()) {
                                        String scope1 = mth.group(1);
                                        String scope2 = mth.group(2);
                                        boolean ok1 = scope1.length() == 0
                                                || StringUtils.indexOfAny(scope1, scopeStrs) != -1;
                                        boolean ok2 = scope2.length() == 0
                                                || StringUtils.indexOfAny(scope2, scopeStrs) != -1;
                                        if (ok1 && ok2) {
                                            mth.appendReplacement(sb, scope1 + toTxt + scope2);
                                        }
                                    }
                                    mth.appendTail(sb);
                                    sb.append("\n");
                                }

                                reader.close();
                                jTextArea1.setText(sb.toString());
                            } catch (Exception e) {
                                JCommonUtil.handleException(e);
                            }
                        }

                    });
                }
            }
        }
        pack();
        setSize(400, 300);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:ddf.catalog.pubsub.predicate.ContextualPredicate.java

private static boolean isBooleanOperator(String input) {
    int index = StringUtils.indexOfAny(input.trim().toLowerCase(),
            new String[] { "not", "and", "or", "&", "|" });

    return index == 0;
}

From source file:net.sourceforge.fenixedu.util.StringFormatter.java

/**
 * Finds the first index of a special character within the given string
 * after a start position./*  w  ww  .  j a  va2s. c o  m*/
 * 
 * @param string
 *            the string to check
 * @param startPos
 *            the position to start from
 * @return the first index of a special character
 */
private static int indexOfAnySpecChar(String string, int startPos) {
    return StringUtils.indexOfAny(string.substring(startPos), specialChars);
}

From source file:jos.parser.Parser.java

private void processProperty(String line, boolean appearance) {
    boolean ro = false;
    String getter = null;/* w w w .  ja v a  2s.c om*/

    line = cleanDeclaration(line);
    if (line.length() == 0) {
        return;
    }

    int p = line.indexOf(')');
    String sub = line.substring(0, p + 1);
    if (sub.indexOf("readonly") != -1) {
        ro = true;
    }
    int j = sub.indexOf("getter=");
    if (j != -1) {
        int k = StringUtils.indexOfAny(sub.substring(j + 1), ",)") + j + 1;
        // TODO check translation
        log("j=%d k=%d str=%s", j, k, sub);
        getter = sub.substring(j + 7, j + 7 + k - (j + 7));
    }

    final StringBuilder type = new StringBuilder();
    int i = p + 1;
    for (; i < line.length(); i++) {
        char c = line.charAt(i);
        if (!Character.isWhitespace(c)) {
            break;
        }
    }
    for (; i < line.length(); i++) {
        char c = line.charAt(i);
        if (Character.isWhitespace(c)) {
            break;
        }
        type.append(c);
    }

    for (; i < line.length(); i++) {
        char c = line.charAt(i);
        if (Character.isWhitespace(c) || c == '*') {
            continue;
        } else {
            break;
        }
    }
    final StringBuilder selector = new StringBuilder();
    for (; i < line.length(); i++) {
        char c = line.charAt(i);
        if (Character.isWhitespace(c) || c == ';') {
            break;
        }
        selector.append(c);
    }
    if (extraAnnotation != null) {
        gencs.println("\t/**");
        gencs.printf("\t * @%s", extraAnnotation);
        gencs.println();
        gencs.println("\t */");
    }
    if (appearance) {
        gencs.printf("\t@Appearance");
        gencs.println();
    }
    //gencs.printf("\t@Export(\"%s\")", selector);
    //gencs.println();

    final String retval = remapType(type.toString());
    //        gencs.printf("\tpublic %s %s;", retval, selector);
    //        gencs.println();
    //        gencs.println();

    if (getter != null) {
        gencs.printf("\t@Bind(\"" + getter + "\")");
        gencs.println();
    }
    gencs.printf("\t@Export(\"%s\")", selector.toString());
    gencs.println();
    gencs.printf("\tpublic %s get%s() {", retval, StringUtils.capitalize(selector.toString()));
    gencs.println();
    gencs.printf("\t\tthrow new RuntimeException();");
    gencs.println();
    gencs.printf("\t}");
    gencs.println();
    gencs.println();

    if (!ro) {
        gencs.printf("\t@Export(\"set%s:\")", StringUtils.capitalize(selector.toString()));
        gencs.println();
        gencs.printf("\tpublic void set%s(%s value) {", StringUtils.capitalize(selector.toString()), retval);
        gencs.println();
        gencs.printf("\t\tthrow new RuntimeException();");
        gencs.println();
        gencs.printf("\t}");
        gencs.println();
        gencs.println();
    }
}

From source file:com.edgenius.wiki.render.filter.ListFilter.java

/**
 * Adds a list to a buffer//from   ww w  .  ja v a 2 s  . c  o  m
 */
private void addList(StringBuffer buffer, BufferedReader reader) throws IOException {
    char[] lastBullet = new char[0];
    String line = null;
    String trimLine = null;
    boolean requireLiEnd = false;
    while ((line = reader.readLine()) != null) {
        if (StringUtils.trim(line).length() == 0) {
            //new empty line - end of list
            break;
        }
        //only trim leading spaces, keep tailed spaces
        trimLine = StringUtil.trimStartSpace(line);

        int bulletEnd = StringUtils.indexOfAny(trimLine, new String[] { " ", "\t" });
        if (bulletEnd < 1) {
            //if this line is not valid bullet line, then means this li has multiple lines...
            //please note, here append original line rather than trimmed and with newline - that eat by read.readLine()
            buffer.append("\n").append(line);
            continue;
        }

        String bStr = trimLine.substring(0, bulletEnd).trim();
        if (!bulletPattern.matcher(bStr).matches()) {
            //if this line is not valid bullet line, then means this li has multiple lines...
            //please note, here append original line rather than trimmed and with newline - that eat by read.readLine()
            buffer.append("\n").append(line);
            continue;
        }

        //remove the possible dot, for example, #i. 
        if (bStr.charAt(bStr.length() - 1) == '.') {
            bStr = bStr.substring(0, bStr.length() - 1);
        }

        char[] bullet = bStr.toCharArray();
        if (requireLiEnd) {
            buffer.append("</li>");
            requireLiEnd = false;
        }

        // check whether we find a new sub list, for example 
        //* list
        //** sublist
        int sharedPrefixEnd;
        for (sharedPrefixEnd = 0;; sharedPrefixEnd++) {
            if (bullet.length <= sharedPrefixEnd || lastBullet.length <= sharedPrefixEnd
                    || bullet[sharedPrefixEnd] != lastBullet[sharedPrefixEnd]) {
                break;
            }
        }

        for (int i = sharedPrefixEnd; i < lastBullet.length; i++) {
            // Logger.log("closing " + lastBullet[i]);
            buffer.append(closeList.get(Character.valueOf(lastBullet[i])));
        }

        for (int i = sharedPrefixEnd; i < bullet.length; i++) {
            // Logger.log("opening " + bullet[i]);
            buffer.append(openList.get(Character.valueOf(bullet[i])));
        }
        buffer.append("<li>");
        buffer.append(trimLine.substring(StringUtils.indexOfAny(trimLine, new String[] { " ", "\t" }) + 1));
        requireLiEnd = true;
        lastBullet = bullet;
    }

    if (requireLiEnd) {
        buffer.append("</li>");
    }
    for (int i = lastBullet.length - 1; i >= 0; i--) {
        buffer.append(closeList.get(Character.valueOf(lastBullet[i])));
    }

}

From source file:com.google.gdt.eclipse.designer.builders.GwtBuilder.java

/**
 * Removes annotations of service {@link TypeDeclaration}.
 *//*from w  w w . j ava2 s .  c o m*/
private static void removeAnnotations(TypeDeclaration serviceType, String source, MultiTextEdit edits) {
    int typePos = serviceType.getStartPosition();
    {
        Javadoc javadoc = serviceType.getJavadoc();
        if (javadoc != null) {
            typePos = javadoc.getStartPosition() + javadoc.getLength();
            while (Character.isWhitespace(source.charAt(typePos))) {
                typePos++;
            }
        }
    }
    int pureTypePos = StringUtils.indexOfAny(source,
            new String[] { "public ", "protected ", "class ", "interface " });
    if (pureTypePos != -1 && pureTypePos != typePos) {
        edits.addChild(new DeleteEdit(typePos, pureTypePos - typePos));
    }
}

From source file:org.apache.archiva.repository.metadata.MetadataTools.java

private boolean hasNumberAnywhere(String version) {
    return StringUtils.indexOfAny(version, NUMS) != (-1);
}

From source file:org.apache.cocoon.generation.JXTemplateGenerator.java

private static Locale parseLocale(String locale, String variant) {
    Locale ret = null;/*w  ww  .j  ava  2 s.c  om*/
    String language = locale;
    String country = null;
    int index = StringUtils.indexOfAny(locale, "-_");

    if (index > -1) {
        language = locale.substring(0, index);
        country = locale.substring(index + 1);
    }
    if (StringUtils.isEmpty(language)) {
        throw new IllegalArgumentException("No language in locale");
    }
    if (country == null) {
        ret = variant != null ? new Locale(language, "", variant) : new Locale(language, "");
    } else if (country.length() > 0) {
        ret = variant != null ? new Locale(language, country, variant) : new Locale(language, country);
    } else {
        throw new IllegalArgumentException("Empty country in locale");
    }
    return ret;
}

From source file:org.apache.cocoon.template.environment.ValueHelper.java

public static Locale parseLocale(String locale, String variant) {
    Locale ret = null;//from  w w  w  .j  a va2  s .co  m
    String language = locale;
    String country = null;
    int index = StringUtils.indexOfAny(locale, "-_");

    if (index > -1) {
        language = locale.substring(0, index);
        country = locale.substring(index + 1);
    }
    if (StringUtils.isEmpty(language)) {
        throw new IllegalArgumentException("No language in locale");
    }
    if (country == null) {
        ret = variant != null ? new Locale(language, "", variant) : new Locale(language, "");
    } else if (country.length() > 0) {
        ret = variant != null ? new Locale(language, country, variant) : new Locale(language, country);
    } else {
        throw new IllegalArgumentException("Empty country in locale");
    }
    return ret;
}