convertListFrom
This commit is contained in:
@@ -66,6 +66,8 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
|
||||
private final ConcurrentHashMap<Class, BiFunction> fieldFuncs = new ConcurrentHashMap();
|
||||
|
||||
private final ConcurrentHashMap<Type, Type> genericListTypes = new ConcurrentHashMap<>();
|
||||
|
||||
private final Set<Class> skipIgnores = new HashSet();
|
||||
|
||||
final Set<String> ignoreMapColumns = new HashSet();
|
||||
@@ -253,6 +255,8 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
|
||||
public abstract ConvertFactory createChild(int features);
|
||||
|
||||
protected abstract ConvertFactory rootFactory();
|
||||
|
||||
protected SimpledCoder createEnumSimpledCoder(Class enumClass) {
|
||||
return new EnumSimpledCoder(this, enumClass);
|
||||
}
|
||||
@@ -372,6 +376,11 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
return nullable ? addFeature(Convert.FEATURE_NULLABLE) : removeFeature(Convert.FEATURE_NULLABLE);
|
||||
}
|
||||
|
||||
protected Type createGenericListType(Type componentType) {
|
||||
ConcurrentHashMap<Type, Type> map = rootFactory().genericListTypes;
|
||||
return map.computeIfAbsent(componentType, t -> TypeToken.createParameterizedType(null, List.class, t));
|
||||
}
|
||||
|
||||
public static boolean checkTinyFeature(int features) {
|
||||
return (features & Convert.FEATURE_TINY) > 0;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.redkale.convert;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文本序列化/反序列化操作类
|
||||
@@ -29,6 +30,10 @@ public abstract class TextConvert<R extends Reader, W extends Writer> extends Co
|
||||
|
||||
public abstract <T> T convertFrom(final Type type, final String text);
|
||||
|
||||
public <T> List<T> convertListFrom(final Type componentType, final String text) {
|
||||
return (List) convertFrom(factory.createGenericListType(componentType), text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化
|
||||
*
|
||||
|
||||
@@ -89,6 +89,11 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConvertFactory rootFactory() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static BsonFactory root() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -91,6 +91,11 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConvertFactory rootFactory() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static JsonFactory root() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,11 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConvertFactory rootFactory() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ProtobufFactory root() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
*/
|
||||
package org.redkale.util;
|
||||
|
||||
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
|
||||
/**
|
||||
* 获取泛型的Type类
|
||||
@@ -568,7 +567,8 @@ public abstract class TypeToken<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态创建 ParameterizedType
|
||||
* 动态创建 ParameterizedType <br>
|
||||
* 例如: List<String>: createParameterizedType(null, List.class, String.class)
|
||||
*
|
||||
* @param ownerType0 ParameterizedType 的 ownerType, 一般为null
|
||||
* @param rawType0 ParameterizedType 的 rawType
|
||||
|
||||
@@ -21,11 +21,15 @@ public class ScheduledTest {
|
||||
ScheduleManagerService manager = ScheduleManagerService.create(null);
|
||||
manager.init(null);
|
||||
ScheduledTestService service = new ScheduledTestService();
|
||||
long s = 1000 - System.currentTimeMillis() % 1000;
|
||||
if (s > 0) {
|
||||
Utility.sleep(s);
|
||||
}
|
||||
manager.schedule(service);
|
||||
System.out.println("开始执行");
|
||||
Utility.sleep(2000);
|
||||
manager.stop("task2");
|
||||
Utility.sleep(1001);
|
||||
Utility.sleep(1010);
|
||||
manager.unschedule(service);
|
||||
manager.destroy(null);
|
||||
Assertions.assertEquals(3, service.count1.get());
|
||||
|
||||
Reference in New Issue
Block a user