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 maskEmpty(String s, String mask) {
    return s == null || s.isEmpty() ? mask : s;
}

From source file:Main.java

/**
 * From the given throwable or its cause, or cause's cause, etc.,
 * get the first one that has a non-empty message, and return that message.
 *
 * @param t/*  w w w  .j a v a  2 s . c om*/
 * @return the first non-empty message string, or null.
 */
public static String getFirstMeaningfulMessage(Throwable t) {
    if (t == null)
        return null;
    String m = t.getMessage();
    if (m != null && !m.isEmpty()) {
        return m;
    }
    return getFirstMeaningfulMessage(t.getCause());
}

From source file:Main.java

@Nullable
private static String removePunctuation(@Nullable String pWord) {
    if (pWord == null || pWord.isEmpty())
        return pWord;
    String mResult = pWord;//from   w  w  w  .j  a  v  a 2  s . co m

    String[] mPunctuation = new String[] { ".", ",", ";", ":", "?", "!", "(", ")" };
    List<String> mPunctuationList = Arrays.asList(mPunctuation);

    while (mResult.length() > 0 && mPunctuationList.contains(mResult.substring(mResult.length() - 1))) {
        mResult = mResult.substring(0, mResult.length() - 1);
    }
    while (mResult.length() > 0 && mPunctuationList.contains(mResult.substring(0, 1))) {
        mResult = mResult.substring(1, mResult.length());
    }

    return mResult;
}

From source file:Main.java

public static Boolean parseBoolean(Element element, String key) {
    String value = element.getAttribute(key);
    if (value != null && !value.isEmpty()) {
        if ("1".equals(value) || "true".equals(value)) {
            return true;
        } else {/*  w  w w  .  j  ava  2s. c om*/
            return false;
        }
    }
    return null;
}

From source file:Main.java

/**
 * Returns trimmed text content of the given node
 * or <code>null</code> if that content is empty (is whitespace).
 *
 * @param node The node to extract content from
 *
 * @return Text content of the node//from w  w w  .j  a v  a2 s . c o m
 *
 * @throws NullPointerException If <code>node</code> is <code>null</code>
 */
public static String getBodyValue(Node node) {
    String text = node.getTextContent().trim();
    return text.isEmpty() ? null : text;
}

From source file:Main.java

/**
 * @param eElement element containing boolean attribute
 * @param atribute name of attribute in element
 * @return value of boolean or null if attribute not exists
 *//*from w ww .j  ava 2s  . c  om*/
public static Boolean getBooleanElementAtribute(Element eElement, String atribute) {
    String atr = eElement.getAttribute(atribute);
    if (atr != null && !atr.isEmpty()) {
        return Boolean.valueOf(atr);
    }
    return null;
}

From source file:Main.java

public static Integer getIntegerAttr(Element element, String name) {
    String attr = element.getAttribute(name);
    if (!attr.isEmpty()) {
        Integer ret = Integer.valueOf(attr);
        return ret;
    }// www  .  j a  v  a  2  s .c o m
    return null;
}

From source file:Main.java

public static Integer getIntegerAttr(Element element, String name, int def) {
    String attr = element.getAttribute(name);
    if (!attr.isEmpty()) {
        Integer ret = Integer.valueOf(attr);
        return ret;
    }/* w ww.  j a v  a  2s.c  o m*/
    return def;
}

From source file:Main.java

public static String getFacebookId(Context context) {
    if (facebookId != null)
        return facebookId;
    else {//  w w  w  .j  a  v  a 2s .  c  o m
        SharedPreferences prefs = context.getSharedPreferences("profilo", Context.MODE_PRIVATE);
        String id = prefs.getString("reg_id", "");
        if (id.isEmpty()) {
            Log.e("HELPER_FACEBOOK", "id facebook not found.");
            return null;
        } else {
            facebookId = id;
            return facebookId;
        }
    }
}

From source file:Main.java

public static int getStepsCount(String xPathAbs) {
    if ((xPathAbs == null) || xPathAbs.isEmpty()) {
        return 0;
    }/*from  w ww. jav  a 2 s .  com*/
    int result = 0;

    if (!xPathAbs.startsWith("/")) {
        xPathAbs = "/" + xPathAbs;
    }

    do {
        xPathAbs = removeLastStep(xPathAbs);
        ++result;
    } while ((xPathAbs != null) && !xPathAbs.isEmpty());

    return result;
}