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

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

Introduction

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

Prototype

public static int length(final CharSequence cs) 

Source Link

Document

Gets a CharSequence length or 0 if the CharSequence is null .

Usage

From source file:com.shenit.commons.utils.ShenStrings.java

/**
 * ?
 * @param str
 * @return
 */
public static int len(Object str) {
    return StringUtils.length(str(str));
}

From source file:de.micromata.genome.db.jpa.logging.BaseJpaLoggingImpl.java

private String shortendToCol(SearchColumnDesc colDesc, String value) {
    if (StringUtils.length(value) <= colDesc.maxLength) {
        return value;
    }/* w  w  w  . ja  v a 2 s .  c o m*/
    return value.substring(0, colDesc.maxLength);
}

From source file:com.buildabrand.gsb.util.URLUtils.java

public String canonicalizeIp(String host) {
    if (StringUtils.length(host) <= 15) {
        // The Windows resolver allows a 4-part dotted decimal IP address to have a
        // space followed by any old rubbish, so long as the total length of the
        // string doesn't get above 15 characters. So, "10.192.95.89 xy" is
        // resolved to 10.192.95.89.
        // If the string length is greater than 15 characters,
        // e.g. "10.192.95.89 xy.wildcard.example.com", it will be resolved through
        // DNS./*from w ww . j a  va  2 s.co m*/
        Matcher ipWithTrailingSpaceMatched = IP_WITH_TRAILING_SPACE.matcher(host);

        if (ipWithTrailingSpaceMatched.find()) {
            host = ipWithTrailingSpaceMatched.group(1);
        }
    }

    if (!POSSIBLE_IP.matcher(host).find()) {
        return null;
    }

    // Skip trailing, leading and consecutive dots.
    return convertIpAddress(host);
}

From source file:gtu.jpa.hibernate.Rcdf002eDBUI.java

private void executeReportBtnActionPerformed(ActionEvent evt) {
    try {//from w  w  w .  j av  a  2s  .c o  m
        final LoadToDBAndWriteFile exe = new LoadToDBAndWriteFile();
        if (StringUtils.isNotBlank(xmlFileText.getText())) {
            File file = new File(xmlFileText.getText());
            if (file.exists()) {
                exe.bulkTxt = file;
            }
        } else if (getBulkFile() != null) {
            xmlFileText.setText(getBulkFile().getAbsolutePath());
        }
        Log.Setting.NORMAL.apply();
        exe.setOut(new PrintStream(new PrintStreamAdapter("big5") {
            @Override
            public void println(String message) {
                Log.debug(message);
                if (StringUtils.length(logArea.getText()) > 500) {
                    logArea.setText("");
                }
                logArea.append(message + "\n");
            }
        }));
        setTitle(".......");
        Thread thread = new Thread(Thread.currentThread().getThreadGroup(), new Runnable() {
            @Override
            public void run() {
                try {
                    long current = System.currentTimeMillis();
                    exe.execute();
                    current = System.currentTimeMillis() - current;
                    setTitle(" : ?");
                    JCommonUtil._jOptionPane_showMessageDialog_info(
                            " : ?,:" + current + "\n?!");
                } catch (Exception ex) {
                    setTitle(":" + ex.getMessage());
                    JCommonUtil.handleException(ex);
                }
            }
        }, "xxxxxxxxxxxxxxxxxcxccx");
        thread.setDaemon(true);
        thread.start();
    } catch (Exception ex) {
        setTitle(":" + ex.getMessage());
        JCommonUtil.handleException(ex);
    }
}

From source file:gov.nih.nci.caintegrator.web.action.query.form.QueryForm.java

private void validateQueryName(ValidationAware action) {
    if (StringUtils.isBlank(getQuery().getName())) {
        action.addActionError("Query Name is required.");
    } else if (StringUtils.length(getQuery().getName()) > QUERY_NAME_LENGTH) {
        action.addActionError("Query Name must be " + QUERY_NAME_LENGTH + " characters or less.");
    } else {/*from www .  ja v a2  s. c  om*/
        validateUniqueQueryName(action);
    }
}

From source file:gov.nih.nci.caintegrator.web.action.query.form.QueryForm.java

private void validateQueryDescription(ValidationAware action) {
    if (StringUtils.length(getQuery().getDescription()) > QUERY_DESCRIPTION_LENGTH) {
        action.addActionError("Query Description must be " + QUERY_DESCRIPTION_LENGTH + " characters or less.");
    }//from  w w w. j  av  a2  s . c  o  m
}

From source file:com.adguard.android.service.FilterServiceImpl.java

