Remove unnecessary boxing/unboxing

This commit is contained in:
Mahmoud Ben Hassine
2023-06-12 16:17:32 +02:00
parent 7babb341f5
commit c5b4f1a777
26 changed files with 62 additions and 53 deletions

View File

@@ -172,7 +172,7 @@ public abstract class AbstractStepParser {
String isAbstract = stepElement.getAttribute("abstract");
if (StringUtils.hasText(isAbstract)) {
bd.setAbstract(Boolean.valueOf(isAbstract));
bd.setAbstract(Boolean.parseBoolean(isAbstract));
}
String jobRepositoryRef = stepElement.getAttribute(JOB_REPO_ATTR);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@ import org.springframework.util.xml.DomUtils;
* Internal parser for the <chunk/> element inside a step.
*
* @author Thomas Risberg
* @author Mahmoud Ben Hassine
* @since 2.0
*/
public class ChunkElementParser {
@@ -141,7 +142,7 @@ public class ChunkElementParser {
if (!CollectionUtils.isEmpty(exceptionClassElements)) {
skippableExceptions.setMergeEnabled(exceptionClassElements.get(0).hasAttribute(MERGE_ATTR)
&& Boolean.valueOf(exceptionClassElements.get(0).getAttribute(MERGE_ATTR)));
&& Boolean.parseBoolean(exceptionClassElements.get(0).getAttribute(MERGE_ATTR)));
}
// Even if there is no retryLimit, we can still accept exception
// classes for an abstract parent bean definition
@@ -167,7 +168,7 @@ public class ChunkElementParser {
if (!CollectionUtils.isEmpty(exceptionClassElements)) {
retryableExceptions.setMergeEnabled(exceptionClassElements.get(0).hasAttribute(MERGE_ATTR)
&& Boolean.valueOf(exceptionClassElements.get(0).getAttribute(MERGE_ATTR)));
&& Boolean.parseBoolean(exceptionClassElements.get(0).getAttribute(MERGE_ATTR)));
}
// Even if there is no retryLimit, we can still accept exception
// classes for an abstract parent bean definition
@@ -296,7 +297,7 @@ public class ChunkElementParser {
parserContext.pushContainingComponent(compositeDef);
ManagedList<BeanMetadataElement> retryListenerBeans = new ManagedList<>();
retryListenerBeans.setMergeEnabled(listenersElement.hasAttribute(MERGE_ATTR)
&& Boolean.valueOf(listenersElement.getAttribute(MERGE_ATTR)));
&& Boolean.parseBoolean(listenersElement.getAttribute(MERGE_ATTR)));
handleRetryListenerElements(parserContext, listenersElement, retryListenerBeans, enclosing);
propertyValues.addPropertyValue("retryListeners", retryListenerBeans);
parserContext.popAndRegisterContainingComponent();
@@ -319,7 +320,7 @@ public class ChunkElementParser {
if (streamsElement != null) {
ManagedList<RuntimeBeanReference> streamBeans = new ManagedList<>();
streamBeans.setMergeEnabled(streamsElement.hasAttribute(MERGE_ATTR)
&& Boolean.valueOf(streamsElement.getAttribute(MERGE_ATTR)));
&& Boolean.parseBoolean(streamsElement.getAttribute(MERGE_ATTR)));
List<Element> streamElements = DomUtils.getChildElementsByTagName(streamsElement, "stream");
if (streamElements != null) {
for (Element streamElement : streamElements) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@ import java.util.Map;
*
* @author Thomas Risberg
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
public class CoreNamespaceUtils {
@@ -202,7 +203,7 @@ public class CoreNamespaceUtils {
*/
public static boolean isAbstract(Element element) {
String abstractAttr = element.getAttribute("abstract");
return StringUtils.hasText(abstractAttr) && Boolean.valueOf(abstractAttr);
return StringUtils.hasText(abstractAttr) && Boolean.parseBoolean(abstractAttr);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@ import org.w3c.dom.Element;
* definition for a {@link org.springframework.batch.core.Job}.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class JobParser extends AbstractSingleBeanDefinitionParser {
@@ -135,7 +136,7 @@ public class JobParser extends AbstractSingleBeanDefinitionParser {
parserContext.pushContainingComponent(compositeDef);
ManagedList<BeanDefinition> listeners = new ManagedList<>();
listeners.setMergeEnabled(listenersElement.hasAttribute(MERGE_ATTR)
&& Boolean.valueOf(listenersElement.getAttribute(MERGE_ATTR)));
&& Boolean.parseBoolean(listenersElement.getAttribute(MERGE_ATTR)));
List<Element> listenerElements = DomUtils.getChildElementsByTagName(listenersElement, "listener");
for (Element listenerElement : listenerElements) {
listeners.add(jobListenerParser.parse(listenerElement, parserContext));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2013 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ import org.w3c.dom.Element;
* attributes from the configuration.
*
* @author Dan Garrette
* @author Mahmoud Ben Hassine
* @since 2.0
* @see AbstractListenerParser
*/
@@ -78,7 +79,7 @@ public class StepListenerParser extends AbstractListenerParser {
listenerBeans = (ManagedList<BeanDefinition>) propertyValues.getPropertyValue("listeners").getValue();
}
listenerBeans.setMergeEnabled(listenersElement.hasAttribute(MERGE_ATTR)
&& Boolean.valueOf(listenersElement.getAttribute(MERGE_ATTR)));
&& Boolean.parseBoolean(listenersElement.getAttribute(MERGE_ATTR)));
List<Element> listenerElements = DomUtils.getChildElementsByTagName(listenersElement, "listener");
if (listenerElements != null) {
for (Element listenerElement : listenerElements) {

View File

@@ -595,7 +595,7 @@ public class StepParserStepFactoryBean<I, O> implements FactoryBean<Step>, BeanN
}
private boolean isTrue(Boolean b) {
return b != null && b.booleanValue();
return b != null && b;
}
private boolean isPositive(Integer n) {

View File

@@ -212,7 +212,7 @@ public class TaskletParser {
Element exceptionClassesElement = children.get(0);
ManagedList<TypedStringValue> list = new ManagedList<>();
list.setMergeEnabled(exceptionClassesElement.hasAttribute(MERGE_ATTR)
&& Boolean.valueOf(exceptionClassesElement.getAttribute(MERGE_ATTR)));
&& Boolean.parseBoolean(exceptionClassesElement.getAttribute(MERGE_ATTR)));
addExceptionClasses("include", exceptionClassesElement, list, parserContext);
propertyValues.addPropertyValue(propertyName, list);
}

View File

@@ -190,7 +190,7 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
if (tokens.length <= 2) {
return true;
}
return Boolean.valueOf(tokens[2]);
return Boolean.parseBoolean(tokens[2]);
}
}

View File

@@ -111,7 +111,7 @@ public class JsonJobParametersConverter extends DefaultJobParametersConverter {
}
boolean parameterIdentifying = true;
if (jobParameterDefinition.identifying() != null && !jobParameterDefinition.identifying().isEmpty()) {
parameterIdentifying = Boolean.valueOf(jobParameterDefinition.identifying());
parameterIdentifying = Boolean.parseBoolean(jobParameterDefinition.identifying());
}
Object parameterTypedValue = this.conversionService.convert(jobParameterDefinition.value(), parameterType);
return new JobParameter(parameterTypedValue, parameterType, parameterIdentifying);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2013 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import org.springframework.batch.core.ExitStatus;
* @author Stijn Maller
* @author Lucas Ward
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
public class SimpleJvmExitCodeMapper implements ExitCodeMapper {
@@ -81,7 +82,7 @@ public class SimpleJvmExitCodeMapper implements ExitCodeMapper {
logger.fatal("Error mapping exit code, generic exit status returned.", ex);
}
return (statusCode != null) ? statusCode.intValue() : JVM_EXITCODE_GENERIC_ERROR;
return (statusCode != null) ? statusCode : JVM_EXITCODE_GENERIC_ERROR;
}
}

View File

@@ -390,7 +390,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_JOB_EXECUTION), Integer.class,
jobExecution.getId());
if (currentVersion != jobExecution.getVersion().intValue()) {
if (currentVersion != jobExecution.getVersion()) {
String status = getJdbcTemplate().queryForObject(getQuery(GET_STATUS), String.class, jobExecution.getId());
jobExecution.upgradeStatus(BatchStatus.valueOf(status));
jobExecution.setVersion(currentVersion);

View File

@@ -96,7 +96,7 @@ class JobParametersBuilderTests {
assertEquals(date, parameters.getDate("SCHEDULE_DATE"));
assertEquals(1L, parameters.getLong("LONG").longValue());
assertEquals("string value", parameters.getString("STRING"));
assertEquals(1, parameters.getDouble("DOUBLE").doubleValue(), 1e-15);
assertEquals(1, parameters.getDouble("DOUBLE"), 1e-15);
assertFalse(parameters.getParameters().get("SCHEDULE_DATE").isIdentifying());
assertFalse(parameters.getParameters().get("LONG").isIdentifying());
assertFalse(parameters.getParameters().get("STRING").isIdentifying());
@@ -112,7 +112,7 @@ class JobParametersBuilderTests {
JobParameters parameters = this.parametersBuilder.toJobParameters();
assertEquals(date, parameters.getDate("SCHEDULE_DATE"));
assertEquals(1L, parameters.getLong("LONG").longValue());
assertEquals(1, parameters.getDouble("DOUBLE").doubleValue(), 1e-15);
assertEquals(1, parameters.getDouble("DOUBLE"), 1e-15);
assertEquals("string value", parameters.getString("STRING"));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -249,7 +249,7 @@ class StepParserStepFactoryBeanTests {
assertTrue(step instanceof TaskletStep);
Object throttleLimit = ReflectionTestUtils.getField(ReflectionTestUtils.getField(step, "stepOperations"),
"throttleLimit");
assertEquals(Integer.valueOf(10), throttleLimit);
assertEquals(10, throttleLimit);
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
assertTrue(tasklet instanceof ChunkOrientedTasklet<?>);
assertFalse((Boolean) ReflectionTestUtils.getField(tasklet, "buffering"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ public class StepParserTests {
TaskletStep bean = (TaskletStep) factory.getObject();
assertEquals(25, bean.getStartLimit(), "wrong start-limit:");
Object throttleLimit = ReflectionTestUtils.getField(factory, "throttleLimit");
assertEquals(Integer.valueOf(10), throttleLimit);
assertEquals(10, throttleLimit);
}
@Test

View File

@@ -51,7 +51,7 @@ public abstract class AbstractExecutionContextSerializerTests {
@Test
void testSerializeAMap() throws Exception {
Map<String, Object> m1 = new HashMap<>();
m1.put("object1", Long.valueOf(12345L));
m1.put("object1", 12345L);
m1.put("object2", "OBJECT TWO");
// Use a date after 1971 (otherwise daylight saving screws up)...
m1.put("object3", new Date(123456790123L));
@@ -141,7 +141,7 @@ public abstract class AbstractExecutionContextSerializerTests {
ComplexObject o1 = new ComplexObject();
o1.setName("02345");
Map<String, Object> m = new HashMap<>();
m.put("object1", Long.valueOf(12345L));
m.put("object1", 12345L);
m.put("object2", "OBJECT TWO");
o1.setMap(m);
o1.setNumber(new BigDecimal("12345.67"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 the original author or authors.
* Copyright 2008-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -181,7 +181,7 @@ public abstract class AbstractJobInstanceDaoTests {
String paramKey = "myID";
int instanceCount = 6;
for (int i = 1; i <= instanceCount; i++) {
JobParameters params = new JobParametersBuilder().addLong(paramKey, Long.valueOf(i)).toJobParameters();
JobParameters params = new JobParametersBuilder().addLong(paramKey, (long) i).toJobParameters();
dao.createJobInstance(multiInstanceJob, params);
}