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

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

Introduction

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

Prototype

public static int length(String str) 

Source Link

Document

Gets a String's length or 0 if the String is null.

Usage

From source file:eu.annocultor.analyzers.SolrPropertyHitsAnalyzer.java

static String extractQuery(String line) {
    line = StringUtils.substringAfter(line, ", query=");
    String query = StringUtils.substringBefore(line, ", ");
    if (StringUtils.length(query) < 3) {
        // try referal
        query = StringUtils.substringAfter(line, ", referer=");
        query = StringUtils.substringAfter(query, "&q=");
        if (!StringUtils.isBlank(query)) {
            query = StringUtils.substringBefore(query, "&");
            query = StringUtils.replace(query, "+", " ");
            if (isLongEnoughToCount(query)) {
                return query;
            } else {
                return "";
            }//from  w w w.j  a  v a  2  s  .c om
        }
    }
    return query;
}

From source file:com.pedra.storefront.forms.validation.AddressValidator.java

protected static void validateStringField(final String addressField, final String addressFieldKey,
        final String fieldErrorMessage, final int maxFieldLength, final Errors errors) {
    if (StringUtils.isEmpty(addressField) || (StringUtils.length(addressField) > maxFieldLength)) {
        errors.rejectValue(addressFieldKey, fieldErrorMessage);
    }//from   ww w  .  j  a  v  a2s .co  m
}

From source file:com.zb.jcseg.util.WordUnionUtils.java

/**
 * ????//from  www.  j a  v  a  2 s  .c  om
 * 
 * @param segWords
 * @return
 */
@SuppressWarnings("unused")
public static List<String> wiselyCombineWords(List<String> segWords) {
    if (segWords.isEmpty()) {
        return segWords;
    }
    List<String> splitWordsList = new ArrayList<String>(segWords.size());
    StringBuilder sb = new StringBuilder();
    String candidate = "";
    String space = " ";
    // ?--????
    for (int i = 0, size = segWords.size(); i < size; i++) {
        String word = segWords.get(i);
        // }
        // for (String word : segWords) {
        // ??1
        if (StringUtils.length(word) > 1) {
            // 
            if (sb.length() > 0) {
                // ???
                String tmpStr = sb.toString();
                if (sb.length() == 1) {
                    // ???
                    if (isSingleWord(tmpStr)) {
                        addStr2List(splitWordsList, candidate);
                        addStr2List(splitWordsList, tmpStr);
                    }
                    // ????
                    else if (isPrefixLetter(tmpStr)) {
                        if (StringUtils.isNotBlank(candidate)) {
                            addStr2List(splitWordsList, candidate);
                        }
                        // ?
                        word = tmpStr + word;
                    } else {
                        if (isEndWithDigit(candidate)) {
                            // ??
                            if (unitSet.contains(tmpStr) || StringUtils.length(word) > 1) {
                                candidate = candidate + tmpStr;
                                addStr2List(splitWordsList, candidate);
                            } else {
                                if (StringUtils.isNotBlank(candidate)) {
                                    addStr2List(splitWordsList, candidate);
                                }
                                // ??
                                word = tmpStr + word;
                            }
                        } else {
                            handleSingleWord(splitWordsList, candidate, tmpStr);
                        }
                    }
                } else {
                    addStr2List(splitWordsList, candidate);
                    addStr2List(splitWordsList, tmpStr);
                }
                sb.setLength(0);
            } else {
                if (StringUtils.isNotBlank(candidate)) {
                    addStr2List(splitWordsList, candidate);
                }
            }
            candidate = word;
        } else {
            {
                int k = i + 1;
                // ???
                int singleWordCount = 1;
                for (int j = k; j < size; j++) {
                    if (StringUtils.length(segWords.get(j)) != 1) {
                        break;
                    }
                    singleWordCount++;
                }
                if (singleWordCount > 1) {
                    int exIndex = i;
                    boolean canAllBeTreatedAsSingle = true;
                    for (int j = i, stop = i + singleWordCount; j < stop; j++) {
                        if (!isSingleWord(segWords.get(j))) {
                            exIndex = j;
                            canAllBeTreatedAsSingle = false;
                            break;
                        }
                    }
                    // ???
                    if (canAllBeTreatedAsSingle) {
                        addStr2List(splitWordsList, candidate);
                        candidate = "";
                        for (int stop = i + singleWordCount; i < stop; i++) {
                            addStr2List(splitWordsList, segWords.get(i));
                        }
                        i--;
                    } else {
                        // TODO zxc:?
                        for (int stop = i + singleWordCount; i < stop; i++) {
                            sb.append(segWords.get(i));
                        }
                        i--;
                        addStr2List(splitWordsList, candidate);
                        addStr2List(splitWordsList, sb.toString());
                        sb.setLength(0);
                        candidate = "";
                    }
                    continue;
                }
            }

            if (StringUtils.equals(word, space)) {
                String tmpStr = sb.toString();
                if (sb.length() == 1) {
                    candidate = candidate + tmpStr;
                    addStr2List(splitWordsList, candidate);
                } else {
                    if (StringUtils.isNotBlank(candidate)) {
                        addStr2List(splitWordsList, candidate);
                    }
                    if (sb.length() > 1) {
                        addStr2List(splitWordsList, tmpStr);
                    }
                }
                splitWordsList.add(space);
                sb.setLength(0);
                candidate = "";
            } else {
                // 2013
                // if (index + 1 < size) {
                // nextWordIsSingle = StringUtils.length(segWords.get(index + 1)) == 1;
                // } else {
                // nextWordIsSingle = false;
                // }
                if (sb.length() > 0) {
                    String header = sb.substring(0, 1);
                    // ?
                    if (isSingleWord(header)) {
                        addStr2List(splitWordsList, candidate);
                        candidate = "";
                        addStr2List(splitWordsList, header);
                        sb.deleteCharAt(0);
                    }
                }
                sb.append(word);
            }
        }
    }
    boolean isCandidateNotNull = StringUtils.length(candidate) > 0;
    boolean isSbNotNull = sb.length() > 0;
    if (isCandidateNotNull) {
        if (isSbNotNull) {
            String w = sb.toString();
            if (isSingleWord(w)) {
                addStr2List(splitWordsList, candidate);
                addStr2List(splitWordsList, w);
            } else {
                handleSingleWord(splitWordsList, candidate, w);
            }
        } else {
            addStr2List(splitWordsList, candidate);
        }
    } else if (isSbNotNull) {
        addStr2List(splitWordsList, sb.toString());
    }
    return splitWordsList;
}

