Skip to content

Commit 70a4cd0

Browse files
committed
made this class final and clean up a few compiler warnings.
Also converter the JDBC_TYPE_HANDLER_MAP to an EnumMap
1 parent 1395dd7 commit 70a4cd0

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import java.math.BigDecimal;
77
import java.util.Date;
88
import java.util.HashMap;
9+
import java.util.EnumMap;
910
import java.util.Map;
1011
import java.util.Set;
1112

12-
public class TypeHandlerRegistry {
13+
public final class TypeHandlerRegistry {
1314

14-
private static final Map<Class, Class> reversePrimitiveMap = new HashMap<Class, Class>() {
15+
private static final Map<Class<?>, Class<?>> reversePrimitiveMap = new HashMap<Class<?>, Class<?>>() {
1516
{
1617
put(Byte.class, byte.class);
1718
put(Short.class, short.class);
@@ -23,8 +24,8 @@ public class TypeHandlerRegistry {
2324
}
2425
};
2526

26-
private final Map<JdbcType, TypeHandler> JDBC_TYPE_HANDLER_MAP = new HashMap<JdbcType, TypeHandler>();
27-
private final Map<Class, Map<JdbcType, TypeHandler>> TYPE_HANDLER_MAP = new HashMap<Class, Map<JdbcType, TypeHandler>>();
27+
private final Map<JdbcType, TypeHandler> JDBC_TYPE_HANDLER_MAP = new EnumMap<JdbcType, TypeHandler>(JdbcType.class);
28+
private final Map<Class<?>, Map<JdbcType, TypeHandler>> TYPE_HANDLER_MAP = new HashMap<Class<?>, Map<JdbcType, TypeHandler>>();
2829
private final TypeHandler UNKNOWN_TYPE_HANDLER = new UnknownTypeHandler(this);
2930

3031
public TypeHandlerRegistry() {
@@ -98,29 +99,29 @@ public TypeHandlerRegistry() {
9899
register(java.sql.Timestamp.class, new SqlTimestampTypeHandler());
99100
}
100101

101-
public boolean hasTypeHandler(Class javaType) {
102+
public boolean hasTypeHandler(Class<?> javaType) {
102103
return hasTypeHandler(javaType, null);
103104
}
104105

105-
public boolean hasTypeHandler(Class javaType, JdbcType jdbcType) {
106+
public boolean hasTypeHandler(Class<?> javaType, JdbcType jdbcType) {
106107
return javaType != null && getTypeHandler(javaType, jdbcType) != null;
107108
}
108109

109-
public TypeHandler getTypeHandler(Class type) {
110+
public TypeHandler getTypeHandler(Class<?> type) {
110111
return getTypeHandler(type, null);
111112
}
112113

113114
public TypeHandler getTypeHandler(JdbcType jdbcType) {
114115
return JDBC_TYPE_HANDLER_MAP.get(jdbcType);
115116
}
116117

117-
public TypeHandler getTypeHandler(Class type, JdbcType jdbcType) {
118-
Map jdbcHandlerMap = TYPE_HANDLER_MAP.get(type);
118+
public TypeHandler getTypeHandler(Class<?> type, JdbcType jdbcType) {
119+
Map<JdbcType, TypeHandler> jdbcHandlerMap = TYPE_HANDLER_MAP.get(type);
119120
TypeHandler handler = null;
120121
if (jdbcHandlerMap != null) {
121-
handler = (TypeHandler) jdbcHandlerMap.get(jdbcType);
122+
handler = jdbcHandlerMap.get(jdbcType);
122123
if (handler == null) {
123-
handler = (TypeHandler) jdbcHandlerMap.get(null);
124+
handler = jdbcHandlerMap.get(null);
124125
}
125126
}
126127
if (handler == null && type != null && Enum.class.isAssignableFrom(type)) {
@@ -137,11 +138,11 @@ public void register(JdbcType jdbcType, TypeHandler handler) {
137138
JDBC_TYPE_HANDLER_MAP.put(jdbcType, handler);
138139
}
139140

140-
public void register(Class type, TypeHandler handler) {
141+
public void register(Class<?> type, TypeHandler handler) {
141142
register(type, null, handler);
142143
}
143144

144-
public void register(Class type, JdbcType jdbcType, TypeHandler handler) {
145+
public void register(Class<?> type, JdbcType jdbcType, TypeHandler handler) {
145146
Map<JdbcType, TypeHandler> map = TYPE_HANDLER_MAP.get(type);
146147
if (map == null) {
147148
map = new HashMap<JdbcType, TypeHandler>();
@@ -154,12 +155,12 @@ public void register(Class type, JdbcType jdbcType, TypeHandler handler) {
154155
}
155156

156157
public void register(String packageName) {
157-
ResolverUtil<Class> resolverUtil = new ResolverUtil<Class>();
158+
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<Class<?>>();
158159
resolverUtil.find(new ResolverUtil.IsA(TypeHandler.class), packageName);
159-
Set<Class<? extends Class>> handlerSet = resolverUtil.getClasses();
160+
Set<Class<? extends Class<?>>> handlerSet = resolverUtil.getClasses();
160161

161162
TypeHandler handler;
162-
for (Class type : handlerSet) {
163+
for (Class<?> type : handlerSet) {
163164
@SuppressWarnings({"unchecked"})
164165
Annotation annotation = type.getAnnotation(MappedTypes.class);
165166
try {
@@ -169,7 +170,7 @@ public void register(String packageName) {
169170
}
170171
if (null != annotation) {
171172
MappedTypes mappedType = (MappedTypes) annotation;
172-
for (Class handledType : mappedType.value()) {
173+
for (Class<?> handledType : mappedType.value()) {
173174
register(handledType, handler);
174175
}
175176
}

0 commit comments

Comments
 (0)