jdk11 的一些不推荐语法优化

This commit is contained in:
thinkgem
2020-03-29 18:49:08 +08:00
parent eea35d5831
commit be38ce85c1
11 changed files with 35 additions and 87 deletions

View File

@@ -84,7 +84,7 @@ public class MapUtils extends org.apache.commons.collections.MapUtils {
* @param clazz
* @param list
*/
public static <T, V> List<T> toObjectList(Class<T> clazz, List<HashMap<String, V>> list) throws IllegalAccessException,
public static <T, V> List<T> toObjectList(Class<T> clazz, List<HashMap<String, V>> list) throws Exception,
InvocationTargetException, NoSuchMethodException, InstantiationException {
List<T> retList = new ArrayList<T>();
if (list != null && !list.isEmpty()) {
@@ -100,9 +100,9 @@ public class MapUtils extends org.apache.commons.collections.MapUtils {
* @param clazz 目标对象的类
* @param map 待转换Map
*/
public static <T, V> T toObject(Class<T> clazz, Map<String, V> map) throws InstantiationException, IllegalAccessException,
public static <T, V> T toObject(Class<T> clazz, Map<String, V> map) throws Exception,
InvocationTargetException {
T object = clazz.newInstance();
T object = clazz.getDeclaredConstructor().newInstance();
return toObject(object, map);
}
@@ -112,9 +112,9 @@ public class MapUtils extends org.apache.commons.collections.MapUtils {
* @param map 待转换Map
* @param toCamelCase 是否去掉下划线
*/
public static <T, V> T toObject(Class<T> clazz, Map<String, V> map, boolean toCamelCase) throws InstantiationException, IllegalAccessException,
public static <T, V> T toObject(Class<T> clazz, Map<String, V> map, boolean toCamelCase) throws Exception,
InvocationTargetException {
T object = clazz.newInstance();
T object = clazz.getDeclaredConstructor().newInstance();
return toObject(object, map, toCamelCase);
}

View File

@@ -4,6 +4,7 @@
package com.jeesite.common.lang;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
/**
@@ -72,7 +73,7 @@ public class NumberUtils extends org.apache.commons.lang3.math.NumberUtils {
}
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue();
}
/**
@@ -81,7 +82,7 @@ public class NumberUtils extends org.apache.commons.lang3.math.NumberUtils {
*/
public static String formatDouble(Double b) {
BigDecimal bg = new BigDecimal(b);
return bg.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
return bg.setScale(2, RoundingMode.HALF_UP).toString();
}
/**
@@ -90,7 +91,7 @@ public class NumberUtils extends org.apache.commons.lang3.math.NumberUtils {
*/
public static String formatScale(double one, long total) {
BigDecimal bg = new BigDecimal(one * 100 / total);
return bg.setScale(0, BigDecimal.ROUND_HALF_UP).toString();
return bg.setScale(0, RoundingMode.HALF_UP).toString();
}
/**

View File

@@ -167,7 +167,6 @@ public class XmlMapper extends com.fasterxml.jackson.dataformat.xml.XmlMapper{
* @param element
* @return
*/
@SuppressWarnings("unchecked")
private static Object xmlToMap(Element element) {
// System.out.println(element.getName());
Map<String, Object> map = new LinkedHashMap<String, Object>();
@@ -212,7 +211,6 @@ public class XmlMapper extends com.fasterxml.jackson.dataformat.xml.XmlMapper{
* @param element
* @return
*/
@SuppressWarnings("unchecked")
private static Object xmlToMapWithAttr(Element element) {
// System.out.println(element.getName());
Map<String, Object> map = new LinkedHashMap<String, Object>();

View File

@@ -288,14 +288,12 @@ abstract class VFS {
for (int i = 0; vfs == null || !vfs.isValid(); i++) {
Class<? extends VFS> impl = impls.get(i);
try {
vfs = impl.newInstance();
vfs = impl.getDeclaredConstructor().newInstance();
if (vfs == null || !vfs.isValid()) {
log.debug("VFS implementation " + impl.getName() + " is not valid in this environment.");
}
} catch (InstantiationException e) {
log.error("Failed to instantiate " + impl, e);
return null;
} catch (IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
log.error("Failed to instantiate " + impl, e);
return null;
}

View File

@@ -230,8 +230,8 @@ public class ExcelExport implements Closeable{
Collections.sort(annotationList, new Comparator<Object[]>() {
@Override
public int compare(Object[] o1, Object[] o2) {
return new Integer(((ExcelField)o1[0]).sort()).compareTo(
new Integer(((ExcelField)o2[0]).sort()));
return Integer.valueOf(((ExcelField)o1[0]).sort()).compareTo(
Integer.valueOf(((ExcelField)o2[0]).sort()));
};
});
// Initialize

View File

@@ -319,7 +319,7 @@ public class ExcelImport implements Closeable {
* @param cls 导入对象类型
* @param groups 导入分组
*/
public <E> List<E> getDataList(Class<E> cls, String... groups) throws InstantiationException, IllegalAccessException{
public <E> List<E> getDataList(Class<E> cls, String... groups) throws Exception{
return getDataList(cls, false, groups);
}
@@ -329,7 +329,7 @@ public class ExcelImport implements Closeable {
* @param isThrowException 遇见错误是否抛出异常
* @param groups 导入分组
*/
public <E> List<E> getDataList(Class<E> cls, final boolean isThrowException, String... groups) throws InstantiationException, IllegalAccessException{
public <E> List<E> getDataList(Class<E> cls, final boolean isThrowException, String... groups) throws Exception{
return getDataList(cls, new MethodCallback() {
@Override
public Object execute(Object... params) {
@@ -350,7 +350,7 @@ public class ExcelImport implements Closeable {
* @param groups 导入分组
*/
@SuppressWarnings("unchecked")
public <E> List<E> getDataList(Class<E> cls, MethodCallback exceptionCallback, String... groups) throws InstantiationException, IllegalAccessException{
public <E> List<E> getDataList(Class<E> cls, MethodCallback exceptionCallback, String... groups) throws Exception{
List<Object[]> annotationList = ListUtils.newArrayList();
// Get annotation field
Field[] fs = cls.getDeclaredFields();
@@ -380,15 +380,15 @@ public class ExcelImport implements Closeable {
Collections.sort(annotationList, new Comparator<Object[]>() {
@Override
public int compare(Object[] o1, Object[] o2) {
return new Integer(((ExcelField)o1[0]).sort()).compareTo(
new Integer(((ExcelField)o2[0]).sort()));
return Integer.valueOf(((ExcelField)o1[0]).sort()).compareTo(
Integer.valueOf(((ExcelField)o2[0]).sort()));
};
});
//log.debug("Import column count:"+annotationList.size());
// Get excel data
List<E> dataList = ListUtils.newArrayList();
for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) {
E e = (E)cls.newInstance();
E e = (E)cls.getDeclaredConstructor().newInstance();
Row row = this.getRow(i);
if (row == null){
continue;

View File

@@ -213,7 +213,7 @@ public class ServletUtils {
return XmlMapper.toXml(resultMap);
}else{
if (response != null){
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
}
if (ObjectUtils.toBoolean(PropertiesUtils.getInstance().getProperty("web.jsonp.enabled"))) {
String functionName = request.getParameter("__callback");
@@ -225,7 +225,7 @@ public class ServletUtils {
}
}else{
if (response != null){
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
}
return JsonMapper.toJson(resultMap);
}
@@ -300,7 +300,7 @@ public class ServletUtils {
if (type == null && StringUtils.isBlank(response.getContentType())){
if ((StringUtils.startsWith(string, "{") && StringUtils.endsWith(string, "}"))
|| (StringUtils.startsWith(string, "[") && StringUtils.endsWith(string, "]"))){
type = MediaType.APPLICATION_JSON_UTF8_VALUE;
type = MediaType.APPLICATION_JSON_VALUE;
}else if (StringUtils.startsWith(string, "<") && StringUtils.endsWith(string, ">")){
if (StringUtils.startsWith(string, "<!DOCTYPE")){
type = MediaType.TEXT_HTML_VALUE+";charset=UTF-8";