From source file:com.manydesigns.elements.pdf.TableFormPdfExporter.java

/**
 * <p>Returns an array of column sizes (in characters) for the search export.<br />
 * By default, sizes are computed comparing the relative sizes of each column,
 * consisting of the header and the values produced by the search.</p>
 * <p>Users can override this method to compute the sizes using a different algorithm,
 * or hard-coding them for a particular CRUD instance.</p>
 *//*w  ww .j  a v  a 2  s . com*/
protected double[] setupColumnSizes() {
    double[] headerSizes = new double[form.getColumns().length];
    for (int i = 0; i < headerSizes.length; i++) {
        TableForm.Column col = form.getColumns()[i];
        int length = StringUtils.length(col.getLabel());
        headerSizes[i] = length;
    }

    double[] columnSizes = new double[form.getColumns().length];
    for (TableForm.Row row : form.getRows()) {
        int i = 0;
        for (Field field : row) {
            int size = StringUtils.length(field.getStringValue());
            double relativeSize = ((double) size) / form.getRows().length;
            columnSizes[i++] += relativeSize;
        }
    }

    double totalSize = 0;
    for (int i = 0; i < columnSizes.length; i++) {
        double effectiveSize = Math.max(columnSizes[i], headerSizes[i]);
        columnSizes[i] = effectiveSize;
        totalSize += effectiveSize;
    }
    while (totalSize > 75) {
        int maxIndex = 0;
        double max = 0;
        for (int i = 0; i < columnSizes.length; i++) {
            if (columnSizes[i] > max) {
                max = columnSizes[i];
                maxIndex = i;
            }
        }
        columnSizes[maxIndex] -= 1;
        totalSize -= 1;
    }
    while (totalSize < 70) {
        int minIndex = 0;
        double min = Double.MAX_VALUE;
        for (int i = 0; i < columnSizes.length; i++) {
            if (columnSizes[i] < min) {
                min = columnSizes[i];
                minIndex = i;
            }
        }
        columnSizes[minIndex] += 1;
        totalSize += 1;
    }
    return columnSizes;
}

