Skip to content

Commit 004f8e2

Browse files
committed
Merge pull request #653 from kazuki43zoo/polishing
Polishing some code
2 parents 388ac1c + a2152b8 commit 004f8e2

File tree

14 files changed

+50
-51
lines changed

14 files changed

+50
-51
lines changed

src/main/java/org/apache/ibatis/binding/MapperMethod.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ private Object rowCountResult(int rowCount) {
9191
if (method.returnsVoid()) {
9292
result = null;
9393
} else if (Integer.class.equals(method.getReturnType()) || Integer.TYPE.equals(method.getReturnType())) {
94-
result = Integer.valueOf(rowCount);
94+
result = rowCount;
9595
} else if (Long.class.equals(method.getReturnType()) || Long.TYPE.equals(method.getReturnType())) {
96-
result = Long.valueOf(rowCount);
96+
result = (long)rowCount;
9797
} else if (Boolean.class.equals(method.getReturnType()) || Boolean.TYPE.equals(method.getReturnType())) {
98-
result = Boolean.valueOf(rowCount > 0);
98+
result = rowCount > 0;
9999
} else {
100100
throw new BindingException("Mapper method '" + command.getName() + "' has an unsupported return type: " + method.getReturnType());
101101
}
@@ -269,12 +269,12 @@ public Object convertArgsToSqlCommandParam(Object[] args) {
269269
if (args == null || paramCount == 0) {
270270
return null;
271271
} else if (!hasNamedParameters && paramCount == 1) {
272-
return args[params.keySet().iterator().next().intValue()];
272+
return args[params.keySet().iterator().next()];
273273
} else {
274274
final Map<String, Object> param = new ParamMap<Object>();
275275
int i = 0;
276276
for (Map.Entry<Integer, String> entry : params.entrySet()) {
277-
param.put(entry.getValue(), args[entry.getKey().intValue()]);
277+
param.put(entry.getValue(), args[entry.getKey()]);
278278
// issue #71, add param names as param1, param2...but ensure backward compatibility
279279
final String genericParamName = "param" + String.valueOf(i + 1);
280280
if (!param.containsKey(genericParamName)) {

src/main/java/org/apache/ibatis/builder/ParameterExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void jdbcTypeOpt(String expression, int p) {
9898
} else if (expression.charAt(p) == ',') {
9999
option(expression, p + 1);
100100
} else {
101-
throw new BuilderException("Parsing error in {" + new String(expression) + "} in position " + p);
101+
throw new BuilderException("Parsing error in {" + expression + "} in position " + p);
102102
}
103103
}
104104
}
@@ -109,7 +109,7 @@ private void jdbcType(String expression, int p) {
109109
if (right > left) {
110110
put("jdbcType", trimmedStr(expression, left, right));
111111
} else {
112-
throw new BuilderException("Parsing error in {" + new String(expression) + "} in position " + p);
112+
throw new BuilderException("Parsing error in {" + expression + "} in position " + p);
113113
}
114114
option(expression, right + 1);
115115
}

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ private LanguageDriver getLanguageDriver(Method method) {
362362
private Class<?> getParameterType(Method method) {
363363
Class<?> parameterType = null;
364364
Class<?>[] parameterTypes = method.getParameterTypes();
365-
for (int i = 0; i < parameterTypes.length; i++) {
366-
if (!RowBounds.class.isAssignableFrom(parameterTypes[i]) && !ResultHandler.class.isAssignableFrom(parameterTypes[i])) {
365+
for (Class<?> currentParameterType : parameterTypes) {
366+
if (!RowBounds.class.isAssignableFrom(currentParameterType) && !ResultHandler.class.isAssignableFrom(currentParameterType)) {
367367
if (parameterType == null) {
368-
parameterType = parameterTypes[i];
368+
parameterType = currentParameterType;
369369
} else {
370370
// issue #135
371371
parameterType = ParamMap.class;

src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class ProviderSqlSource implements SqlSource {
3838
private String[] providerMethodArgumentNames;
3939

4040
public ProviderSqlSource(Configuration config, Object provider) {
41-
String providerMethodName = null;
41+
String providerMethodName;
4242
try {
4343
this.sqlSourceParser = new SqlSourceBuilder(config);
4444
this.providerType = (Class<?>) provider.getClass().getMethod("type").invoke(provider);

src/main/java/org/apache/ibatis/cache/CacheKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ public int hashCode() {
129129
@Override
130130
public String toString() {
131131
StringBuilder returnValue = new StringBuilder().append(hashcode).append(':').append(checksum);
132-
for (int i = 0; i < updateList.size(); i++) {
133-
returnValue.append(':').append(updateList.get(i));
132+
for (Object object : updateList) {
133+
returnValue.append(':').append(object);
134134
}
135135

136136
return returnValue.toString();

src/main/java/org/apache/ibatis/datasource/jndi/JndiDataSourceFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class JndiDataSourceFactory implements DataSourceFactory {
4040
@Override
4141
public void setProperties(Properties properties) {
4242
try {
43-
InitialContext initCtx = null;
43+
InitialContext initCtx;
4444
Properties env = getEnvProperties(properties);
4545
if (env == null) {
4646
initCtx = new InitialContext();

src/main/java/org/apache/ibatis/executor/BaseExecutor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,13 @@ public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBo
198198
}
199199
CacheKey cacheKey = new CacheKey();
200200
cacheKey.update(ms.getId());
201-
cacheKey.update(Integer.valueOf(rowBounds.getOffset()));
202-
cacheKey.update(Integer.valueOf(rowBounds.getLimit()));
201+
cacheKey.update(rowBounds.getOffset());
202+
cacheKey.update(rowBounds.getLimit());
203203
cacheKey.update(boundSql.getSql());
204204
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
205205
TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();
206206
// mimic DefaultParameterHandler logic
207-
for (int i = 0; i < parameterMappings.size(); i++) {
208-
ParameterMapping parameterMapping = parameterMappings.get(i);
207+
for (ParameterMapping parameterMapping : parameterMappings) {
209208
if (parameterMapping.getMode() != ParameterMode.OUT) {
210209
Object value;
211210
String propertyName = parameterMapping.getProperty();

src/main/java/org/apache/ibatis/executor/keygen/SelectKeyGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ private void handleMultipleProperties(String[] keyProperties,
9999

100100
if (keyColumns == null || keyColumns.length == 0) {
101101
// no key columns specified, just use the property names
102-
for (int i = 0; i < keyProperties.length; i++) {
103-
setValue(metaParam, keyProperties[i], metaResult.getValue(keyProperties[i]));
102+
for (String keyProperty : keyProperties) {
103+
setValue(metaParam, keyProperty, metaResult.getValue(keyProperty));
104104
}
105105
} else {
106106
if (keyColumns.length != keyProperties.length) {

src/main/java/org/apache/ibatis/executor/loader/cglib/CglibProxyFactory.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static Object crateProxy(Class<?> type, Callback callback, List<Class<?>> constr
8686
} catch (SecurityException e) {
8787
// nothing to do here
8888
}
89-
Object enhanced = null;
89+
Object enhanced;
9090
if (constructorArgTypes.isEmpty()) {
9191
enhanced = enhancer.create();
9292
} else {
@@ -99,13 +99,13 @@ static Object crateProxy(Class<?> type, Callback callback, List<Class<?>> constr
9999

100100
private static class EnhancedResultObjectProxyImpl implements MethodInterceptor {
101101

102-
private Class<?> type;
103-
private ResultLoaderMap lazyLoader;
104-
private boolean aggressive;
105-
private Set<String> lazyLoadTriggerMethods;
106-
private ObjectFactory objectFactory;
107-
private List<Class<?>> constructorArgTypes;
108-
private List<Object> constructorArgs;
102+
private final Class<?> type;
103+
private final ResultLoaderMap lazyLoader;
104+
private final boolean aggressive;
105+
private final Set<String> lazyLoadTriggerMethods;
106+
private final ObjectFactory objectFactory;
107+
private final List<Class<?>> constructorArgTypes;
108+
private final List<Object> constructorArgs;
109109

110110
private EnhancedResultObjectProxyImpl(Class<?> type, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
111111
this.type = type;
@@ -131,7 +131,7 @@ public Object intercept(Object enhanced, Method method, Object[] args, MethodPro
131131
try {
132132
synchronized (lazyLoader) {
133133
if (WRITE_REPLACE_METHOD.equals(methodName)) {
134-
Object original = null;
134+
Object original;
135135
if (constructorArgTypes.isEmpty()) {
136136
original = objectFactory.create(type);
137137
} else {

src/main/java/org/apache/ibatis/executor/loader/javassist/JavassistProxyFactory.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static Object crateProxy(Class<?> type, MethodHandler callback, List<Class<?>> c
8787
// nothing to do here
8888
}
8989

90-
Object enhanced = null;
90+
Object enhanced;
9191
Class<?>[] typesArray = constructorArgTypes.toArray(new Class[constructorArgTypes.size()]);
9292
Object[] valuesArray = constructorArgs.toArray(new Object[constructorArgs.size()]);
9393
try {
@@ -101,13 +101,13 @@ static Object crateProxy(Class<?> type, MethodHandler callback, List<Class<?>> c
101101

102102
private static class EnhancedResultObjectProxyImpl implements MethodHandler {
103103

104-
private Class<?> type;
105-
private ResultLoaderMap lazyLoader;
106-
private boolean aggressive;
107-
private Set<String> lazyLoadTriggerMethods;
108-
private ObjectFactory objectFactory;
109-
private List<Class<?>> constructorArgTypes;
110-
private List<Object> constructorArgs;
104+
private final Class<?> type;
105+
private final ResultLoaderMap lazyLoader;
106+
private final boolean aggressive;
107+
private final Set<String> lazyLoadTriggerMethods;
108+
private final ObjectFactory objectFactory;
109+
private final List<Class<?>> constructorArgTypes;
110+
private final List<Object> constructorArgs;
111111

112112
private EnhancedResultObjectProxyImpl(Class<?> type, ResultLoaderMap lazyLoader, Configuration configuration, ObjectFactory objectFactory, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
113113
this.type = type;
@@ -133,7 +133,7 @@ public Object invoke(Object enhanced, Method method, Method methodProxy, Object[
133133
try {
134134
synchronized (lazyLoader) {
135135
if (WRITE_REPLACE_METHOD.equals(methodName)) {
136-
Object original = null;
136+
Object original;
137137
if (constructorArgTypes.isEmpty()) {
138138
original = objectFactory.create(type);
139139
} else {

0 commit comments

Comments
 (0)