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:com.webbfontaine.valuewebb.model.validators.TemplateFieldMandatoryValidator.java

@Override
public void validate(FacesContext facesContext, UIComponent uiComponent, Object o) throws ValidatorException {
    PdHome pdHome = (PdHome) Component.getInstance(PdHome.class, ScopeType.CONVERSATION, false);
    Pd pdInstance = pdHome.getInstance();

    if (!StringUtils.isEmpty(pdInstance.getHsCodeF()) && StringUtils.isEmpty(o.toString())) {
        throw new ValidatorException(MessageHandling.createFacesErrorMessage(Messages.VALUE_IS_REQUIRED));
    }/*ww w .  j a  v a2  s .  co  m*/
}

From source file:jp.toastkid.script.runner.GroovyRunner.java

@Override
public Optional<String> run(final String script) {
    if (StringUtils.isEmpty(script)) {
        return Optional.empty();
    }//from  w  w  w. j  a va2 s  .  c o m
    if (engine == null) {
        System.out.println("groovy null");
    }

    final StringBuilder result = new StringBuilder();

    try (final StringWriter writer = new StringWriter();) {
        if (engine != null) {
            final ScriptContext context = engine.getContext();
            context.setWriter(new PrintWriter(writer));
            context.setErrorWriter(new PrintWriter(writer));
        }
        final java.lang.Object run = engine.eval(script);
        result.append(writer.toString()).append(LINE_SEPARATOR);
        if (run != null) {
            result.append("return = ").append(run.toString());
        }
        writer.close();
    } catch (final CompilationFailedException | IOException | javax.script.ScriptException e) {
        e.printStackTrace();
        result.append("Occurred Exception.").append(LINE_SEPARATOR).append(e.getMessage());
    }
    return Optional.of(result.toString());
}

From source file:com.haulmont.cuba.gui.components.sys.ValuePathHelper.java

public static String[] parse(String path) {
    if (!path.contains(".") && !path.contains("[")) {
        return new String[] { path };
    }//from w  ww . j  a va  2  s. c o m

    if (!path.contains("[")) {
        return path.split("\\.");
    }

    List<String> elements = new ArrayList<>();

    int bracketCount = 0;

    StringBuilder buffer = new StringBuilder();

    for (int i = 0; i < path.length(); i++) {
        char c = path.charAt(i);
        if (c == '[') {
            bracketCount++;
            continue;
        }

        if (c == ']') {
            bracketCount--;
            continue;
        }

        if ('.' != c || bracketCount > 0)
            buffer.append(c);

        if ('.' == c && bracketCount == 0) {
            String element = buffer.toString();
            if (!StringUtils.isEmpty(element)) {
                elements.add(element);
            } else {
                throw new IllegalStateException("Wrong value path format");
            }
            buffer = new StringBuilder();
        }
    }
    elements.add(buffer.toString());

    return elements.toArray(new String[elements.size()]);
}

From source file:io.servicecomb.swagger.generator.jaxrs.processor.annotation.ProducesAnnotationProcessor.java

@Override
public void process(Object annotation, OperationGenerator operationGenerator) {
    Produces produces = (Produces) annotation;

    for (String produce : produces.value()) {
        if (!StringUtils.isEmpty(produce)) {
            operationGenerator.getOperation().addProduces(produce);
        }/*from w w  w . ja v  a  2s .  com*/
    }
}

From source file:de.bund.bva.isyfact.benutzerverwaltung.core.rollenverwaltung.validation.ValideRollenIdValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    return StringUtils.isEmpty(value) || value.matches("[a-zA-Z0-9\\-_.]+");
}

From source file:com.netflix.spinnaker.halyard.config.validate.v1.security.GoogleRoleProviderValidator.java

@Override
public void validate(ConfigProblemSetBuilder p, GoogleRoleProvider n) {
    if (StringUtils.isEmpty(n.getAdminUsername())) {
        p.addProblem(Problem.Severity.ERROR, "No admin username specified.");
    }//  www  .j  ava2s  . c om

    if (StringUtils.isEmpty(n.getCredentialPath())) {
        p.addProblem(Problem.Severity.ERROR, "No credentials path specified.");
    }

    if (StringUtils.isEmpty(n.getDomain())) {
        p.addProblem(Problem.Severity.ERROR, "No domain specified.");
    }
}

From source file:jp.toastkid.script.runner.JavaScriptRunner.java

@Override
public Optional<String> run(final String script) {

    if (StringUtils.isEmpty(script)) {
        return Optional.empty();
    }//from w w w .  ja v a 2s  .c  o m
    final StringBuilder result = new StringBuilder();

    try (final StringWriter writer = new StringWriter();) {
        final ScriptContext context = engine.getContext();
        context.setWriter(writer);
        context.setErrorWriter(writer);

        final java.lang.Object run = engine.eval(script);
        result.append(writer.toString()).append(LINE_SEPARATOR);
        if (run != null) {
            result.append("return = ").append(run.toString());
        }
        writer.close();
    } catch (final CompilationFailedException | IOException | ScriptException e) {
        e.printStackTrace();
        result.append("Occurred Exception.").append(LINE_SEPARATOR).append(e.getMessage());
    }
    return Optional.of(result.toString());
}

From source file:com.sample.common.util.AssertUtil.java

/**
 * Solleva una @link(IllegalArgumentException) con message message in caso di string empty
 * //from ww w.ja v a2 s . com
 * @param str
 * @param message
 */
public static void assertNotEmpty(String str, String message) {
    if (StringUtils.isEmpty(str)) {
        throw new IllegalArgumentException(message);
    }
}

From source file:io.cloudslang.content.httpclient.build.ContentTypeBuilder.java

public ContentTypeBuilder setRequestCharacterSet(String requestCharacterSet) {
    if (!StringUtils.isEmpty(requestCharacterSet)) {
        this.requestCharacterSet = requestCharacterSet;
    }//from  w  w w. jav  a2 s .c o m
    return this;
}

From source file:de.micromata.genome.gdbfs.FileNameUtils.java

public static String join(String first, String second) {
    if (StringUtils.isEmpty(second) == true || second.equals("/") == true) {
        return first;
    }/*from   w w  w  .ja  v a  2  s.c o  m*/
    if (StringUtils.isEmpty(first) == true || first.equals("/") == true) {
        return second;
    }
    if (first.endsWith("/") == true || second.startsWith("/") == true) {
        if (first.endsWith("/") == true && second.startsWith("/") == true) {
            return first + second.substring(1);
        }
        return first + second;
    }
    return first + "/" + second;
}