Example usage for java.lang String isEmpty

List of usage examples for java.lang String isEmpty

Introduction

In this page you can find the example usage for java.lang String isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if, and only if, #length() is 0 .

Usage

From source file:Main.java

/**
 * Absolutize a relative resource path on the given absolute base path.
 *
 * @param path The absolute base path/*  w  ww.j a  v  a 2  s .c o  m*/
 * @param resource The relative resource path
 * @return The absolutized resource path
 */
public static String absolutize(String path, String resource) {
    if (path == null || path.isEmpty()) {
        return resource;
    } else if (resource == null || resource.isEmpty()) {
        return path;
    } else if (resource.charAt(0) == '/') {
        // Resource path is already absolute
        return resource;
    }

    boolean slash = (path.charAt(path.length() - 1) == '/');

    StringBuffer b = new StringBuffer(path.length() + 1 + resource.length());
    b.append(path);
    if (!slash) {
        b.append('/');
    }
    b.append(resource);
    return b.toString();
}

From source file:Main.java

public static byte[] parseByteString(String str) {
    if (str == null) {
        return null;
    }/*from  w  w w  . j  a  v a2s  . c  om*/
    str = str.trim();
    if (str.isEmpty()) {
        return null;
    }
    return str.getBytes();
}

From source file:io.yields.math.framework.range.IntegerRange.java

public static Range<Integer> fromString(String rangeAsString) {
    if (rangeAsString.isEmpty()) {
        return IntegerRange.MAX_RANGE_INT;
    } else {//from   w ww. j  a  v a 2  s.  co m
        //lower bound
        String lowerBoundAsString = rangeAsString.split(",")[0].substring(1);
        Integer lowerBound = getIntValue(lowerBoundAsString);
        boolean lowerBoundIsOpen = rangeAsString.charAt(0) == ']';
        //upper bound
        String upperBoundAsString = rangeAsString.split(",")[1];
        upperBoundAsString = upperBoundAsString.substring(0, upperBoundAsString.length() - 1);
        Integer upperBound = getIntValue(upperBoundAsString);
        boolean upperBoundIsOpen = rangeAsString.charAt(rangeAsString.length() - 1) == '[';
        return new IntegerRange(lowerBound, upperBound, lowerBoundIsOpen, upperBoundIsOpen);
    }
}

From source file:Main.java

/**
 * Get one element from XML document using xpath expression
 * //from   ww  w  .  j av a  2 s  .com
 * @param doc
 * @param expression
 * @return
 * @throws XPathExpressionException
 */
public static Element getElement(final Document doc, final String expression) throws XPathExpressionException {
    if (null == expression || expression.isEmpty() || null == doc) {
        return null;
    }
    log.finer("Executing xpath xpression " + expression);
    XPath xPath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xPath.compile(expression);
    Object result = expr.evaluate(doc, XPathConstants.NODE);
    return (Element) result;
}

From source file:Main.java

public static String wrap(String str, int w) {
    StringBuffer sb = new StringBuffer();
    String line = "";

    for (String s : regex_ws.split(str)) {
        if (!line.isEmpty() && line.length() + s.length() >= w) {
            if (sb.length() != 0)
                sb.append('\n');
            sb.append(line);//from  www. jav  a  2 s  .  com
            line = s;
        } else {
            line = (line.isEmpty()) ? s : line + ' ' + s;
        }
    }

    if (!line.isEmpty()) {
        if (sb.length() != 0)
            sb.append('\n');
        sb.append(line);
    }

    return sb.toString();
}

From source file:alien4cloud.paas.cloudify2.rest.external.StringUtils.java

/**
 * Checks if a given String is not null or empty.
 *
 * @param str The String object to evaluate
 * @return true/false/*from  w  w  w. jav a  2s  .com*/
 */
public static boolean notEmpty(final String str) {
    return str != null && !str.isEmpty();
}

From source file:com.streamsets.pipeline.lib.el.FileEL.java

private static boolean isEmpty(String str) {
    return str == null || str.isEmpty();
}

From source file:Main.java

/**
 * Get node from XML document using xpath expression
 * /*from   w ww  .j av  a  2 s. c  om*/
 * @param doc
 * @param expression
 * @return
 * @throws XPathExpressionException
 */
public static Node getNode(final Document doc, final String expression) throws XPathExpressionException {
    if (null == expression || expression.isEmpty() || null == doc) {
        return null;
    }
    log.finer("Executing xpath xpression " + expression);
    XPath xPath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xPath.compile(expression);
    Object result = expr.evaluate(doc, XPathConstants.NODE);
    return (Node) result;
}

From source file:Main.java

public static SimpleDateFormat getEndDateTimeInTimezone(String timezone) {
    SimpleDateFormat format = new SimpleDateFormat("h:mm a");
    if (timezone == null || timezone.isEmpty()) {
        format.setTimeZone(TimeZone.getDefault());
    } else//w  ww  .  j  a v  a2  s  . c  o m
        format.setTimeZone(TimeZone.getTimeZone("GMT+" + timezone));
    return format;
}

From source file:Main.java

/** 
 * Uses the value returned via the component's getText() method to set a Mnemonic key.
 * The character following the first '&' charcater is used as Mnemonic key,
 * but this only works for characters in the range a..Z
 * If a Mnemonic key is found, the '&' character is removed from the text.
 * @param textComponent/*www  . jav  a2  s. c om*/
 */
public static void setMnemonic(AbstractButton textComponent) {

    String label = textComponent.getText();
    if (label == null || label.isEmpty() || !label.contains("&") || label.indexOf('&') == label.length() - 1) {

        return;
    }
    char ch = label.charAt(label.indexOf('&') + 1);
    if (!Character.isLetter(ch)) {
        return;
    }
    int ke = getKeyEvent(ch);
    if (ke != Integer.MIN_VALUE) {
        label = label.substring(0, label.indexOf('&'))
                + label.substring(label.indexOf('&') + 1, label.length());
        textComponent.setText(label);
        textComponent.setMnemonic(ke);
    }
}