Skip to content

Commit 145c31b

Browse files
tatisledfmbenhassine
authored andcommitted
Change JobParameters to HashMap
Resolves #4179
1 parent 597ecb4 commit 145c31b

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.Collections;
2525
import java.util.Date;
26-
import java.util.LinkedHashMap;
26+
import java.util.HashMap;
2727
import java.util.List;
2828
import java.util.Map;
2929
import java.util.Objects;
@@ -58,7 +58,7 @@ public class JobParameters implements Serializable {
5858
* Default constructor.
5959
*/
6060
public JobParameters() {
61-
this.parameters = new LinkedHashMap<>();
61+
this.parameters = new HashMap<>();
6262
}
6363

6464
/**
@@ -68,7 +68,7 @@ public JobParameters() {
6868
* {@link JobParameter} value.
6969
*/
7070
public JobParameters(Map<String, JobParameter<?>> parameters) {
71-
this.parameters = new LinkedHashMap<>(parameters);
71+
this.parameters = new HashMap<>(parameters);
7272
}
7373

7474
/**

spring-batch-core/src/main/java/org/springframework/batch/core/JobParametersBuilder.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,9 +21,7 @@
2121
import java.time.LocalTime;
2222
import java.util.Date;
2323
import java.util.HashMap;
24-
import java.util.LinkedHashMap;
2524
import java.util.Map;
26-
import java.util.Properties;
2725

2826
import org.springframework.batch.core.explore.JobExplorer;
2927
import org.springframework.lang.NonNull;
@@ -57,7 +55,7 @@ public class JobParametersBuilder {
5755
* Default constructor. Initializes the builder with empty parameters.
5856
*/
5957
public JobParametersBuilder() {
60-
this.parameterMap = new LinkedHashMap<>();
58+
this.parameterMap = new HashMap<>();
6159
}
6260

6361
/**
@@ -66,7 +64,7 @@ public JobParametersBuilder() {
6664
*/
6765
public JobParametersBuilder(JobExplorer jobExplorer) {
6866
this.jobExplorer = jobExplorer;
69-
this.parameterMap = new LinkedHashMap<>();
67+
this.parameterMap = new HashMap<>();
7068
}
7169

7270
/**
@@ -85,7 +83,7 @@ public JobParametersBuilder(JobParameters jobParameters) {
8583
*/
8684
public JobParametersBuilder(JobParameters jobParameters, JobExplorer jobExplorer) {
8785
this.jobExplorer = jobExplorer;
88-
this.parameterMap = new LinkedHashMap<>(jobParameters.getParameters());
86+
this.parameterMap = new HashMap<>(jobParameters.getParameters());
8987
}
9088

9189
/**

spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersBuilderTests.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2022 the original author or authors.
2+
* Copyright 2008-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
2020
import java.util.Iterator;
2121
import java.util.List;
2222
import java.util.Map;
23-
import java.util.Properties;
23+
import java.util.Set;
2424

2525
import org.junit.jupiter.api.BeforeEach;
2626
import org.junit.jupiter.api.Test;
@@ -29,6 +29,7 @@
2929
import org.springframework.batch.core.job.SimpleJob;
3030
import org.springframework.batch.core.launch.support.RunIdIncrementer;
3131

32+
import static org.assertj.core.api.Assertions.assertThat;
3233
import static org.junit.jupiter.api.Assertions.assertEquals;
3334
import static org.junit.jupiter.api.Assertions.assertFalse;
3435
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -121,31 +122,27 @@ void testCopy() {
121122
}
122123

123124
@Test
124-
void testOrderedTypes() {
125+
void testNotOrderedTypes() {
125126
this.parametersBuilder.addDate("SCHEDULE_DATE", date);
126127
this.parametersBuilder.addLong("LONG", 1L);
127128
this.parametersBuilder.addString("STRING", "string value");
128-
Iterator<String> parameters = this.parametersBuilder.toJobParameters().getParameters().keySet().iterator();
129-
assertEquals("SCHEDULE_DATE", parameters.next());
130-
assertEquals("LONG", parameters.next());
131-
assertEquals("STRING", parameters.next());
129+
Set<String> parameters = this.parametersBuilder.toJobParameters().getParameters().keySet();
130+
assertThat(parameters).containsExactlyInAnyOrder("STRING", "LONG", "SCHEDULE_DATE");
132131
}
133132

134133
@Test
135-
void testOrderedStrings() {
134+
void testNotOrderedStrings() {
136135
this.parametersBuilder.addString("foo", "value foo");
137136
this.parametersBuilder.addString("bar", "value bar");
138137
this.parametersBuilder.addString("spam", "value spam");
139-
Iterator<String> parameters = this.parametersBuilder.toJobParameters().getParameters().keySet().iterator();
140-
assertEquals("foo", parameters.next());
141-
assertEquals("bar", parameters.next());
142-
assertEquals("spam", parameters.next());
138+
Set<String> parameters = this.parametersBuilder.toJobParameters().getParameters().keySet();
139+
assertThat(parameters).containsExactlyInAnyOrder("foo", "bar", "spam");
143140
}
144141

145142
@Test
146143
void testAddJobParameter() {
147144
JobParameter jobParameter = new JobParameter("bar", String.class);
148-
this.parametersBuilder.addParameter("foo", jobParameter);
145+
this.parametersBuilder.addJobParameter("foo", jobParameter);
149146
Map<String, JobParameter<?>> parameters = this.parametersBuilder.toJobParameters().getParameters();
150147
assertEquals(1, parameters.size());
151148
assertEquals("bar", parameters.get("foo").getValue());

0 commit comments

Comments
 (0)