From 84ed5657f79bd1d2160f3ac77adacd1fddc0ed94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=90=A6=E6=B6=9B?= Date: Fri, 3 Mar 2023 17:58:49 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=20sonar=E3=80=91oConvertUtils?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jero/common/util/oConvertUtils.java | 96 +++++++++++-------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/oConvertUtils.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/oConvertUtils.java index 9ea519a7..33fbe7cd 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/oConvertUtils.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/oConvertUtils.java @@ -15,18 +15,24 @@ import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.sql.Date; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * + * * @Author 张代浩 * */ @Slf4j public class oConvertUtils { + + private oConvertUtils(){ + + } public static boolean isEmpty(Object object) { if (object == null) { return (true); @@ -39,7 +45,7 @@ public class oConvertUtils { } return (false); } - + public static boolean isNotEmpty(Object object) { if (object != null && !object.equals("") && !object.equals("null")) { return (true); @@ -52,8 +58,8 @@ public class oConvertUtils { return temp; } - public static String StrToUTF(String strIn, String sourceCode, String targetCode) { - strIn = ""; + public static String StrToUTF() { + String strIn = ""; try { strIn = new String(strIn.getBytes("ISO-8859-1"), "GBK"); } catch (UnsupportedEncodingException e) { @@ -72,7 +78,7 @@ public class oConvertUtils { try { byte[] b = strIn.getBytes(sourceCode); for (int i = 0; i < b.length; i++) { - System.out.print(b[i] + " "); + log.info(b[i] + " "); } strOut = new String(b, targetCode); } catch (Exception e) { @@ -83,7 +89,7 @@ public class oConvertUtils { } public static int getInt(String s, int defval) { - if (s == null || s == "") { + if (s == null || "".equals(s)) { return (defval); } try { @@ -94,7 +100,7 @@ public class oConvertUtils { } public static int getInt(String s) { - if (s == null || s == "") { + if (s == null || "".equals(s)) { return 0; } try { @@ -105,7 +111,7 @@ public class oConvertUtils { } public static int getInt(String s, Integer df) { - if (s == null || s == "") { + if (s == null || "".equals(s)) { return df; } try { @@ -117,9 +123,6 @@ public class oConvertUtils { public static Integer[] getInts(String[] s) { Integer[] integer = new Integer[s.length]; - if (s == null) { - return null; - } for (int i = 0; i < s.length; i++) { integer[i] = Integer.parseInt(s[i]); } @@ -128,7 +131,7 @@ public class oConvertUtils { } public static double getDouble(String s, double defval) { - if (s == null || s == "") { + if (s == null || "".equals(s)) { return (defval); } try { @@ -163,7 +166,7 @@ public class oConvertUtils { return (defval); } } - + public static Integer getInt(Object object) { if (isEmpty(object)) { return null; @@ -207,7 +210,7 @@ public class oConvertUtils { /*public static String escapeJava(Object s) { return StringEscapeUtils.escapeJava(getString(s)); }*/ - + public static String getString(Object object) { if (isEmpty(object)) { return ""; @@ -263,12 +266,12 @@ public class oConvertUtils { /** * 判断一个类是否为基本数据类型。 - * + * * @param clazz * 要判断的类。 * @return true 表示为基本数据类型。 */ - private static boolean isBaseDataType(Class clazz) throws Exception { + private static boolean isBaseDataType(Class clazz) { return (clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class) || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class) || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(BigDecimal.class) || clazz.equals(BigInteger.class) || clazz.equals(Boolean.class) || clazz.equals(Date.class) || clazz.isPrimitive()); } @@ -278,14 +281,15 @@ public class oConvertUtils { * @return IP Address */ public static String getIpAddrByRequest(HttpServletRequest request) { + String unknown = "unknown"; String ip = request.getHeader("x-forwarded-for"); - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; @@ -326,7 +330,7 @@ public class oConvertUtils { /** * java去除字符串中的空格、回车、换行符、制表符 - * + * * @param str * @return */ @@ -343,7 +347,7 @@ public class oConvertUtils { /** * 判断元素是否在数组内 - * + * * @param substring * @param source * @return @@ -370,7 +374,7 @@ public class oConvertUtils { /** * SET转换MAP - * + * * @param str * @return */ @@ -414,12 +418,12 @@ public class oConvertUtils { private static boolean isInner(long userIp, long begin, long end) { return (userIp >= begin) && (userIp <= end); } - + /** * 将下划线大写方式命名的字符串转换为驼峰式。 * 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
* 例如:hello_world->helloWorld - * + * * @param name * 转换前的下划线大写方式命名的字符串 * @return 转换后的驼峰式命名的字符串 @@ -456,12 +460,12 @@ public class oConvertUtils { } return result.toString(); } - + /** * 将下划线大写方式命名的字符串转换为驼峰式。 * 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
* 例如:hello_world,test_id->helloWorld,testId - * + * * @param name * 转换前的下划线大写方式命名的字符串 * @return 转换后的驼峰式命名的字符串 @@ -470,7 +474,7 @@ public class oConvertUtils { if(names==null||names.equals("")){ return null; } - StringBuffer sf = new StringBuffer(); + StringBuilder sf = new StringBuilder(); String[] fs = names.split(","); for (String field : fs) { field = camelName(field); @@ -479,13 +483,13 @@ public class oConvertUtils { String result = sf.toString(); return result.substring(0, result.length() - 1); } - + //update-begin--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能 /** * 将下划线大写方式命名的字符串转换为驼峰式。(首字母写) * 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
* 例如:hello_world->HelloWorld - * + * * @param name * 转换前的下划线大写方式命名的字符串 * @return 转换后的驼峰式命名的字符串 @@ -514,7 +518,7 @@ public class oConvertUtils { return result.toString(); } //update-end--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能 - + /** * 将驼峰命名转化成下划线 * @param para @@ -522,18 +526,18 @@ public class oConvertUtils { */ public static String camelToUnderline(String para){ if(para.length()<3){ - return para.toLowerCase(); + return para.toLowerCase(); } StringBuilder sb=new StringBuilder(para); int temp=0;//定位 - //从第三个字符开始 避免命名不规范 + //从第三个字符开始 避免命名不规范 for(int i=2;i> select = new ArrayList<>(); for (Map row : list) { Map resultMap = new HashMap<>(); - Set keySet = row.keySet(); - for (String key : keySet) { - String newKey = key.toLowerCase(); - resultMap.put(newKey, row.get(key)); + Set keySet = row.keySet(); + for (String key : keySet) { + String newKey = key.toLowerCase(); + resultMap.put(newKey, row.get(key)); } select.add(resultMap); }