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

/**
 * Get a double value from an attribute.
 * //w ww  .  jav a2s. co  m
 * @param element the element to get the attribute from, may be null
 * @param attributeName the attribute name to get
 * @return the value, null if element is null or the attribute value is null
 *         or empty
 */
public static Double getDoubleAttributeValue(final Element element, final String attributeName) {
    if (null == element) {
        return null;
    }
    final String str = element.getAttribute(attributeName);
    if (str.isEmpty()) {
        return null;
    } else {
        return Double.valueOf(str);
    }
}

From source file:Main.java

public static String getHash(String input) {
    if (input == null || input.equals("") || input.isEmpty()) {
        return "";
    }/*w  w  w .  j  av a  2  s  .c  o m*/

    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] messageDigest = md.digest(input.getBytes());
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            sb.append(Integer.toString((messageDigest[i] & 0xff) + 0x100, 16).substring(1));
        }

        return sb.toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:Main.java

private static String mixStep(String str) {
    if (str == null || str.isEmpty()) {
        return "";
    }// w  w w . ja va2 s.c  om
    if (str.length() == 1) {
        return str;
    }
    if (str.length() == 2) {
        StringBuilder sb = new StringBuilder(str);
        return sb.reverse().toString();
    }
    StringBuilder sb = new StringBuilder();
    String char1 = String.valueOf(str.charAt(0));
    String char2 = String.valueOf(str.charAt(1));
    String char3 = String.valueOf(str.charAt(2));
    if ((char1.compareTo(char2) > 0) && (char1.compareTo(char3) < 0)) {
        return sb.append(mixStep(str.substring(2))).append(str.charAt(1)).append(str.charAt(0)).toString();
    } else if ((char1.compareTo(char2) > 0) && (char1.compareTo(char3) > 0)) {
        String mixReverse = (new StringBuilder(mixStep(str.substring(2)))).reverse().toString();
        return sb.append(str.charAt(1)).append(mixReverse).append(str.charAt(0)).toString();
    } else if ((char1.compareTo(char2) < 0) && (char1.compareTo(char3) > 0)) {
        return sb.append(str.charAt(0)).append(mixStep(str.substring(2))).append(str.charAt(1)).toString();
    } else if ((char1.compareTo(char2) < 0) && (char1.compareTo(char3) < 0)) {
        String mixReverse = (new StringBuilder(mixStep(str.substring(2)))).reverse().toString();
        return sb.append(str.charAt(0)).append(mixReverse).append(str.charAt(1)).toString();
    }
    return sb.append(str.charAt(1)).append(str.charAt(0)).append(mixStep(str.substring(2))).toString();
}

From source file:Main.java

private static String name(Element elem) {
    String name = elem.getAttribute("name");
    if (!name.isEmpty()) {
        return elem.getTagName() + "[" + name + "]";
    } else {/*  w  w w.  jav a 2 s.  c om*/
        return elem.getTagName();
    }
}

From source file:Main.java

public static int[] tointArray(String str, String seperator) {
    str = str.trim();// w ww.j  a  va2s  . com
    if (str == null || str.isEmpty()) {
        return null;
    }
    String[] arr = str.split(seperator);
    int[] result = new int[arr.length];
    for (int i = 0; i < arr.length; i++) {
        result[i] = Integer.parseInt(arr[i]);
    }
    return result;
}

From source file:com.swingtech.apps.filemgmt.util.MimeTypeUtils.java

public static String getMimeType(String extension) {
    if (extension.isEmpty())
        return "application/octet-stream";

    if (MimeMap.containsKey(extension)) {
        return MimeMap.get(extension);
    } else {//w  ww  .  j a  v a2s. c  o m
        return "unknown/" + extension;
    }
}

From source file:Main.java

public static boolean validIP(String ip) {
    try {//from   w ww.jav  a2  s  . co  m
        if (ip == null || ip.isEmpty()) {
            return false;
        }

        String[] parts = ip.split("\\.");
        if (parts.length != 4) {
            return false;
        }

        for (String s : parts) {
            int i = Integer.parseInt(s);
            if ((i < 0) || (i > 255)) {
                return false;
            }
        }
        if (ip.endsWith(".")) {
            return false;
        }

        return true;
    } catch (NumberFormatException nfe) {
        return false;
    }
}

From source file:Main.java

public static String selectStringAttribute(Element parent, String attrName, String defaultVal) {
    String result = parent.getAttribute(attrName);

    if (result == null || result.isEmpty()) {
        //            Logger.getLogger(XmlUtil.class.getName()).log(Level.INFO,
        //                    "Attribute {0} is not found", attrName);
        return defaultVal;
    }//ww w .  j av  a 2s  .c  om

    return result;
}

From source file:Main.java

public static Date getAuthDate(String dataString) {
    try {//from  w  w  w .  ja v a  2s . c om
        if (dataString == null || dataString.isEmpty()) {
            return null;
        }
        return getAuthFormat().parse(dataString);
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

public static String getTextValue(Element value, String defaultValue) {
    if (value == null) {
        return defaultValue;
    }//from  ww w  .ja v a 2  s. co m

    String strValue = getTextValue(value);
    if (strValue.isEmpty()) {
        return defaultValue;
    }
    return strValue;
}