| | |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.regex.Matcher; |
| | |
| | | /** |
| | | * 数字正则 |
| | | */ |
| | | public static final Pattern NUMBER_PATTERN = Pattern.compile("^[-\\+]?[\\d]*[.]?[\\d]*$"); |
| | | public static final Pattern NUMBER_PATTERN = Pattern.compile("-?\\d+(\\.\\d+)?"); |
| | | |
| | | /** |
| | | * 格式化当前系统日期 1 |
| | |
| | | */ |
| | | public static final SimpleDateFormat YMD_HM_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmm"); |
| | | |
| | | public static final double D1024 = 1024.0; |
| | | /** |
| | | * 判断字符串,是否为整数 |
| | | */ |
| | | public static boolean isInteger(String str) { |
| | | return str != null && str.matches("[0-9]+"); |
| | | } |
| | | |
| | | /** |
| | | * 判断字符串,是否为数字 |
| | | * 判断字符串,是否为浮点数 |
| | | */ |
| | | public static boolean isNumber(String str) { |
| | | return NUMBER_PATTERN.matcher(str).matches(); |
| | | public static boolean isNumeric(String str) { |
| | | return str != null && str.matches("-?\\d+(\\.\\d+)?"); |
| | | } |
| | | |
| | | /** |
| | | * 判断字符串,是否为浮点数 |
| | | */ |
| | | public static boolean isNumeric2(String str) { |
| | | return str != null && NUMBER_PATTERN.matcher(str).matches(); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 首字母大写 |
| | | */ |
| | | public static String capitalize(String str) { |
| | | return String.valueOf(str.charAt(0)).toUpperCase() + str.substring(1); |
| | | public static String firstCharToUpperCase(String str) { |
| | | return str.substring(0, 1).toUpperCase() + str.substring(1); |
| | | } |
| | | |
| | | /** |
| | | * 首字母小写 |
| | | */ |
| | | public static String firstCharToLowerCase(String str) { |
| | | return str.substring(0, 1).toLowerCase() + str.substring(1); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean checkPwdValid(String pwd) { |
| | | return Pattern.matches(StaticData.PWD_REG, pwd); |
| | | } |
| | | |
| | | /** |
| | | * 字节单位换算 |
| | | */ |
| | | public static String formatByte(long byteNumber) { |
| | | double kbNumber = byteNumber / D1024; |
| | | if (kbNumber < D1024) { |
| | | return new DecimalFormat("#.##KB").format(kbNumber); |
| | | } |
| | | double mbNumber = kbNumber / D1024; |
| | | if (mbNumber < D1024) { |
| | | return new DecimalFormat("#.##MB").format(mbNumber); |
| | | } |
| | | double gbNumber = mbNumber / D1024; |
| | | if (gbNumber < D1024) { |
| | | return new DecimalFormat("#.##GB").format(gbNumber); |
| | | } |
| | | double tbNumber = gbNumber / D1024; |
| | | |
| | | return new DecimalFormat("#.##TB").format(tbNumber); |
| | | } |
| | | } |