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

public static String getAttribute(Element element, String name) {
    String value = element.getAttribute(name);
    if (value != null && !value.isEmpty()) {
        return value;
    }/* ww w. j a v a 2 s .c om*/
    throw new NoSuchElementException(String.format("Element <%s> has no \"%s\" attribute", element, name));
}

From source file:Main.java

/**
 * Returns a {@code Class} object that identifies the
 * declared class for the field represented by the given {@code String name} parameter inside
 * the invoked {@code Class<?> clazz} parameter.
 *
 * @param clazz the {@code Class} object whose declared fields to be
 *       checked for a certain field./*from   www  . ja va2s .  c  o  m*/
 * @param name the field name as {@code String} to be
 *       compared with {@link Field#getName()}
 * @return the {@code Class} object representing the type of given field name.
 *
 * @see {@link Class#getDeclaredFields()}
 * @see {@link Field#getType()}
 */
public static Class<?> getFieldClass(Class<?> clazz, String name) {
    if (clazz == null || name == null || name.isEmpty()) {
        return null;
    }

    Class<?> propertyClass = null;

    for (Field field : clazz.getDeclaredFields()) {
        field.setAccessible(true);
        if (field.getName().equalsIgnoreCase(name)) {
            propertyClass = field.getType();
            break;
        }
    }

    return propertyClass;
}

From source file:Main.java

/**
 * Returns a {@code Class} object that identifies the
 * declared class as a return type for the method represented by the given
 * {@code String name} parameter inside the invoked {@code Class<?> clazz} parameter.
 *
 * @param clazz the {@code Class} object whose declared methods to be
 *       checked for the wanted method name.
 * @param name the method name as {@code String} to be
 *       compared with {@link Method#getName()}
 * @return the {@code Class} object representing the return type of the given method name.
 *
 * @see {@link Class#getDeclaredMethods()}
 * @see {@link Method#getReturnType()}/*ww  w  .  j  a  v a  2s  . c om*/
 */
public static Class<?> getMethodReturnType(Class<?> clazz, String name) {
    if (clazz == null || name == null || name.isEmpty()) {
        return null;
    }

    name = name.toLowerCase();
    Class<?> returnType = null;

    for (Method method : clazz.getDeclaredMethods()) {
        if (method.getName().equals(name)) {
            returnType = method.getReturnType();
            break;
        }
    }

    return returnType;
}

From source file:Main.java

/**
 * Applies the cm: default namespace to all the path-part on which the
 * namespace is missing.//from   w  ww  .j a v a 2 s  . c o m
 * 
 * @param xpathValue
 * @return
 */
public static String getXPathEquivalentPath(String pathToResource) {

    final StringBuilder sb = new StringBuilder();
    final String[] splitPath = pathToResource.split("/");
    final Iterator<String> it = Arrays.asList(splitPath).iterator();

    while (it.hasNext()) {
        final String pathElement = it.next();
        if (pathElement.isEmpty())
            continue;

        if (!pathElement.contains(":") && !pathElement.contains("{")) { // weak but sufficient in a first place
            sb.append("cm:");
        }
        sb.append(pathElement);
        if (it.hasNext()) {
            sb.append("/");
        }
    }

    return sb.toString();

}

From source file:Main.java

/**
 * Checks if a String is whitespace, empty ("") or null.
 *//*  w w w  .  j  a  v  a  2s  . c om*/
public static boolean isBlank(String string) {
    if (string == null) {
        return true;
    }
    return string.isEmpty() || " ".equals(string);
}

From source file:Main.java

public static boolean isEmpty(String str) {
    if (str == null || str.length() == 0 || str.equalsIgnoreCase("null") || str.isEmpty() || str.equals("")) {
        return true;
    } else {/*from w  w w .  j  av  a  2  s .c o m*/
        return false;
    }
}

From source file:Main.java

/**
 * Added by TJJ Feb 2014/*from   w  w  w  .  j a v  a  2  s .c  om*/
 * 
 * This method ensures that the output String has only
 * valid XML unicode characters as specified by the
 * XML 1.0 standard. For reference, please see
 * <a href="http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char">the
 * standard</a>. This method will return an empty
 * String if the input is null or empty.
 *
 * @param in The String whose non-valid characters we want to remove.
 * @return The in String, stripped of non-valid characters.
 */

public static String stripNonValidXMLCharacters(String in) {
    if ((in == null) || in.isEmpty()) {
        return ""; // vacancy test.
    }
    StringBuilder out = new StringBuilder(in.length()); // Used to hold the output.
    for (int i = 0; i < in.length(); i++) {
        char current = in.charAt(i); // Used to reference the current character.
                                     // NOTE: No IndexOutOfBoundsException caught here; it should not happen.
        if ((current == 0x9) || (current == 0xA) || (current == 0xD)
                || ((current >= 0x20) && (current <= 0xD7FF)) || ((current >= 0xE000) && (current <= 0xFFFD))
                || ((current >= 0x10000) && (current <= 0x10FFFF))) {
            out.append(current);
        }
    }
    return out.toString();
}

From source file:Main.java

/**
 * from "myFunction(arg1,arg2)", return ["arg1","arg2"]
 *///w  ww.  j  ava 2  s. com
public static String[] getAttributes(String tag) {
    String attributes = tag.substring(tag.indexOf('(') + 1, tag.lastIndexOf(')'));
    if (attributes.isEmpty())
        return new String[0];
    return trim(attributes.split(","));
}

From source file:Main.java

public static Element GetChildElement(Element element, String name) {
    if (element != null && name != null && !name.isEmpty()) {
        NodeList nodes = element.getChildNodes();

        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);

            if (node instanceof Element && name.equals(node.getNodeName())) {
                return (Element) node;
            }//from w w w.  j ava 2s.c om
        }
    }

    return null;
}

From source file:Main.java

/**
 * /*from  w ww . j  a v  a  2  s.  co  m*/
 * @param node
 * @param name
 * @return
 */
public static int getIntAttribute(Node node, String name) {
    String value = getStringAttribute(node, name);
    if (value != null && !value.isEmpty()) {
        return Integer.valueOf(value).intValue();
    } else {
        return 0;
    }
}