类型转换器相关代码调整.
This commit is contained in:
+7
-7
@@ -19,20 +19,17 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
import fun.asgc.neutrino.core.type.TypeMatcher;
|
||||
import fun.asgc.neutrino.core.type.TypeMatcherGroup;
|
||||
package fun.asgc.neutrino.core.type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 抽象的扩展类型匹配器组
|
||||
* 抽象的匹配器组
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public abstract class AbstractExtensionMatcherGroup implements TypeMatcherGroup {
|
||||
public abstract class AbstractMatcherGroup implements TypeMatcherGroup {
|
||||
/**
|
||||
* 最小距离
|
||||
*/
|
||||
@@ -48,12 +45,15 @@ public abstract class AbstractExtensionMatcherGroup implements TypeMatcherGroup
|
||||
*/
|
||||
private List<TypeMatcher> matchers;
|
||||
|
||||
public AbstractExtensionMatcherGroup(int distanceMin, int distanceMax) {
|
||||
public AbstractMatcherGroup(int distanceMin, int distanceMax) {
|
||||
this.distanceMin = distanceMin;
|
||||
this.distanceMax = distanceMax;
|
||||
this.matchers = new ArrayList<>();
|
||||
this.init();
|
||||
}
|
||||
|
||||
protected abstract void init();
|
||||
|
||||
@Override
|
||||
public List<TypeMatcher> matchers() {
|
||||
return matchers;
|
||||
@@ -60,14 +60,6 @@ public class TypeMatchers {
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册自定义类型匹配器具
|
||||
* @param typeMatcher
|
||||
*/
|
||||
public synchronized void registerCustomTypeMatcher(TypeMatcher typeMatcher) {
|
||||
customTypeMatcherList.add(typeMatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册内置扩展匹配器组
|
||||
* @param typeMatcherGroup
|
||||
@@ -91,6 +83,32 @@ public class TypeMatchers {
|
||||
extensionMatcherGroupList.add(typeMatcherGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册自定义类型匹配器具
|
||||
* @param typeMatcher
|
||||
*/
|
||||
public synchronized void registerCustomTypeMatcher(TypeMatcher typeMatcher) {
|
||||
Assert.notNull(typeMatcher, "匹配器不能为空!");
|
||||
customTypeMatcherList.add(typeMatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册自定义匹配器组
|
||||
* @param typeMatcherGroup
|
||||
*/
|
||||
public synchronized void registerCustomTypeMatcher(TypeMatcherGroup typeMatcherGroup) {
|
||||
if (null == typeMatcherGroup || CollectionUtil.isEmpty(typeMatcherGroup.matchers())) {
|
||||
return;
|
||||
}
|
||||
// 自定义匹配器距离区间检测
|
||||
if (typeMatcherGroup.getDistanceMin() < TypeMatchLevel.CUSTOM.getDistanceMin() ||
|
||||
typeMatcherGroup.getDistanceMax() > TypeMatchLevel.CUSTOM.getDistanceMax() ||
|
||||
typeMatcherGroup.getDistanceMax() < typeMatcherGroup.getDistanceMin()) {
|
||||
throw new RuntimeException(String.format("自定义扩展器:[%s] 距离区间定义有误!", typeMatcherGroup.getClass().getSimpleName()));
|
||||
}
|
||||
customTypeMatcherList.addAll(typeMatcherGroup.matchers());
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配
|
||||
* @param clazz
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
import fun.asgc.neutrino.core.type.AbstractMatcherGroup;
|
||||
import fun.asgc.neutrino.core.type.TypeMatchInfo;
|
||||
import fun.asgc.neutrino.core.type.TypeMatcher;
|
||||
|
||||
@@ -32,13 +33,13 @@ import java.util.Set;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public class ArrayMatcherGroup extends AbstractExtensionMatcherGroup {
|
||||
public class ArrayMatcherGroup extends AbstractMatcherGroup {
|
||||
|
||||
public ArrayMatcherGroup(int distanceMin, int distanceMax) {
|
||||
super(distanceMin, distanceMax);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// List -> Object[]
|
||||
add(new TypeMatcher() {
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
import fun.asgc.neutrino.core.type.AbstractMatcherGroup;
|
||||
import fun.asgc.neutrino.core.type.TypeMatchInfo;
|
||||
import fun.asgc.neutrino.core.type.TypeMatcher;
|
||||
import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
@@ -30,13 +31,13 @@ import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public class BooleanMatcherGroup extends AbstractExtensionMatcherGroup {
|
||||
public class BooleanMatcherGroup extends AbstractMatcherGroup {
|
||||
|
||||
public BooleanMatcherGroup(int distanceMin, int distanceMax) {
|
||||
super(distanceMin, distanceMax);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
add(new TypeMatcher() {
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
|
||||
import fun.asgc.neutrino.core.type.AbstractMatcherGroup;
|
||||
import fun.asgc.neutrino.core.type.TypeMatchInfo;
|
||||
import fun.asgc.neutrino.core.type.TypeMatcher;
|
||||
import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
@@ -36,13 +37,13 @@ import java.util.Date;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public class DateMatcherGroup extends AbstractExtensionMatcherGroup {
|
||||
public class DateMatcherGroup extends AbstractMatcherGroup {
|
||||
|
||||
public DateMatcherGroup(int distanceMin, int distanceMax) {
|
||||
super(distanceMin, distanceMax);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// Long -> Date
|
||||
add(new TypeMatcher() {
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
|
||||
import fun.asgc.neutrino.core.type.AbstractMatcherGroup;
|
||||
import fun.asgc.neutrino.core.type.TypeMatchInfo;
|
||||
import fun.asgc.neutrino.core.type.TypeMatcher;
|
||||
|
||||
@@ -34,13 +35,13 @@ import java.util.stream.Stream;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public class ListMatcherGroup extends AbstractExtensionMatcherGroup {
|
||||
public class ListMatcherGroup extends AbstractMatcherGroup {
|
||||
|
||||
public ListMatcherGroup(int distanceMin, int distanceMax) {
|
||||
super(distanceMin, distanceMax);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
add(new TypeMatcher() {
|
||||
@Override
|
||||
|
||||
+4
-2
@@ -21,18 +21,20 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
import fun.asgc.neutrino.core.type.AbstractMatcherGroup;
|
||||
|
||||
/**
|
||||
* Map匹配器组
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public class MapMatcherGroup extends AbstractExtensionMatcherGroup {
|
||||
public class MapMatcherGroup extends AbstractMatcherGroup {
|
||||
|
||||
public MapMatcherGroup(int distanceMin, int distanceMax) {
|
||||
super(distanceMin, distanceMax);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
import fun.asgc.neutrino.core.type.AbstractMatcherGroup;
|
||||
import fun.asgc.neutrino.core.type.TypeMatchInfo;
|
||||
import fun.asgc.neutrino.core.type.TypeMatcher;
|
||||
import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
@@ -30,13 +31,13 @@ import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public class NumberMatcherGroup extends AbstractExtensionMatcherGroup {
|
||||
public class NumberMatcherGroup extends AbstractMatcherGroup {
|
||||
|
||||
public NumberMatcherGroup(int distanceMin, int distanceMax) {
|
||||
super(distanceMin, distanceMax);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// String -> Byte
|
||||
add(new TypeMatcher() {
|
||||
|
||||
+3
-3
@@ -21,8 +21,8 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
import fun.asgc.neutrino.core.type.AbstractMatcherGroup;
|
||||
import fun.asgc.neutrino.core.type.TypeMatchInfo;
|
||||
import fun.asgc.neutrino.core.type.TypeMatchLevel;
|
||||
import fun.asgc.neutrino.core.type.TypeMatcher;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -34,13 +34,13 @@ import java.util.stream.Stream;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public class SetMatcherGroup extends AbstractExtensionMatcherGroup {
|
||||
public class SetMatcherGroup extends AbstractMatcherGroup {
|
||||
|
||||
public SetMatcherGroup(int distanceMin, int distanceMax) {
|
||||
super(distanceMin, distanceMax);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
add(new TypeMatcher() {
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.core.type.extension;
|
||||
|
||||
import fun.asgc.neutrino.core.type.AbstractMatcherGroup;
|
||||
import fun.asgc.neutrino.core.type.TypeMatchInfo;
|
||||
import fun.asgc.neutrino.core.type.TypeMatcher;
|
||||
import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
@@ -30,13 +31,13 @@ import fun.asgc.neutrino.core.util.TypeUtil;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/29
|
||||
*/
|
||||
public class StringMatcherGroup extends AbstractExtensionMatcherGroup {
|
||||
public class StringMatcherGroup extends AbstractMatcherGroup {
|
||||
|
||||
public StringMatcherGroup(int distanceMin, int distanceMax) {
|
||||
super(distanceMin, distanceMax);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// 基本类型 -> String
|
||||
add(new TypeMatcher() {
|
||||
|
||||
@@ -92,6 +92,7 @@ public class TypeUtilTest {
|
||||
|
||||
@Test
|
||||
public void conversionString() {
|
||||
typeMatchers.setEnableExtensionMatcher(false);
|
||||
System.out.println(typeMatchers.conversion("true", boolean.class));
|
||||
System.out.println(typeMatchers.conversion("100", byte.class));
|
||||
System.out.println(typeMatchers.conversion("101", short.class));
|
||||
|
||||
Reference in New Issue
Block a user