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 void callPhone(Context ctx, String phoneNumber) {
    if (ctx == null) {
        return;//w  w w . j  a v  a2  s  .c  om
    }
    if (phoneNumber == null || phoneNumber.isEmpty()) {
        return;
    }
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));

    //        ctx.startActivity(intent);
}

From source file:Main.java

/**
 * Helper Method. Searches through the child nodes of a node and returns the first node with a matching name.
 * Do we need this ?/*  w ww .j  av  a  2 s.  c o  m*/
 * @param element The node to read from
 * @param nodeName String The name of the node
 * @param caseSensitive If true, the node name searcher will be case sensitive
 * @return Node the located node or null if one was not found
 */

public static Node getChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive) {
    if (element == null)
        return null;
    if (nodeName == null)
        return null;
    final String name = nodeName.toString().trim();
    if (name.isEmpty())
        return null;
    NodeList list = element.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        Node node = list.item(i);
        if (caseSensitive) {
            if (node.getNodeName().equals(name))
                return node;
        } else {
            if (node.getNodeName().equalsIgnoreCase(name))
                return node;
        }
    }
    return null;
}

From source file:Main.java

/**
 * Parses a String to a ChronoLocalDate using a DateTimeFormatter with a short
 * pattern based on the current Locale and the provided Chronology, then
 * converts this to a LocalDate (ISO) value.
 *
 * @param text/*from   w  w w .  j  av  a  2s  .  c o  m*/
 *          - the input date text in the SHORT format expected for the
 *          Chronology and the current Locale.
 *
 * @param chrono
 *          - an optional Chronology. If null, then IsoChronology is used.
 */
public static LocalDate fromString(String text, Chronology chrono) {
    if (text != null && !text.isEmpty()) {
        Locale locale = Locale.getDefault(Locale.Category.FORMAT);
        if (chrono == null) {
            chrono = IsoChronology.INSTANCE;
        }
        String pattern = "M/d/yyyy GGGGG";
        DateTimeFormatter df = new DateTimeFormatterBuilder().parseLenient().appendPattern(pattern)
                .toFormatter().withChronology(chrono).withDecimalStyle(DecimalStyle.of(locale));
        TemporalAccessor temporal = df.parse(text);
        ChronoLocalDate cDate = chrono.date(temporal);
        return LocalDate.from(cDate);
    }
    return null;
}

From source file:Main.java

/**
 * Checks if the passed String is null or empty
 * @param str String to check/*from w  w  w  .ja va2  s  . co  m*/
 * @return Boolean, true if it is null or empty, false if it is not.
 */
public static boolean isNullOrEmpty(String str) {
    if (str == null) {
        return true;
    }
    if (str.isEmpty()) {
        return true;
    }
    if (str.length() == 0) {
        return true;
    }
    if (str.equalsIgnoreCase(" ")) {
        return true;
    }
    return false;
}

From source file:Main.java

public static void callPhone(Context ctx, String phoneNumber) {
    if (ctx == null) {
        return;//from w w  w  .j  a  va  2  s.c o  m
    }
    if (phoneNumber == null || phoneNumber.isEmpty()) {
        return;
    }
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));

    ctx.startActivity(intent);
}

From source file:Main.java

/**
 * Method for showing Log messages./*from w  w  w . j ava  2s  .c  o  m*/
 *
 * @param message
 */
public static void showLog(String tag, Object message) {

    if (ENABLE_LOG) {
        if (tag == null || tag.isEmpty()) {
            Log.d(TAG_INSTAGRAM, String.valueOf(message));
        } else {
            Log.d(tag, String.valueOf(message));
        }
    }

}

From source file:de.arraying.arraybot.util.UFormatting.java

/**
 * Formats an Object array to list.//from  www .j  a v a 2s  . c om
 * This will not append anything called "UNKNOWN".
 * @param input The array to format.
 * @return A formatted list.
 */
public static String formatToList(Object[] input) {
    StringBuilder builder = new StringBuilder();
    for (Object object : input) {
        if (object.toString().equals("UNKNOWN")) {
            continue;
        }
        builder.append(UFormatting.displayableEnumField(object)).append(", ");
    }
    String value = builder.toString().trim();
    if (!value.isEmpty()) {
        value = value.substring(0, value.length() - 1);
    }
    return value;
}

From source file:Main.java

public static List<String> parse(String input) {
    List<String> term = new ArrayList<>();
    for (String part : input.replace('"', ' ').split("\\s+")) {
        if (part.isEmpty()) {
            continue;
        }/*from   w w w.  j ava 2 s  .  c  om*/
        final String cleaned = clean(part);
        if (isKeyword(cleaned) || cleaned.contains("*")) {
            term.add(part);
        } else if (!cleaned.isEmpty()) {
            term.add(cleaned);
        }
    }
    return term;
}

From source file:com.gs.obevo.util.DAStringUtil.java

/**
 * Replaces all forms and lengths of whitespace w/ a single space so that we can subsequently calculate the hash of
 * a string based solely on the textual content.
 * Note that for practical reasons, we treat this as a 99.99999% accurate thing, i.e. we do not try to be smart
 * enough where we only parse out whitespace that is not inside quotes (i.e. if it is an actual string literal).
 * (Though if we can get it to 100% one day, I'm all for it. But in practice, this should be good enough)
 *///from w ww  .  jav  a 2s  .c om
public static String normalizeWhiteSpaceFromString(String content) {
    if (content == null) {
        return null;
    }
    final Matcher matcher = pattern.matcher(content);
    final String s = matcher.replaceAll(" ").trim();
    if (s.isEmpty()) {
        return null;
    }
    return s;
}

From source file:Main.java

public static int[] longestSubstring(String str1, String str2) {
    if (str1 == null || str1.isEmpty() || str2 == null || str2.isEmpty())
        return null;

    // dynamic programming => save already identical length into array
    // to understand this algo simply print identical length in every entry
    // of the array
    // i+1, j+1 then reuses information from i,j
    // java initializes them already with 0
    int[][] num = new int[str1.length()][str2.length()];
    int maxlen = 0;
    int lastSubstrBegin = 0;
    int endIndex = 0;
    for (int i = 0; i < str1.length(); i++) {
        for (int j = 0; j < str2.length(); j++) {
            if (str1.charAt(i) == str2.charAt(j)) {
                if ((i == 0) || (j == 0))
                    num[i][j] = 1;/* www .j ava2s  .  com*/
                else
                    num[i][j] = 1 + num[i - 1][j - 1];

                if (num[i][j] > maxlen) {
                    maxlen = num[i][j];
                    // generate substring from str1 => i
                    lastSubstrBegin = i - num[i][j] + 1;
                    endIndex = i + 1;
                }
            }
        }
    }
    return new int[] { lastSubstrBegin, endIndex };
}