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 List<String> readListFromFile(String filePath) throws IOException {
    List<String> result = new ArrayList<String>();

    InputStream fis = null;//from   w  ww  .  j a va2  s . co  m
    BufferedReader br = null;

    try {
        fis = new FileInputStream(filePath);
        br = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8")));
        String line;
        while ((line = br.readLine()) != null) {
            String trimmed = line.trim();
            if (!trimmed.isEmpty()) {
                result.add(line);
            }
        }
    } finally {
        if (br != null) {
            br.close();
        }
        if (fis != null) {
            fis.close();
        }
    }

    return result;

}

From source file:Main.java

static public int getIntegerTextContent(Element element) {
    String s = getTrimmedTextContent(element);
    return s == null || s.isEmpty() ? 0 : Integer.parseInt(s);
}

From source file:Main.java

public static boolean isEmpty(String s) {
    if (null == s) {
        return true;
    } else {//from   w ww.ja  v  a 2 s. com
        return s.isEmpty();
    }
}

From source file:com.moz.fiji.schema.util.JavaIdentifiers.java

/**
 * Determines whether a string is a valid Java identifier.
 *
 * <p>A valid Java identifier may not start with a number, but may contain any
 * combination of letters, digits, underscores, or dollar signs.</p>
 *
 * <p>See the <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8">
 * Java Language Specification</a></p>
 *
 * @param identifier The identifier to test for validity.
 * @return Whether the identifier was valid.
 *///from  w ww . java2 s . c o m
public static boolean isValidIdentifier(String identifier) {
    if (identifier.isEmpty() || !Character.isJavaIdentifierStart(identifier.charAt(0))) {
        return false;
    }
    for (int i = 1; i < identifier.length(); i++) {
        if (!Character.isJavaIdentifierPart(identifier.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * Strip off the end portion of the name. The user might be typing
 * the activity name such that only a portion has been entered so far (e.g.
 * "MainActivi") and we want to chop off that portion too such that we don't
 * offer a layout name partially containing the activity suffix (e.g. "main_activi").
 *///from   ww w.j  a  va 2  s .  c om
public static String stripSuffix(String name, String suffix, boolean recursiveStrip) {
    if (name.isEmpty()) {
        return name;
    }

    int suffixStart = name.lastIndexOf(suffix.charAt(0));
    if (suffixStart != -1 && name.regionMatches(suffixStart, suffix, 0, name.length() - suffixStart)) {
        name = name.substring(0, suffixStart);
    }
    // Recursively continue to strip the suffix (catch the FooActivityActivity case)
    if (recursiveStrip && name.endsWith(suffix)) {
        return stripSuffix(name, suffix, recursiveStrip);
    }

    return name;
}

From source file:Main.java

private static Class<?> getClass(Type type) throws ClassNotFoundException {
    String className = getClassName(type);
    if (className == null || className.isEmpty()) {
        return null;
    }//from  w ww  .  j  av a 2  s.co m
    return Class.forName(className);
}

From source file:Main.java

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

        if (nodes != null && nodes.getLength() > 0) {
            return nodes.item(0).getTextContent();
        }//from   w  w w. ja va  2s .  co m
    }

    return null;
}

From source file:com.omertron.slackbot.listeners.AbstractListener.java

/**
 * Add the missing "https:" to the front of a URL string
 *
 * @param link//from ww w.j  a  v  a  2s  .c  o m
 * @return
 */
protected static String formatHttpLink(final String link) {
    if (link == null || link.isEmpty() || link.startsWith("http")) {
        return link;
    } else {
        return "https:" + link;
    }
}

From source file:Main.java

public static String getFileNameFromUri(String uri) {
    String file = "";
    int lastIndexOfSlash = -1;
    if (uri != null && !uri.isEmpty()) {
        lastIndexOfSlash = uri.lastIndexOf('/');
        if (lastIndexOfSlash > -1)
            file = uri.substring(uri.lastIndexOf('/'), uri.length());
    }/*  w  ww .  ja va2  s  .  c  o  m*/
    return file;
}

From source file:Main.java

public static char parse(String str, char fallback) {
    if (str == null || str.isEmpty()) {
        return fallback;
    }//  ww  w  .ja va2s  . c  o m
    return str.charAt(0);
}