/**
 * Checks the rules of non ascii symbols and control symbols
 *
 * @param userRule rule//from ww  w  .j  a  v a 2  s . c  o  m
 *
 * @return true if correct rule or false
 */
private boolean validateRuleText(String userRule) {
    return StringUtils.isNotBlank(userRule) && userRule.matches(ASCII_SYMBOL)
            && StringUtils.length(userRule) > MIN_RULE_LENGTH && !StringUtils.startsWith(userRule, COMMENT)
            && !StringUtils.startsWith(userRule, ADBLOCK_META_START)
            && !StringUtils.contains(userRule, MASK_OBSOLETE_SCRIPT_INJECTION)
            && !StringUtils.contains(userRule, MASK_OBSOLETE_STYLE_INJECTION);
}

From source file:com.quinsoft.zeidon.objectbrowser.EntitySquare.java

/**
 * Sets the tooltip text from the current selected EI.
 *
 * @param cursor/*from  w  w  w. jav  a 2 s .  c  o  m*/
 */
private void setToolTipText(EntityCursor cursor) {
    EntityInstance ei = cursor.getEntityInstance();
    if (ei == currentEi && ei != null)
        return;

    currentEi = ei;

    StringBuilder html = new StringBuilder("<html><table>");

    EntityDef entityDef = cursor.getEntityDef();
    html.append("<tr><td><b>").append(entityDef.getName()).append("</b></td><td></td></tr>");

    if (ei != null) {
        for (AttributeDef attributeDef : entityDef.getAttributes()) {
            if (attributeDef.isHidden())
                continue;

            String value = "*error*";

            try {
                if (ei.getAttribute(attributeDef).isNull())
                    continue;

                value = ei.getAttribute(attributeDef).getString();
            } catch (Exception e) {
                getView().log().error(e);
            }

            // Skip null attributes.
            if (StringUtils.isBlank(value))
                continue;

            html.append("<tr><td>").append(attributeDef.getName()).append("</td>");

            if (StringUtils.length(value) > 50)
                value = value.substring(0, 50);
            html.append("<td>").append(value).append("</td></tr>");
        }
    }

    html.append("</table></html>");
    setToolTipText(html.toString());
}

From source file:gtu.jpa.hibernate.Rcdf002eDBUI.java

private JButton getMakeExcelBtn() {
    if (makeExcelBtn == null) {
        makeExcelBtn = new JButton();
        makeExcelBtn.setText("\u7522\u751fexcel");
        makeExcelBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    File file = JCommonUtil.filePathCheck(srcDirText.getText(), "", true);
                    final Rcdf002eExcelMaker exe = new Rcdf002eExcelMaker();
                    exe.setBaseDir(file);
                    Log.Setting.NORMAL.apply();
                    exe.setOut(new PrintStream(new PrintStreamAdapter("big5") {
                        @Override
                        public void println(String message) {
                            Log.debug(message);
                            if (StringUtils.length(logArea.getText()) > 500) {
                                logArea.setText("");
                            }/*from w w  w . jav a2s . c  om*/
                            logArea.append(message + "\n");
                        }
                    }));
                    setTitle(".......");
                    Thread thread = new Thread(Thread.currentThread().getThreadGroup(), new Runnable() {
                        @Override
                        public void run() {
                            try {
                                long current = System.currentTimeMillis();
                                exe.execute();
                                current = System.currentTimeMillis() - current;
                                setTitle("excel?");
                                JCommonUtil._jOptionPane_showMessageDialog_info(
                                        "excel : ?,:" + current + "\n?!");
                            } catch (Exception ex) {
                                setTitle(":" + ex.getMessage());
                                JCommonUtil.handleException(ex);
                            }
                        }
                    }, "xxxxxxxxxxxxxxxxxcxccx");
                    thread.setDaemon(true);
                    thread.start();
                } catch (Exception ex) {
                    setTitle(":" + ex.getMessage());
                    JCommonUtil.handleException(ex);
                }
            }
        });
    }
    return makeExcelBtn;
}

From source file:com.neophob.sematrix.properties.ApplicationConfigurationHelper.java

/**
 * Parses the art net devices./*  w  w w  .jav a2  s  .co  m*/
 *
 * @return the int
 */
private int parseArtNetDevices() {
    //minimal ip length 1.1.1.1
    if (StringUtils.length(getArtNetIp()) > 6 && parseOutputXResolution() > 0 && parseOutputYResolution() > 0) {
        this.devicesInRow1 = 1;
        this.devicesInRow2 = 0;
        this.deviceXResolution = parseOutputXResolution();
        this.deviceYResolution = parseOutputYResolution();
        return 1;
    }

    return 0;
}