字符串相关工具 @author SeanDragon
| 8 | * @author SeanDragon |
| 9 | */ |
| 10 | public final class ToolStr { |
| 11 | |
| 12 | private ToolStr() { |
| 13 | throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); |
| 14 | } |
| 15 | |
| 16 | |
| 17 | /** |
| 18 | * 判断字符串是否为null或长度为0 |
| 19 | * |
| 20 | * @param s |
| 21 | * 待校验字符串 |
| 22 | * |
| 23 | * @return {@code true}: 空<br> {@code false}: 不为空 |
| 24 | */ |
| 25 | public static boolean isEmpty(CharSequence s) { |
| 26 | return s == null || s.length() == 0; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * 判断字符串是否为null或全为空格 |
| 31 | * |
| 32 | * @param s |
| 33 | * 待校验字符串 |
| 34 | * |
| 35 | * @return {@code true}: null或全空格<br> {@code false}: 不为null且不全空格 |
| 36 | */ |
| 37 | public static boolean isSpace(String s) { |
| 38 | return (s == null || s.trim().length() == 0); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | /** |
| 43 | * 字符串为 null 或者内部字符全部为 ' ' '\t' '\n' '\r' 这四类字符时返回 true |
| 44 | */ |
| 45 | public static boolean isBlank(String str) { |
| 46 | if (str == null) { |
| 47 | return true; |
| 48 | } |
| 49 | int len = str.length(); |
| 50 | if (len == 0) { |
| 51 | return true; |
| 52 | } |
| 53 | for (int i = 0; i < len; i++) { |
| 54 | switch (str.charAt(i)) { |
| 55 | case ' ': |
| 56 | case '\t': |
| 57 | case '\n': |
| 58 | case '\r': |
| 59 | //case '\b': |
| 60 | //case '\f': |
| 61 | break; |
| 62 | default: |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | return true; |
| 67 | } |
nothing calls this directly
no outgoing calls
no test coverage detected