TextUtils.java 757 Bytes
Newer Older
1 2
package chat.rocket.android.helper;

3 4 5
/**
 * Text Utility class like android.text.TextUtils.
 */
6
public class TextUtils {
7

8 9 10 11 12 13 14 15 16
  /**
   * Returns true if the string is null or 0-length.
   * @param str the string to be examined
   * @return true if str is null or zero length
   */
  public static boolean isEmpty(CharSequence str) {
    // same definition as android.text.TextUtils#isEmpty().
    return str == null || str.length() == 0;
  }
17

18 19 20
  /**
   * Returns str if it is not empty; otherwise defaultValue is returned.
   */
Yusuke Iwaki's avatar
Yusuke Iwaki committed
21 22
  @SuppressWarnings("PMD.ShortMethodName")
  public static CharSequence or(CharSequence str,
Yusuke Iwaki's avatar
Yusuke Iwaki committed
23
                                CharSequence defaultValue) {
24 25
    if (isEmpty(str)) {
      return defaultValue;
26
    }
27 28
    return str;
  }
29
}