forked from spring-projects/spring-batch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JobParameter.java
195 lines (169 loc) · 4.71 KB
/
JobParameter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Copyright 2006-2022 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core;
import java.io.Serializable;
import java.util.Date;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
/**
* Domain representation of a parameter to a batch job. Only the following types
* can be parameters: String, Long, Date, and Double. The identifying flag is
* used to indicate if the parameter is to be used as part of the identification of
* a job instance.
*
* @author Lucas Ward
* @author Dave Syer
* @author Michael Minella
* @author Mahmoud Ben Hassine
* @since 2.0
*
*/
public class JobParameter implements Serializable {
private final Object parameter;
private final ParameterType parameterType;
private final boolean identifying;
/**
* Construct a new JobParameter as a String.
* @param parameter {@link String} instance. Must not be {@code null}.
* @param identifying true if JobParameter should be identifying.
*/
public JobParameter(@NonNull String parameter, boolean identifying) {
this(parameter, identifying, ParameterType.STRING);
}
/**
* Construct a new JobParameter as a Long.
*
* @param parameter {@link Long} instance. Must not be {@code null}.
* @param identifying true if JobParameter should be identifying.
*/
public JobParameter(@NonNull Long parameter, boolean identifying) {
this(parameter, identifying, ParameterType.LONG);
}
/**
* Construct a new JobParameter as a Date.
*
* @param parameter {@link Date} instance. Must not be {@code null}.
* @param identifying true if JobParameter should be identifying.
*/
public JobParameter(@NonNull Date parameter, boolean identifying) {
this(parameter, identifying, ParameterType.DATE);
}
/**
* Construct a new JobParameter as a Double.
*
* @param parameter {@link Double} instance. Must not be {@code null}.
* @param identifying true if JobParameter should be identifying.
*/
public JobParameter(@NonNull Double parameter, boolean identifying) {
this(parameter, identifying, ParameterType.DOUBLE);
}
private JobParameter(Object parameter, boolean identifying, ParameterType parameterType) {
Assert.notNull(parameter, "parameter must not be null");
this.parameter = parameter;
this.parameterType = parameterType;
this.identifying = identifying;
}
/**
* Construct a new JobParameter as a String.
*
* @param parameter {@link String} instance.
*/
public JobParameter(String parameter) {
this(parameter, true);
}
/**
* Construct a new JobParameter as a Long.
*
* @param parameter {@link Long} instance.
*/
public JobParameter(Long parameter) {
this(parameter, true);
}
/**
* Construct a new JobParameter as a Date.
*
* @param parameter {@link Date} instance.
*/
public JobParameter(Date parameter) {
this(parameter, true);
}
/**
* Construct a new JobParameter as a Double.
*
* @param parameter {@link Double} instance.
*/
public JobParameter(Double parameter) {
this(parameter, true);
}
/**
* @return The identifying flag. It is set to true if the job parameter is identifying.
*/
public boolean isIdentifying() {
return identifying;
}
/**
* @return the value contained within this JobParameter.
*/
public Object getValue() {
return parameter;
}
/**
* @return a ParameterType representing the type of this parameter.
*/
public ParameterType getType() {
return parameterType;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof JobParameter)) {
return false;
}
if (this == obj) {
return true;
}
JobParameter rhs = (JobParameter) obj;
return parameterType == rhs.parameterType && parameter.equals(rhs.parameter);
}
@Override
public String toString() {
return parameterType == ParameterType.DATE ? "" + ((Date) parameter).getTime() : parameter.toString();
}
@Override
public int hashCode() {
return 7 + 21 * parameter.hashCode();
}
/**
* Enumeration representing the type of {@link JobParameter}.
*/
public enum ParameterType {
/**
* String parameter type.
*/
STRING,
/**
* Date parameter type.
*/
DATE,
/**
* Long parameter type.
*/
LONG,
/**
* Double parameter type.
*/
DOUBLE;
}
}