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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 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.
@@ -38,6 +38,7 @@ import org.springframework.util.Assert;
* representing the {@link Void#TYPE}).
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
public class RepeatOperationsInterceptor implements MethodInterceptor {
@@ -132,7 +133,7 @@ public class RepeatOperationsInterceptor implements MethodInterceptor {
* @return
*/
private boolean isComplete(Object result) {
return result == null || (result instanceof Boolean) && !((Boolean) result).booleanValue();
return result == null || (result instanceof Boolean) && !(Boolean) result;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 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.
@@ -27,7 +27,7 @@ public class IntArrayPropertyEditor extends PropertyEditorSupport {
String[] strs = StringUtils.commaDelimitedListToStringArray(text);
int[] value = new int[strs.length];
for (int i = 0; i < value.length; i++) {
value[i] = Integer.valueOf(strs[i].trim()).intValue();
value[i] = Integer.parseInt(strs[i].trim());
}
setValue(value);
}

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.
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test;
/**
* @author Lucas Ward
* @author Will Schipp
* @author Mahmoud Ben Hassine
*/
class ColumnMapExecutionContextRowMapperTests {
@@ -42,8 +43,8 @@ class ColumnMapExecutionContextRowMapperTests {
mapper = new ColumnMapItemPreparedStatementSetter();
key = new LinkedHashMap<>(2);
key.put("1", Integer.valueOf(1));
key.put("2", Integer.valueOf(2));
key.put("1", 1);
key.put("2", 2);
}
@Test
@@ -55,8 +56,8 @@ class ColumnMapExecutionContextRowMapperTests {
@Test
void testCreateSetter() throws Exception {
ps.setObject(1, Integer.valueOf(1));
ps.setObject(2, Integer.valueOf(2));
ps.setObject(1, 1);
ps.setObject(2, 2);
mapper.setValues(key, ps);
}

View File

@@ -38,7 +38,7 @@ public class FlatFileItemReaderCommonTests extends AbstractItemStreamItemReaderT
@Override
public Foo mapLine(String line, int lineNumber) {
Foo foo = new Foo();
foo.setValue(Integer.valueOf(line.trim()));
foo.setValue(Integer.parseInt(line.trim()));
return foo;
}
});

View File

@@ -37,7 +37,7 @@ class MultiResourceItemReaderFlatFileTests extends AbstractItemStreamItemReaderT
@Override
public Foo mapLine(String line, int lineNumber) throws Exception {
Foo foo = new Foo();
foo.setValue(Integer.valueOf(line));
foo.setValue(Integer.parseInt(line));
return foo;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 the original author or authors.
* Copyright 2016-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.
@@ -223,8 +223,8 @@ class FlatFileItemReaderBuilderTests {
.fieldSetMapper(fieldSet -> {
Foo item = new Foo();
item.setFirst(Integer.valueOf(fieldSet.readString(0).replaceAll("\\|", "")));
item.setSecond(Integer.valueOf(fieldSet.readString(1).replaceAll("\\|", "")));
item.setFirst(Integer.parseInt(fieldSet.readString(0).replaceAll("\\|", "")));
item.setSecond(Integer.parseInt(fieldSet.readString(1).replaceAll("\\|", "")));
item.setThird(fieldSet.readString(2).replaceAll("\\|", ""));
return item;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-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.
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.mock;
/**
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
*/
class MultiResourceItemReaderBuilderTests extends AbstractItemStreamItemReaderTests {
@@ -45,7 +46,7 @@ class MultiResourceItemReaderBuilderTests extends AbstractItemStreamItemReaderTe
fileReader.setLineMapper((line, lineNumber) -> {
Foo foo = new Foo();
foo.setValue(Integer.valueOf(line));
foo.setValue(Integer.parseInt(line));
return foo;
});
fileReader.setSaveState(true);

View File

@@ -28,6 +28,7 @@ import org.springframework.lang.Nullable;
/**
* @author Jimmy Praet
* @author Mahmoud Ben Hassine
*/
class ClassifierCompositeItemProcessorTests {
@@ -98,9 +99,9 @@ class ClassifierCompositeItemProcessorTests {
classifier.setTypeMap(typeMap);
processor.setClassifier(classifier);
assertEquals("int: 1", processor.process(Integer.valueOf(1)).toString());
assertEquals("long: 2", processor.process(Long.valueOf(2)).toString());
assertEquals("number: 3", processor.process(Byte.valueOf((byte) 3)).toString());
assertEquals("int: 1", processor.process(1).toString());
assertEquals("long: 2", processor.process(2L).toString());
assertEquals("number: 3", processor.process((byte) 3).toString());
}
}

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 RepeatOperationsInterceptorTests {
public Object service() throws Exception {
count++;
if (count <= maxService) {
return Integer.valueOf(count);
return count;
}
else {
return null;

View File

@@ -283,9 +283,9 @@ class SkipSampleFunctionalTests {
assertEquals(new BigDecimal("340.45"), jobExecution.getExecutionContext().get(TradeWriter.TOTAL_AMOUNT_KEY));
Map<String, Object> step1Execution = getStepExecutionAsMap(jobExecution, "step1");
assertEquals(Long.valueOf(4L), step1Execution.get("COMMIT_COUNT"));
assertEquals(Long.valueOf(8L), step1Execution.get("READ_COUNT"));
assertEquals(Long.valueOf(7L), step1Execution.get("WRITE_COUNT"));
assertEquals(4L, step1Execution.get("COMMIT_COUNT"));
assertEquals(8L, step1Execution.get("READ_COUNT"));
assertEquals(7L, step1Execution.get("WRITE_COUNT"));
}
private void validateLaunchWithoutSkips(JobExecution jobExecution) {