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

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

Introduction

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

Prototype

public static boolean isEmpty(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is empty ("") or null.

 StringUtils.isEmpty(null)      = true StringUtils.isEmpty("")        = true StringUtils.isEmpty(" ")       = false StringUtils.isEmpty("bob")     = false StringUtils.isEmpty("  bob  ") = false 

NOTE: This method changed in Lang version 2.0.

Usage

From source file:de.micromata.genome.gwiki.controls.GWikiUserProfileActionBean.java

protected boolean initUser() {
    if (StringUtils.isEmpty(pageId) == false
            || (wikiContext.isAllowTo(GWikiAuthorizationRights.GWIKI_ADMIN.name()) == true
                    && isNewPage() == true)) {
        if (StringUtils.isEmpty(pageId) == false) {
            userName = FileNameUtils.getNamePart(pageId);
        }/*ww  w  . j a v a 2 s  .  co  m*/
        return true;
    }
    userName = wikiContext.getWikiWeb().getAuthorization().getCurrentUserName(wikiContext);
    if (StringUtils.isEmpty(userName) == true) {
        wikiContext.addSimpleValidationError(wikiContext.getTranslated("gwiki.profile.user.nouser"));
        return false;
    }
    pageId = "admin/user/" + userName;
    elementToEdit = wikiContext.getWikiWeb().findElement("admin/user/" + userName);
    if (elementToEdit == null) {
        wikiContext.addSimpleValidationError(wikiContext.getTranslated("gwiki.profile.user.nouser"));
        return false;
    }
    metaTemplate = elementToEdit.getMetaTemplate();
    metaTemplatePageId = metaTemplate.getPageId();
    return true;
}

From source file:edu.uoa.cs.master.cloudmanufacturingnlp.business.dictionary.DictionaryService.java

/**
 * e.g. with-5 vs. with// w ww. java  2  s.c om
 *
 * @param originalTerm
 * @param ontologyTerm
 * @return
 */
public boolean isSynonym(final String originalTerm, final String ontologyTerm) {

    // validation
    if (StringUtils.isEmpty(originalTerm) || StringUtils.isEmpty(ontologyTerm)) {
        return false;
    }

    // literal match
    final String lowerCaseOriginalTerm = Tools.lowerCaseString(originalTerm);
    final String lowerCaseOntologyTerm = Tools.lowerCaseString(ontologyTerm);
    if (doesLiteralMatch(lowerCaseOriginalTerm, lowerCaseOntologyTerm)) {
        return true;
    }

    final String originalTermWithoutDashSuffix = Tools.removeDashSuffix(lowerCaseOriginalTerm);
    final String ontologyTermWithoutDashSuffix = Tools.removeDashSuffix(lowerCaseOntologyTerm);
    if (doesLiteralMatch(originalTermWithoutDashSuffix, ontologyTermWithoutDashSuffix)) {
        return true;
    }

    // WordNet synonym match
    final Set<String> synonymSet = JwnlWordNet.getInstance().lookupSynonym(ontologyTermWithoutDashSuffix, null);
    if (doesLiteralArrayMatch(originalTermWithoutDashSuffix, synonymSet)) {
        return true;
    }

    // local synonym match
    List<String> synonymList = LocalDictionary.getIntance().lookupSynonym(ontologyTermWithoutDashSuffix);
    if (doesLiteralArrayMatch(originalTermWithoutDashSuffix, synonymList)) {
        return true;
    }

    synonymList = LocalDictionary.getIntance().lookupSynonym(originalTermWithoutDashSuffix);
    if (doesLiteralArrayMatch(ontologyTermWithoutDashSuffix, synonymList)) {
        return true;
    }

    return false;
}

From source file:ip.ui.LearningParamsInputPanel.java

public double getLearningRate() throws EmptyInputFieldException {
    String learningRateParam = learningRateInput.getText();
    if (StringUtils.isEmpty(learningRateParam)) {
        throw new EmptyInputFieldException(learningRateLabel.getText());
    }//from  w  w w.  j  ava2 s  .  com

    return Double.parseDouble(learningRateParam);
}

From source file:com.webbfontaine.valuewebb.model.validators.tt.PortValidator.java

public void checkPortOfLoadingAndPlaceOfReceiptAgainstCountryOfSupply() {

    String errorMessage1 = "Port of loading does not match to the country of supply!";
    String errorMessage2 = "Country of supply cannot be empty while Port of Loading/Place of Receipt is not empty!";
    String errorMessage3 = "Place of receipt does not match to the country of supply!";

    String countryOfSupply = ttGen.getCtySupp() == null ? "" : ttGen.getCtySupp();
    String portOfLoading = ttGen.getTtTrans().getLoadPort();
    String placeOfReceipt = ttGen.getTtTrans().getPlaceOfReceipt();

    if ((!StringUtils.isEmpty(portOfLoading) || !StringUtils.isEmpty(placeOfReceipt))
            && StringUtils.isEmpty(countryOfSupply)) {
        ErrorHandling.addFacesMessage("ctySupp", errorMessage2, FacesMessage.SEVERITY_ERROR);
    } else {/*from w  ww .jav a  2  s  .c om*/
        if (StringUtils.isEmpty(placeOfReceipt)) {
            if (!StringUtils.isEmpty(portOfLoading)
                    && !portOfLoading.substring(0, 2).toLowerCase().equals(countryOfSupply.toLowerCase())) {
                ErrorHandling.addFacesMessage("loadPort", errorMessage1, FacesMessage.SEVERITY_ERROR);
            }
        } else {
            if (!placeOfReceipt.substring(0, 2).toLowerCase().equals(countryOfSupply.toLowerCase())) {
                ErrorHandling.addFacesMessage("placeOfReceipt", errorMessage3, FacesMessage.SEVERITY_ERROR);
            }
        }
    }
}

From source file:com.xiaoxiaomo.flink.batch.distcp.FileCopyTask.java

public FileCopyTask(Path path, String relativePath) {
    if (StringUtils.isEmpty(relativePath)) {
        throw new IllegalArgumentException("Relative path should not be empty for: " + path);
    }// w ww  . ja  va  2 s . c o m
    this.path = path;
    this.relativePath = relativePath;
}

From source file:com.salesforce.ide.apex.internal.core.tooling.systemcompletions.model.Constructor.java

@Override
public String getDisplayString() {
    if (StringUtils.isEmpty(name))
        return null;

    StringBuilder sb = new StringBuilder();
    sb.append(name);/*from w w w. jav a 2  s .  co m*/
    sb.append('(');
    if (parameters != null) {
        sb.append(StringUtils.join(parameters, ","));
    }
    sb.append(')');
    return sb.toString();
}

From source file:com.github.britter.beanvalidators.EmptyConstraintValidator.java

@Override
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
    if (value == null) {
        return true;
    } else if (value instanceof String) {
        return StringUtils.isEmpty((String) value);
    } else if (value instanceof Collection) {
        return ((Collection) value).isEmpty();
    } else if (value instanceof Map) {
        return ((Map) value).isEmpty();
    } else if (value.getClass().isArray()) {
        return Array.getLength(value) == 0;
    } else {//from  w w w.j  a v a 2s .co m
        // Is this the correct behavior?
        throw new ValidationException("@Empty can not be applied to objects of type " + value.getClass());
    }
}

