001/** 002 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.gnu.org/licenses/lgpl-3.0.txt 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package dev.tinyflow.core.util; 017 018public class StringUtil { 019 020 public static boolean noText(String string) { 021 return !hasText(string); 022 } 023 024 public static boolean hasText(String string) { 025 return string != null && !string.isEmpty() && containsText(string); 026 } 027 028 public static boolean hasText(String... strings) { 029 for (String string : strings) { 030 if (!hasText(string)) { 031 return false; 032 } 033 } 034 return true; 035 } 036 037 private static boolean containsText(CharSequence str) { 038 for (int i = 0; i < str.length(); i++) { 039 if (!Character.isWhitespace(str.charAt(i))) { 040 return true; 041 } 042 } 043 return false; 044 } 045 046 public static String getFirstWithText(String... strings) { 047 if (strings == null) { 048 return null; 049 } 050 for (String str : strings) { 051 if (hasText(str)) { 052 return str; 053 } 054 } 055 return null; 056 } 057 058 /** 059 * 判断字符串是否是数字 060 * 061 * @param string 需要判断的字符串 062 * @return boolean 是数字返回 true,否则返回 false 063 */ 064 public static boolean isNumeric(String string) { 065 if (string == null || string.isEmpty()) { 066 return false; 067 } 068 char[] chars = string.trim().toCharArray(); 069 for (char c : chars) { 070 if (!Character.isDigit(c)) { 071 return false; 072 } 073 } 074 return true; 075 } 076 077 078}