移除 commons-collections、commons-beanutils 依赖

This commit is contained in:
thinkgem
2023-06-09 14:38:16 +08:00
parent 361baa781b
commit 50466b2556
8 changed files with 379 additions and 376 deletions

View File

@@ -8,7 +8,6 @@ import com.jeesite.common.callback.MethodCallback;
import com.jeesite.common.lang.ObjectUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.reflect.ReflectUtils;
import org.apache.commons.beanutils.PropertyUtils;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -19,7 +18,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* @version 2015-1-23
*/
@SuppressWarnings("rawtypes")
public class ListUtils extends org.apache.commons.collections.ListUtils {
public class ListUtils {
/**
* 是否包含字符串
@@ -141,107 +140,107 @@ public class ListUtils extends org.apache.commons.collections.ListUtils {
}
return addAll(addTo, elementsToAdd.iterator());
}
/**
* 提取集合中的对象的两个属性(通过Getter函数), 组合成Map.
* @param collection 来源集合.
* @param keyPropertyName 要提取为Map中的Key值的属性名.
* @param valuePropertyName 要提取为Map中的Value值的属性名.
*/
@SuppressWarnings("unchecked")
public static Map extractToMap(final Collection collection, final String keyPropertyName,
final String valuePropertyName) {
Map map = new HashMap(collection.size());
try {
for (Object obj : collection) {
map.put(PropertyUtils.getProperty(obj, keyPropertyName),
PropertyUtils.getProperty(obj, valuePropertyName));
}
} catch (Exception e) {
throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
}
return map;
}
/**
* 提取集合中的对象的个属性(通过Getter函数), 组合成List.
* @param collection 来源集合.
* @param propertyName 要提取的属性名.
*/
@SuppressWarnings("unchecked")
public static <T> List<T> extractToList(final Collection collection, final String propertyName) {
if (collection == null){
return newArrayList();
}
List list = new ArrayList(collection.size());
try {
for (Object obj : collection) {
list.add(PropertyUtils.getProperty(obj, propertyName));
}
} catch (Exception e) {
throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
}
return list;
}
/**
* 提取集合中的对象的一个属性(通过Getter函数), 组合成List.
* @param collection 来源集合.
* @param propertyName 要提取的属性名.
* @param prefix 符合前缀的信息(为空则忽略前缀)
* @param isNotBlank 仅包含不为空值(空字符串也排除)
*/
public static List<String> extractToList(final Collection collection, final String propertyName,
final String prefix, final boolean isNotBlank) {
List<String> list = new ArrayList<String>(collection.size());
try {
for (Object obj : collection) {
String value = (String)PropertyUtils.getProperty(obj, propertyName);
if (StringUtils.isBlank(prefix) || StringUtils.startsWith(value, prefix)){
if (isNotBlank){
if (StringUtils.isNotBlank(value)){
list.add(value);
}
}else{
list.add(value);
}
}
}
} catch (Exception e) {
throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
}
return list;
}
/**
* 提取集合中的对象的一个属性(通过Getter函数), 组合成由分割符分隔的字符串.
*
* @param collection 来源集合.
* @param propertyName 要提取的属性名.
* @param separator 分隔符.
*/
public static String extractToString(final Collection collection, final String propertyName, final String separator) {
List list = extractToList(collection, propertyName);
return StringUtils.join(list, separator);
}
/**
* 转换Collection所有元素(通过toString())为String, 中间以 separator分隔。
*/
public static String convertToString(final Collection collection, final String separator) {
return StringUtils.join(collection, separator);
}
/**
* 转换Collection所有元素(通过toString())为String, 每个元素的前面加入prefix后面加入postfix如<div>mymessage</div>。
*/
public static String convertToString(final Collection collection, final String prefix, final String postfix) {
StringBuilder builder = new StringBuilder();
for (Object o : collection) {
builder.append(prefix).append(o).append(postfix);
}
return builder.toString();
}
// /**
// * 提取集合中的对象的个属性(通过Getter函数), 组合成Map.
// * @param collection 来源集合.
// * @param keyPropertyName 要提取为Map中的Key值的属性名.
// * @param valuePropertyName 要提取为Map中的Value值的属性名.
// */
// @SuppressWarnings("unchecked")
// public static Map extractToMap(final Collection collection, final String keyPropertyName,
// final String valuePropertyName) {
// Map map = new HashMap(collection.size());
// try {
// for (Object obj : collection) {
// map.put(ReflectUtils.getFieldValue(obj, keyPropertyName),
// ReflectUtils.getFieldValue(obj, valuePropertyName));
// }
// } catch (Exception e) {
// throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
// }
// return map;
// }
//
// /**
// * 提取集合中的对象的一个属性(通过Getter函数), 组合成List.
// * @param collection 来源集合.
// * @param propertyName 要提取的属性名.
// */
// @SuppressWarnings("unchecked")
// public static <T> List<T> extractToList(final Collection collection, final String propertyName) {
// if (collection == null){
// return newArrayList();
// }
// List list = new ArrayList(collection.size());
// try {
// for (Object obj : collection) {
// list.add(ReflectUtils.getFieldValue(obj, propertyName));
// }
// } catch (Exception e) {
// throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
// }
// return list;
// }
//
// /**
// * 提取集合中的对象的一个属性(通过Getter函数), 组合成List.
// * @param collection 来源集合.
// * @param propertyName 要提取的属性名.
// * @param prefix 符合前缀的信息(为空则忽略前缀)
// * @param isNotBlank 仅包含不为空值(空字符串也排除)
// */
// public static List<String> extractToList(final Collection collection, final String propertyName,
// final String prefix, final boolean isNotBlank) {
// List<String> list = new ArrayList<String>(collection.size());
// try {
// for (Object obj : collection) {
// String value = ReflectUtils.getFieldValue(obj, propertyName);
// if (StringUtils.isBlank(prefix) || StringUtils.startsWith(value, prefix)){
// if (isNotBlank){
// if (StringUtils.isNotBlank(value)){
// list.add(value);
// }
// }else{
// list.add(value);
// }
// }
// }
// } catch (Exception e) {
// throw ReflectUtils.convertReflectionExceptionToUnchecked("", e);
// }
// return list;
// }
//
// /**
// * 提取集合中的对象的一个属性(通过Getter函数), 组合成由分割符分隔的字符串.
// *
// * @param collection 来源集合.
// * @param propertyName 要提取的属性名.
// * @param separator 分隔符.
// */
// public static String extractToString(final Collection collection, final String propertyName, final String separator) {
// List list = extractToList(collection, propertyName);
// return StringUtils.join(list, separator);
// }
//
// /**
// * 转换Collection所有元素(通过toString())为String, 中间以 separator分隔。
// */
// public static String convertToString(final Collection collection, final String separator) {
// return StringUtils.join(collection, separator);
// }
//
// /**
// * 转换Collection所有元素(通过toString())为String, 每个元素的前面加入prefix后面加入postfix如<div>mymessage</div>。
// */
// public static String convertToString(final Collection collection, final String prefix, final String postfix) {
// StringBuilder builder = new StringBuilder();
// for (Object o : collection) {
// builder.append(prefix).append(o).append(postfix);
// }
// return builder.toString();
// }
/**
* 判断是否为空.
@@ -257,70 +256,70 @@ public class ListUtils extends org.apache.commons.collections.ListUtils {
return !(isEmpty(collection));
}
/**
* 取得Collection的第一个元素如果collection为空返回null.
*/
public static <T> T getFirst(Collection<T> collection) {
if (isEmpty(collection)) {
return null;
}
return collection.iterator().next();
}
/**
* 获取Collection的最后一个元素 如果collection为空返回null.
*/
public static <T> T getLast(Collection<T> collection) {
if (isEmpty(collection)) {
return null;
}
//当类型为List时直接取得最后一个元素 。
if (collection instanceof List) {
List<T> list = (List<T>) collection;
return list.get(list.size() - 1);
}
//其他类型通过iterator滚动到最后一个元素.
Iterator<T> iterator = collection.iterator();
while (true) {
T current = iterator.next();
if (!iterator.hasNext()) {
return current;
}
}
}
/**
* 返回a+b的新List.
*/
public static <T> List<T> union(final Collection<T> a, final Collection<T> b) {
List<T> result = new ArrayList<T>(a);
result.addAll(b);
return result;
}
/**
* 返回a-b的新List.
*/
public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) {
List<T> list = new ArrayList<T>(a);
for (T element : b) {
list.remove(element);
}
return list;
}
/**
* 返回a与b的交集的新List.
*/
public static <T> List<T> intersection(Collection<T> a, Collection<T> b) {
List<T> list = new ArrayList<T>();
for (T element : a) {
if (b.contains(element)) {
list.add(element);
}
}
return list;
}
// /**
// * 取得Collection的第一个元素如果collection为空返回null.
// */
// public static <T> T getFirst(Collection<T> collection) {
// if (isEmpty(collection)) {
// return null;
// }
// return collection.iterator().next();
// }
//
// /**
// * 获取Collection的最后一个元素 如果collection为空返回null.
// */
// public static <T> T getLast(Collection<T> collection) {
// if (isEmpty(collection)) {
// return null;
// }
// //当类型为List时直接取得最后一个元素 。
// if (collection instanceof List) {
// List<T> list = (List<T>) collection;
// return list.get(list.size() - 1);
// }
// //其他类型通过iterator滚动到最后一个元素.
// Iterator<T> iterator = collection.iterator();
// while (true) {
// T current = iterator.next();
// if (!iterator.hasNext()) {
// return current;
// }
// }
// }
//
// /**
// * 返回a+b的新List.
// */
// public static <T> List<T> union(final Collection<T> a, final Collection<T> b) {
// List<T> result = new ArrayList<T>(a);
// result.addAll(b);
// return result;
// }
//
// /**
// * 返回a-b的新List.
// */
// public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) {
// List<T> list = new ArrayList<T>(a);
// for (T element : b) {
// list.remove(element);
// }
// return list;
// }
//
// /**
// * 返回a与b的交集的新List.
// */
// public static <T> List<T> intersection(Collection<T> a, Collection<T> b) {
// List<T> list = new ArrayList<T>();
// for (T element : a) {
// if (b.contains(element)) {
// list.add(element);
// }
// }
// return list;
// }
// /**
// * 将字符串使用“,”分隔,转换为,多对多中间表列表的转换

View File

@@ -4,11 +4,6 @@
*/
package com.jeesite.common.collect;
import com.jeesite.common.lang.StringUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -18,7 +13,7 @@ import java.util.concurrent.ConcurrentMap;
* @author ThinkGem
* @version 2015-01-15
*/
public class MapUtils extends org.apache.commons.collections.MapUtils {
public class MapUtils {
public static <K, V> HashMap<K, V> newHashMap() {
return new HashMap<K, V>();
@@ -69,161 +64,161 @@ public class MapUtils extends org.apache.commons.collections.MapUtils {
return new IdentityHashMap<K, V>();
}
/**
* List<Map<String, V>转换为List<T>
* @param clazz
* @param list
*/
public static <T, V> List<T> toObjectList(Class<T> clazz, List<HashMap<String, V>> list) throws Exception {
List<T> retList = new ArrayList<T>();
if (list != null && !list.isEmpty()) {
for (HashMap<String, V> m : list) {
retList.add(toObject(clazz, m));
}
}
return retList;
}
/**
* 将Map转换为Object
* @param clazz 目标对象的类
* @param map 待转换Map
*/
public static <T, V> T toObject(Class<T> clazz, Map<String, V> map) throws Exception {
T object = clazz.getDeclaredConstructor().newInstance();
return toObject(object, map);
}
/**
* 将Map转换为Object
* @param clazz 目标对象的类
* @param map 待转换Map
* @param toCamelCase 是否去掉下划线
*/
public static <T, V> T toObject(Class<T> clazz, Map<String, V> map, boolean toCamelCase) throws Exception {
T object = clazz.getDeclaredConstructor().newInstance();
return toObject(object, map, toCamelCase);
}
/**
* 将Map转换为Object
* @param map 待转换Map
*/
public static <T, V> T toObject(T object, Map<String, V> map) throws InstantiationException, IllegalAccessException, InvocationTargetException {
return toObject(object, map, false);
}
/**
* 将Map转换为Object
* @param object 目标对象的类
* @param map 待转换Map
* @param toCamelCase 是否采用驼峰命名法转换
*/
public static <T, V> T toObject(T object, Map<String, V> map, boolean toCamelCase) throws InstantiationException, IllegalAccessException,
InvocationTargetException {
if (toCamelCase) {
map = toCamelCaseMap(map);
}
BeanUtils.populate(object, map);
return object;
}
/**
* 对象转Map
* @param object 目标对象
* @return 转换出来的值都是String
*/
public static Map<String, String> toMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
return BeanUtils.describe(object);
}
/**
* 对象转Map
* @param object 目标对象
* @return 转换出来的值类型是原类型
*/
public static Map<String, Object> toNavMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
return PropertyUtils.describe(object);
}
/**
* 转换为Collection<Map<K, V>>
* @param collection 待转换对象集合
* @return 转换后的Collection<Map<K, V>>
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
*/
public static <T> Collection<Map<String, String>> toMapList(Collection<T> collection) throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
List<Map<String, String>> retList = new ArrayList<Map<String, String>>();
if (collection != null && !collection.isEmpty()) {
for (Object object : collection) {
Map<String, String> map = toMap(object);
retList.add(map);
}
}
return retList;
}
/**
* 转换为Collection,同时为字段做驼峰转换<Map<K, V>>
* @param collection 待转换对象集合
* @return 转换后的Collection<Map<K, V>>
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
*/
public static <T> Collection<Map<String, String>> toMapListForFlat(Collection<T> collection) throws IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
List<Map<String, String>> retList = new ArrayList<Map<String, String>>();
if (collection != null && !collection.isEmpty()) {
for (Object object : collection) {
Map<String, String> map = toMapForFlat(object);
retList.add(map);
}
}
return retList;
}
/**
* 转换成Map并提供字段命名驼峰转平行
* @param object 目标对象
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
public static Map<String, String> toMapForFlat(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Map<String, String> map = toMap(object);
return toUnderlineStringMap(map);
}
/**
* 将Map的Keys去下划线<br>
* (例:branch_no -> branchNo )<br>
* @param map 待转换Map
* @return
*/
public static <V> Map<String, V> toCamelCaseMap(Map<String, V> map) {
Map<String, V> newMap = new HashMap<String, V>();
for (String key : map.keySet()) {
safeAddToMap(newMap, StringUtils.camelCase(key), map.get(key));
}
return newMap;
}
/**
* 将Map的Keys转译成下划线格式的<br>
* (例:branchNo -> branch_no)<br>
* @param map 待转换Map
* @return
*/
public static <V> Map<String, V> toUnderlineStringMap(Map<String, V> map) {
Map<String, V> newMap = new HashMap<String, V>();
for (String key : map.keySet()) {
newMap.put(StringUtils.uncamelCase(key), map.get(key));
}
return newMap;
}
// /**
// * List<Map<String, V>转换为List<T>
// * @param clazz
// * @param list
// */
// public static <T, V> List<T> toObjectList(Class<T> clazz, List<HashMap<String, V>> list) throws Exception {
// List<T> retList = new ArrayList<T>();
// if (list != null && !list.isEmpty()) {
// for (HashMap<String, V> m : list) {
// retList.add(toObject(clazz, m));
// }
// }
// return retList;
// }
//
// /**
// * 将Map转换为Object
// * @param clazz 目标对象的类
// * @param map 待转换Map
// */
// public static <T, V> T toObject(Class<T> clazz, Map<String, V> map) throws Exception {
// T object = clazz.getDeclaredConstructor().newInstance();
// return toObject(object, map);
// }
//
// /**
// * 将Map转换为Object
// * @param clazz 目标对象的类
// * @param map 待转换Map
// * @param toCamelCase 是否去掉下划线
// */
// public static <T, V> T toObject(Class<T> clazz, Map<String, V> map, boolean toCamelCase) throws Exception {
// T object = clazz.getDeclaredConstructor().newInstance();
// return toObject(object, map, toCamelCase);
// }
//
// /**
// * 将Map转换为Object
// * @param map 待转换Map
// */
// public static <T, V> T toObject(T object, Map<String, V> map) throws InstantiationException, IllegalAccessException, InvocationTargetException {
// return toObject(object, map, false);
// }
//
// /**
// * 将Map转换为Object
// * @param object 目标对象的类
// * @param map 待转换Map
// * @param toCamelCase 是否采用驼峰命名法转换
// */
// public static <T, V> T toObject(T object, Map<String, V> map, boolean toCamelCase) throws InstantiationException, IllegalAccessException,
// InvocationTargetException {
// if (toCamelCase) {
// map = toCamelCaseMap(map);
// }
// BeanUtils.populate(object, map);
// return object;
// }
//
// /**
// * 对象转Map
// * @param object 目标对象
// * @return 转换出来的值都是String
// */
// public static Map<String, String> toMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
// return BeanUtils.describe(object);
// }
//
// /**
// * 对象转Map
// * @param object 目标对象
// * @return 转换出来的值类型是原类型
// */
// public static Map<String, Object> toNavMap(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
// return PropertyUtils.describe(object);
// }
//
// /**
// * 转换为Collection<Map<K, V>>
// * @param collection 待转换对象集合
// * @return 转换后的Collection<Map<K, V>>
// * @throws IllegalAccessException
// * @throws InvocationTargetException
// * @throws NoSuchMethodException
// */
// public static <T> Collection<Map<String, String>> toMapList(Collection<T> collection) throws IllegalAccessException, InvocationTargetException,
// NoSuchMethodException {
// List<Map<String, String>> retList = new ArrayList<Map<String, String>>();
// if (collection != null && !collection.isEmpty()) {
// for (Object object : collection) {
// Map<String, String> map = toMap(object);
// retList.add(map);
// }
// }
// return retList;
// }
//
// /**
// * 转换为Collection,同时为字段做驼峰转换<Map<K, V>>
// * @param collection 待转换对象集合
// * @return 转换后的Collection<Map<K, V>>
// * @throws IllegalAccessException
// * @throws InvocationTargetException
// * @throws NoSuchMethodException
// */
// public static <T> Collection<Map<String, String>> toMapListForFlat(Collection<T> collection) throws IllegalAccessException,
// InvocationTargetException, NoSuchMethodException {
// List<Map<String, String>> retList = new ArrayList<Map<String, String>>();
// if (collection != null && !collection.isEmpty()) {
// for (Object object : collection) {
// Map<String, String> map = toMapForFlat(object);
// retList.add(map);
// }
// }
// return retList;
// }
//
// /**
// * 转换成Map并提供字段命名驼峰转平行
// * @param object 目标对象
// * @throws NoSuchMethodException
// * @throws InvocationTargetException
// * @throws IllegalAccessException
// */
// public static Map<String, String> toMapForFlat(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
// Map<String, String> map = toMap(object);
// return toUnderlineStringMap(map);
// }
//
// /**
// * 将Map的Keys去下划线<br>
// * (例:branch_no -> branchNo )<br>
// * @param map 待转换Map
// * @return
// */
// public static <V> Map<String, V> toCamelCaseMap(Map<String, V> map) {
// Map<String, V> newMap = new HashMap<>();
// map.forEach((key, value) -> {
// map.put(StringUtils.camelCase(key), value);
// });
// return newMap;
// }
//
// /**
// * 将Map的Keys转译成下划线格式的<br>
// * (例:branchNo -> branch_no)<br>
// * @param map 待转换Map
// * @return
// */
// public static <V> Map<String, V> toUnderlineStringMap(Map<String, V> map) {
// Map<String, V> newMap = new HashMap<String, V>();
// for (String key : map.keySet()) {
// newMap.put(StringUtils.uncamelCase(key), map.get(key));
// }
// return newMap;
// }
}

