This commit is contained in:
2022-11-04 09:25:26 +08:00
parent 7d10b53028
commit 31e08a2028
9 changed files with 68 additions and 38 deletions

View File

@@ -1,5 +1,8 @@
package net.tccn.base;
import net.tccn.base.dbq.jdbc.api.DbSource;
import net.tccn.base.dbq.jdbc.api.DbSourceMysql;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
@@ -12,11 +15,12 @@ public class Utils {
/**
* 将集合数组合并到一个Set<T> 集合中
*
* @param <T> 泛型
* @param streams 集合数组
* @return
*/
public static <T> Stream<T> concat(Stream<T> ... streams) {
public static <T> Stream<T> concat(Stream<T>... streams) {
Stream<T> stream = Stream.empty();
for (int i = 0; i < streams.length; i++) {
stream = Stream.concat(stream, streams[i]);
@@ -26,6 +30,7 @@ public class Utils {
/**
* 将字符串第一个字母转大写
*
* @param str 待转换字符串
* @return
*/
@@ -36,6 +41,7 @@ public class Utils {
/**
* 转化集合为数组,带泛型支持
*
* @param values 集合
* @param <T> 泛型
* @return
@@ -53,6 +59,7 @@ public class Utils {
/**
* 转化集合为数组,带泛型支持
*
* @param values 集合
* @param <T> 泛型
* @return
@@ -66,13 +73,12 @@ public class Utils {
}
/**
*
* @param type 待加载的class 类型
* @param name class 的实现名称
* @param <T> 泛型<T>
* @param <T> 泛型<T>
* @return
*/
public static <T extends IService> T getDbSource(Class<T> type, String name) {
public static <T extends DbSource> T getDbSource(Class<T> type, String name) {
ServiceLoader<T> loader = ServiceLoader.load(type);
Iterator<T> iterator = loader.iterator();
@@ -82,6 +88,11 @@ public class Utils {
return t;
}
}
/*if ("mysql".equalsIgnoreCase(name)) {
return (T) new DbSourceMysql();
}*/
return null;
}