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:io.cyberstock.tcdop.model.DropletSize.java

public static DropletSize resolveBySlug(String slug) {
    if (StringUtils.isEmpty(slug)) {
        throw new IllegalArgumentException("slug must not be null");
    }//  www. j  a va 2  s. c  om

    for (DropletSize size : DropletSize.values()) {
        if (size.getSlug().equals(slug)) {
            return size;
        }
    }

    throw new IllegalArgumentException("unknown slug: " + slug);
}

From source file:com.astamuse.asta4d.data.convertor.AbstractString2DateConvertor.java

public T convert(String s) throws UnsupportedValueException {
    if (StringUtils.isEmpty(s)) {
        return null;
    }//from   www  .j av  a 2 s  . c om
    for (DateTimeFormatter formatter : availableFormatters()) {
        try {
            return convert2Target(formatter, s);
        } catch (IllegalArgumentException e) {
            continue;
        }
    }
    throw new UnsupportedValueException();
}

From source file:net.intelli_soft.servlext.helpers.NamedParameter.java

public NamedParameter(String paramName, String value) {
    if (StringUtils.isEmpty(paramName))
        throw new IllegalArgumentException("paramName cannot be empty");

    if (!NAME_PATTERN.matcher(paramName).find())
        throw new IllegalArgumentException("paramName must match: " + NAME_PATTERN.pattern());

    if (value == null)
        value = "";

    this.paramName = paramName;
    this.value = value;
}

From source file:baggage.GitVersion.java

public static String getCommit() {
    return StringUtils.isEmpty(commit) ? "unknown" : commit;
}

From source file:com.google.mr4c.hadoop.RemoteAlgoRunner.java

private static void checkForLauncherProps() {
    String jobid = System.getProperty("oozie.launcher.job.id");
    if (StringUtils.isEmpty(jobid)) {
        return;// ww w  .  j av  a  2 s  .  c om
    }
    String taskid = System.getProperty("hadoop.tasklog.taskid");
    if (StringUtils.isEmpty(taskid)) {
        taskid = "launcher"; // fallback
    }
    CategoryConfig catConf = MR4CConfig.getDefaultInstance().getCategory(Category.CUSTOM);
    catConf.setProperty(CustomConfig.PROP_JOBID, jobid);
    catConf.setProperty(CustomConfig.PROP_TASKID, taskid);
}

From source file:com.freedomotic.util.Unzip.java

/**
 *
 * @param zipFile//ww w  .  j a v  a 2  s.com
 * @throws ZipException
 * @throws IOException
 */
public static void unzip(String zipFile) throws IOException {

    if (StringUtils.isEmpty(zipFile)) {
        LOG.error("File path not provided, no unzipping performed");
        return;
    }

    File file = new File(zipFile);

    if (!file.exists()) {
        LOG.error("File not existing, no unzipping performed");
        return;
    }

    try (ZipFile zip = new ZipFile(file);) {
        String newPath = zipFile.substring(0, zipFile.length() - 4);
        //simulates the unzip here feature
        newPath = newPath.substring(0, newPath.lastIndexOf(File.separator));

        Enumeration<? extends ZipEntry> zipFileEntries = zip.entries();

        // Process each entry
        while (zipFileEntries.hasMoreElements()) {
            // grab a zip file entry
            ZipEntry entry = zipFileEntries.nextElement();
            String currentEntry = entry.getName();
            File destFile = new File(newPath, currentEntry);
            File destinationParent = destFile.getParentFile();

            // create the parent directory structure if needed
            destinationParent.mkdirs();

            if (!entry.isDirectory()) {
                try (BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
                        FileOutputStream fos = new FileOutputStream(destFile);
                        BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);) {

                    int currentByte;

                    // establish buffer for writing file
                    byte[] data = new byte[BUFFER];

                    // read and write until last byte is encountered
                    while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
                        dest.write(data, 0, currentByte);
                    }
                } catch (IOException ex) {
                    LOG.error(Freedomotic.getStackTraceInfo(ex));
                }
            }

            if (currentEntry.endsWith(".zip")) {
                // found a zip file, try to open
                unzip(destFile.getAbsolutePath());
            }
        }
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.constants.FaultTypeAppliesTo.java

public static FaultTypeAppliesTo parseString(final String appliesTo) {
    if (StringUtils.isEmpty(appliesTo)) {
        return NONE;
    } else if ("01workstationOrSubassembly".equals(appliesTo)) {
        return WORKSTATION_OR_SUBASSEMBLY;
    } else if ("02workstationType".equals(appliesTo)) {
        return WORKSTATION_TYPE;
    }//from   www .  ja v  a2 s .c o  m

    throw new IllegalStateException("Unsupported AppliesTo: " + appliesTo);
}

From source file:com.zht.common.file.DownloadController.java

@RequestMapping(value = "/download")
public String download(HttpServletRequest request, HttpServletResponse response,
        @RequestParam(value = "filename") String filename) throws Exception {

    filename = filename.replace("/", "\\");

    if (StringUtils.isEmpty(filename) || filename.contains("\\.\\.")) {
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("??");
        return null;
    }/*from   www .java2  s  . c  o  m*/
    filename = URLDecoder.decode(filename, "UTF-8");

    String projectPath = request.getServletContext().getRealPath("/");

    String filePath = projectPath + File.separator + filename;

    DownloadUtils.download(request, response, filePath, filename);

    return null;
}

From source file:edu.uoa.cs.master.cloudmanufacturingnlp.util.Tools.java

public static String getContentFromArray(String[] args) {

    StringBuilder builder = new StringBuilder(1024);
    for (String arg : args) {
        builder.append(StringUtils.isEmpty(arg) ? "" : arg + "; ");
    }/*from   ww w  . ja va2  s . c  om*/

    String buffer = builder.toString().trim();
    if (buffer.endsWith(";")) {
        buffer = buffer.substring(0, buffer.length() - 1);
    }
    return buffer;
}

From source file:com.linkedin.urls.PathNormalizer.java

License:asdf

/**
 * Normalizes the path by doing the following:
 * remove special spaces, decoding hex encoded characters,
 * gets rid of extra dots and slashes, and re-encodes it once
 *///w ww. j  a  va  2  s  .  c  o m
protected String normalizePath(String path) {

    if (StringUtils.isEmpty(path)) {
        return path;
    }
    path = UrlUtil.decode(path);
    path = sanitizeDotsAndSlashes(path);
    return UrlUtil.encode(path);
}