View File

@@ -20,7 +20,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
* @author ThinkGem
* @version 2015-01-15
*/
public class SetUtils extends org.apache.commons.collections.SetUtils {
public class SetUtils {
public static <E> HashSet<E> newHashSet() {
return new HashSet<E>();

View File

@@ -4,11 +4,8 @@
*/
package com.jeesite.common.io;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import com.alibaba.fastjson.parser.ParserConfig;
import com.jeesite.common.lang.StringUtils;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.boot.env.PropertiesPropertySourceLoader;
import org.springframework.boot.env.YamlPropertySourceLoader;
@@ -16,8 +13,10 @@ import org.springframework.core.Ordered;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import com.alibaba.fastjson.parser.ParserConfig;
import com.jeesite.common.lang.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* 配置文件加载Boot
@@ -40,7 +39,11 @@ public class PropertyLoader implements org.springframework.boot.env.PropertySour
List<PropertySource<?>> propertySources = new ArrayList<>();
if (!isLoadJeeSitePropertySource) {
isLoadJeeSitePropertySource = true;
ParserConfig.getGlobalInstance().setSafeMode(true); // 开启 FastJSON 安全模式
try {
ParserConfig.getGlobalInstance().setSafeMode(true); // 开启 FastJSON 安全模式
} catch (Exception ignored) {
// 兼容 fastjson2 的调用,不返回异常
}
Properties properties = PropertiesUtils.getInstance().getProperties();
propertySources.add(new OriginTrackedMapPropertySource("jeesite", properties));
} else {