From source file:io.seldon.dbcp.DbcpFactory.java

@Override
public void configUpdated(String configKey, String configValue) {
    configValue = StringUtils.strip(configValue);
    logger.info("KEY WAS " + configKey);
    logger.info("Received new dbcp settings: " + configValue);

    if (StringUtils.length(configValue) == 0) {
        logger.warn("*WARNING* no dbcp is set!");
    } else {/*  w  w w .j av  a  2s.co  m*/
        try {
            logger.info("Processing configs " + configValue);
            ObjectMapper mapper = new ObjectMapper();
            DbcpConfigList configs = mapper.readValue(configValue, DbcpConfigList.class);
            if (configs != null && configs.dbs != null) {
                for (DbcpConfig config : configs.dbs)
                    createDbcp(config);
            }
            updateInitialised();
            logger.info("Successfully set dbcp.");
        } catch (IOException e) {
            logger.error("Problem changing dbcp ", e);
        }
    }

    if (dataSources.size() == 0) {
        logger.error(
                "No DBCP settings. Seldon will not run without a database connection. Please add settings to /config/dbcp");
        throw new DbcpUninitialisedException();
    }
}

From source file:com.google.ie.business.service.impl.IdeaCommentServiceImpl.java

/**
 * Trim the comment text upto 40 characters.
 * //from   ww w.  j  a v a  2 s  .  c  o m
 * @param commentText
 * @return the trimmed text.
 */
protected String getTrimmedComment(String commentText) {
    StringBuilder trimcomment = new StringBuilder();
    if (StringUtils.length(commentText) > 40) {
        trimcomment.append(commentText.substring(0, 40));
        trimcomment.append("..");
    } else {
        trimcomment.append(commentText);
    }
    return trimcomment.toString();
}

From source file:gov.nih.nci.firebird.web.action.search.InvestigatorSearchAction.java

/**
 * Perform the search./* ww  w  .j a  v a2 s .  com*/
 *
 * @return the struts forward.
 */
@Override
public String execute() {
    String searchTermAlpha = filterSearchTerm();
    if (StringUtils.length(searchTermAlpha) >= MIN_INPUT_LENGTH) {
        results = profileService.search(getTerm());
    } else {
        results = Collections.emptyList();
    }
    return SUCCESS;
}

From source file:gov.nih.nci.firebird.web.action.search.CtepInvestigatorSearchAction.java

/**
 * Perform the search./*  ww w.ja va2 s .  com*/
 *
 * @return the struts forward.
 */
@Override
public String execute() {
    String searchTermAlpha = filterSearchTerm();
    List<InvestigatorProfile> profileResults = null;
    if (StringUtils.length(searchTermAlpha) >= MIN_INPUT_LENGTH) {
        profileResults = profileService.searchForCtepProfiles(getTerm());
        results = convertProfileResultsToListings(profileResults);
    } else {
        results = Collections.emptyList();
    }
    return SUCCESS;
}

From source file:cn.quickj.utils.Assert.java

/**
 * Assert that the given text does not contain the given substring.
 * <pre class="code">Assert.doesNotContain(name, "rod", "Name must not contain 'rod'");</pre>
 * @param textToSearch the text to search
 * @param substring the substring to find within the text
 * @param message the exception message to use if the assertion fails
 *//*ww w  . j av  a 2s .  c  o m*/
public static void doesNotContain(String textToSearch, String substring, String message) {
    if (StringUtils.length(textToSearch) > 0 && StringUtils.length(substring) > 0
            && textToSearch.indexOf(substring) != -1) {
        throw new IllegalArgumentException(message);
    }
}

From source file:eu.annocultor.data.destinations.SolrServer.java

private String extractSolrProperty(Triple triple) {
    String property = triple.getProperty().getUri();
    Value value = triple.getValue();//from   w  w  w  . j a  va 2s .c o m
    if (value != null && value instanceof LiteralValue) {
        String lang = ((LiteralValue) value).getLang();
        if (StringUtils.length(lang) == 2) {
            property += "." + lang;
        }
    }
    return property;
}