diff --git a/helper/src/main/java/com/github/mrzhqiang/helper/Namings.java b/helper/src/main/java/com/github/mrzhqiang/helper/Namings.java index 6789267..8c60e43 100644 --- a/helper/src/main/java/com/github/mrzhqiang/helper/Namings.java +++ b/helper/src/main/java/com/github/mrzhqiang/helper/Namings.java @@ -9,7 +9,11 @@ public enum Namings { ; /** - * com.randall.FssdApplication, {".qing",".chun"} ==> com-randall-fssd-application.qing.chun + * com.randall.FssdApplication, {".qing",".chun"} == com-randall-fssdapplication.qing.chun + * + * @param clazz 任意类的描述对象。 + * @param more 更多的后缀数组。 + * @return 按照类全名拼接好的字符串,同时替换小数点为破折号。 */ public static String ofCanonical(Class> clazz, String... more) { String first = clazz.getCanonicalName().toLowerCase().replaceAll("[.$]", "-"); @@ -21,7 +25,11 @@ public static String ofCanonical(Class> clazz, String... more) { } /** - * NamingsTest, {"1","2","3"} ==> namings-test123 + * NamingsTest, {"1","2","3"} == namings-test123 + * + * @param clazz 任意类的描述对象。 + * @param more 更多的后缀数组。 + * @return 按照简单类名拼接好的字符串,同时将驼峰命名改为破折号连接。 */ public static String ofSimple(Class> clazz, String... more) { String first = ofCamel(clazz.getSimpleName()); @@ -33,7 +41,10 @@ public static String ofSimple(Class> clazz, String... more) { } /** - * CamelString ==> camel-string + * CamelString == camel-string + * + * @param camel 驼峰字符串。 + * @return 修改驼峰字符串为破折号连接。 */ public static String ofCamel(String camel) { Preconditions.checkNotNull(camel, "camel == null"); diff --git a/helper/src/main/java/com/github/mrzhqiang/helper/math/Numbers.java b/helper/src/main/java/com/github/mrzhqiang/helper/math/Numbers.java index b681db3..34b9165 100644 --- a/helper/src/main/java/com/github/mrzhqiang/helper/math/Numbers.java +++ b/helper/src/main/java/com/github/mrzhqiang/helper/math/Numbers.java @@ -12,10 +12,13 @@ public enum Numbers { /** *
- * ofInt(null) >> 0 - * ofInt("") >> 0 - * ofInt("1") >> 1 + * ofInt(null) == 0 + * ofInt("") == 0 + * ofInt("1") == 1 *+ * + * @param number 仅包含整型数字的字符串。 + * @return 整型数字。无效的数字字符串将默认返回 0。 */ public static int ofInt(String number) { return ofInt(number, 0); @@ -23,10 +26,14 @@ public static int ofInt(String number) { /** *
- * ofInt(null,0) >> 0 - * ofInt("",1) >> 1 - * ofInt("1",0) >> 1 + * ofInt(null,0) == 0 + * ofInt("",1) == 1 + * ofInt("1",0) == 1 *+ * + * @param number 仅包含整型数字的字符串。 + * @param defaultValue 默认返回的整型数字。 + * @return 整型数字。 */ public static int ofInt(String number, int defaultValue) { if (Strings.isNullOrEmpty(number)) { @@ -42,10 +49,13 @@ public static int ofInt(String number, int defaultValue) { /** *
- * ofLong(null) >> 0L - * ofLong("") >> 0L - * ofLong("1") >> 1L + * ofLong(null) == 0L + * ofLong("") == 0L + * ofLong("1") == 1L *+ * + * @param number 仅包含长整型数字的字符串。 + * @return 长整型数字。无效的数字字符串将默认返回 0L。 */ public static long ofLong(String number) { return ofLong(number, 0L); @@ -53,10 +63,14 @@ public static long ofLong(String number) { /** *
- * ofLong(null,0L) >> 0L - * ofLong("",1L) >> 1L - * ofLong("1",0L) >> 1L + * ofLong(null,0L) == 0L + * ofLong("",1L) == 1L + * ofLong("1",0L) == 1L *+ * + * @param number 仅包含长整型数字的字符串。 + * @param defaultValue 默认返回的长整型数字。 + * @return 长整型数字。 */ public static long ofLong(String number, long defaultValue) { if (Strings.isNullOrEmpty(number)) { @@ -72,10 +86,13 @@ public static long ofLong(String number, long defaultValue) { /** *
- * ofFloat(null) >> 0.0f - * ofFloat("") >> 0.0f - * ofFloat("1.0") >> 1.0f + * ofFloat(null) == 0.0f + * ofFloat("") == 0.0f + * ofFloat("1.0") == 1.0f *+ * + * @param number 包含单精度浮点型数字的字符串。 + * @return 单精度浮点型数字。无效的字符串将默认返回 0.0f。 */ public static float ofFloat(String number) { return ofFloat(number, 0.0f); @@ -83,10 +100,14 @@ public static float ofFloat(String number) { /** *
- * ofFloat(null,0.0f) >> 0.0f - * ofFloat("",1.0f) >> 1.0f - * ofFloat("1",0.0f) >> 1.0f + * ofFloat(null,0.0f) == 0.0f + * ofFloat("",1.0f) == 1.0f + * ofFloat("1",0.0f) == 1.0f *+ * + * @param number 包含单精度浮点型数字的字符串。 + * @param defaultValue 默认返回的单精度浮点型数字。 + * @return 单精度浮点型数字。 */ public static float ofFloat(String number, float defaultValue) { if (Strings.isNullOrEmpty(number)) { @@ -102,10 +123,13 @@ public static float ofFloat(String number, float defaultValue) { /** *
- * ofDouble(null) >> 0.0d - * ofDouble("") >> 0.0d - * ofDouble("1") >> 1.0d + * ofDouble(null) == 0.0d + * ofDouble("") == 0.0d + * ofDouble("1") == 1.0d *+ * + * @param number 包含双精度浮点型数字的字符串。 + * @return 双精度浮点型数字。无效的字符串将默认返回 0.0d。 */ public static double ofDouble(String number) { return ofDouble(number, 0.0d); @@ -113,10 +137,14 @@ public static double ofDouble(String number) { /** *
- * ofDouble(null,0.0d) >> 0.0d - * ofDouble("",1.0d) >> 1.0d - * ofDouble("1",0.0d) >> 1.0d + * ofDouble(null,0.0d) == 0.0d + * ofDouble("",1.0d) == 1.0d + * ofDouble("1",0.0d) == 1.0d *+ * + * @param number 包含双精度浮点型数字的字符串。 + * @param defaultValue 默认返回的双精度浮点型数字。 + * @return 双精度浮点型数字。 */ public static double ofDouble(String number, double defaultValue) { if (Strings.isNullOrEmpty(number)) { @@ -132,9 +160,12 @@ public static double ofDouble(String number, double defaultValue) { /** *
- * ofDouble(null) >> 0.0d - * ofDouble(BigDecimal.valueOf(1.0d)) >> 1.0d + * ofDouble(null) == 0.0d + * ofDouble(BigDecimal.valueOf(1.0d)) == 1.0d *+ * + * @param number 大数值数字,带小数点。 + * @return 双精度浮点型数字。无效的字符串将默认返回 0.0d。 */ public static double ofDouble(BigDecimal number) { return ofDouble(number, 0.0d); @@ -142,9 +173,13 @@ public static double ofDouble(BigDecimal number) { /** *
- * ofDouble(null, 1.1d) >> 1.1d - * ofDouble(BigDecimal.valueOf(1.0d), 1.1d) >> 1.0d + * ofDouble(null, 1.1d) == 1.1d + * ofDouble(BigDecimal.valueOf(1.0d), 1.1d) == 1.0d *+ * + * @param number 大数值数字,带小数点。 + * @param defaultValue 默认返回的双精度浮点型数字。 + * @return 双精度浮点型数字。 */ public static double ofDouble(BigDecimal number, double defaultValue) { return number == null ? defaultValue : number.doubleValue(); @@ -152,21 +187,28 @@ public static double ofDouble(BigDecimal number, double defaultValue) { /** *
- * ofByte(null) = 0 - * ofByte("") = 0 - * ofByte("1") = 1 + * ofByte(null) == 0 + * ofByte("") == 0 + * ofByte("1") == 1 *+ * + * @param number 仅包含字节数字的字符串。 + * @return 字节数字。 */ - public static byte ofByte(String numer) { - return ofByte(numer, (byte) 0); + public static byte ofByte(String number) { + return ofByte(number, (byte) 0); } /** *
- * ofByte(null, 1) = 1 - * ofByte("", 1) = 1 - * ofByte("1", 0) = 1 + * ofByte(null, 1) == 1 + * ofByte("", 1) == 1 + * ofByte("1", 0) == 1 *+ * + * @param number 仅包含字节数字的字符串。 + * @param defaultValue 默认返回的字节数字。 + * @return 字节数字。 */ public static byte ofByte(String number, byte defaultValue) { if (Strings.isNullOrEmpty(number)) { @@ -182,10 +224,13 @@ public static byte ofByte(String number, byte defaultValue) { /** *
- * ofShort(null) = 0 - * ofShort("") = 0 - * ofShort("1") = 1 + * ofShort(null) == 0 + * ofShort("") == 0 + * ofShort("1") == 1 *+ * + * @param number 仅包含短整型数字的字符串。 + * @return 短整型数字。 */ public static short ofShort(String number) { return ofShort(number, (short) 0); @@ -193,10 +238,14 @@ public static short ofShort(String number) { /** *
- * ofShort(null, 1) = 1 - * ofShort("", 1) = 1 - * ofShort("1", 0) = 1 + * ofShort(null, 1) == 1 + * ofShort("", 1) == 1 + * ofShort("1", 0) == 1 *+ * + * @param number 仅包含短整型数字的字符串。 + * @param defaultValue 默认返回的短整型数字。 + * @return 短整型数字。 */ public static short ofShort(String number, short defaultValue) { if (number == null) {