From source file:com.esri.geoevent.test.performance.provision.DefaultProvisionerFactory.java

@Override
public Provisioner createProvisioner(ProvisionerConfig config) throws ProvisionException {
    if (config == null) {
        return null;
    }/*from  ww w .  j a v a2 s  .c o  m*/

    String className = config.getClassName();
    if (StringUtils.isEmpty(className)) {
        throw new ProvisionException(
                "Failed to create a valid Provisioner. The attribute \"ClassName\" is missing in the \"ProvisionerConfig\"!");
    }

    try {
        Class<?> clazz = ClassUtils.getClass(className);
        Provisioner provisioner = (Provisioner) clazz.newInstance();
        provisioner.init(config);
        return provisioner;
    } catch (ClassNotFoundException error) {
        throw new ProvisionException(
                "Failed to create a valid Provisioner. The className \"" + className + "\" was not found!",
                error);
    } catch (IllegalAccessException | InstantiationException error) {
        throw new ProvisionException("Failed to instatiate a valid Provisioner. The className \"" + className
                + "\" must have a parameter-less constructor!", error);
    }
}

From source file:cherry.goods.telno.TelNoNormalizerImpl.java

@Override
public String flatten(String telNo) {
    if (StringUtils.isEmpty(telNo)) {
        return telNo;
    }/*from w  ww.jav  a2 s.  c  om*/
    return telNo.replaceAll("-", "");
}

From source file:ch.cyberduck.core.HostPasswordStore.java

/**
 * @param host Hostname/*from   w ww.j a v  a2s. c  o m*/
 * @return the password fetched from the keychain or null if it was not found
 */
public String find(final Host host) {
    if (log.isInfoEnabled()) {
        log.info(String.format("Fetching password from keychain for %s", host));
    }
    if (StringUtils.isEmpty(host.getHostname())) {
        log.warn("No hostname given");
        return null;
    }
    final Credentials credentials = host.getCredentials();
    if (StringUtils.isEmpty(credentials.getUsername())) {
        log.warn("No username given");
        return null;
    }
    String p;
    if (credentials.isPublicKeyAuthentication()) {
        final Local key = credentials.getIdentity();
        p = this.getPassword(host.getHostname(), key.getAbbreviatedPath());
        if (null == p) {
            // Interoperability with OpenSSH (ssh, ssh-agent, ssh-add)
            p = this.getPassword("SSH", key.getAbsolute());
        }
        if (null == p) {
            // Backward compatibility
            p = this.getPassword("SSHKeychain", key.getAbbreviatedPath());
        }
    } else {
        p = this.getPassword(host.getProtocol().getScheme(), host.getPort(), host.getHostname(),
                credentials.getUsername());
    }
    if (null == p) {
        if (log.isInfoEnabled()) {
            log.info(String.format("Password not found in keychain for %s", host));
        }
    }
    return p;
}