View Javadoc
1   // Generated by delombok at Mon Apr 14 16:48:01 UTC 2025
2   package de.larssh.jes;
3   
4   import java.util.Optional;
5   import de.larssh.utils.annotations.SuppressJacocoGenerated;
6   import de.larssh.utils.text.Strings;
7   import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
8   
9   /**
10   * Value object containing a job outputs details.
11   */
12  @SuppressWarnings("PMD.DataClass")
13  public class JobOutput {
14  	/**
15  	 * Corresponding {@link Job}
16  	 */
17  	private final Job job;
18  	/**
19  	 * The job outputs index inside the jobs list of outputs (starting at 1)
20  	 */
21  	private final int index;
22  	/**
23  	 * The job outputs data division name
24  	 */
25  	private final String name;
26  	/**
27  	 * The job outputs content length
28  	 */
29  	private final int length;
30  	/**
31  	 * The job outputs step name
32  	 */
33  	private final Optional<String> step;
34  	/**
35  	 * The job outputs procedure step name
36  	 */
37  	private final Optional<String> procedureStep;
38  	/**
39  	 * The job outputs class
40  	 */
41  	private final Optional<String> outputClass;
42  
43  	/**
44  	 * This constructor creates a {@link JobOutput}. String parameters are trimmed
45  	 * and converted to upper case.
46  	 *
47  	 * @param job           the corresponding job
48  	 * @param index         the job outputs index inside the jobs list of outputs
49  	 *                      (starting at 1)
50  	 * @param name          the job outputs data division name
51  	 * @param length        the job outputs content length
52  	 * @param step          the job outputs step name
53  	 * @param procedureStep the job outputs procedure step name
54  	 * @param outputClass   the output class
55  	 * @throws JobFieldInconsistentException on inconsistent field value
56  	 */
57  	@SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Fields are initialized prior throwing exceptions")
58  	protected JobOutput(final Job job, final int index, final String name, final int length, final Optional<String> step, final Optional<String> procedureStep, final Optional<String> outputClass) {
59  		this.job = job;
60  		this.index = index;
61  		this.name = Strings.toUpperCaseNeutral(name.trim());
62  		this.length = length;
63  		this.step = step.map(String::trim).map(Strings::toUpperCaseNeutral);
64  		this.procedureStep = procedureStep.map(String::trim).map(Strings::toUpperCaseNeutral);
65  		this.outputClass = outputClass.map(String::trim).map(Strings::toUpperCaseNeutral);
66  		validate();
67  	}
68  
69  	/**
70  	 * Corresponding {@link Job}s ID for {@link lombok.ToString.Include}
71  	 *
72  	 * @return the jobs ID
73  	 */
74  	@SuppressJacocoGenerated(justification = "private method, used for toString only")
75  	private String getJobId() {
76  		return getJob().getId();
77  	}
78  
79  	/**
80  	 * Validates fields to be set in a consistent way.
81  	 *
82  	 * @throws JobFieldInconsistentException on inconsistent field value
83  	 */
84  	@SuppressWarnings("PMD.CyclomaticComplexity")
85  	private void validate() {
86  		if (index < 1) {
87  			throw new JobFieldInconsistentException("Index must not be less than one.");
88  		}
89  		if (name.isEmpty()) {
90  			throw new JobFieldInconsistentException("Name must not be empty.");
91  		}
92  		if (length < 0) {
93  			throw new JobFieldInconsistentException("Length must not be less than zero.");
94  		}
95  		if (step.filter(String::isEmpty).isPresent()) {
96  			throw new JobFieldInconsistentException("Step must not be empty if present.");
97  		}
98  		if (procedureStep.filter(String::isEmpty).isPresent()) {
99  			throw new JobFieldInconsistentException("Procedure Step must not be empty if present.");
100 		}
101 		if (outputClass.filter(String::isEmpty).isPresent()) {
102 			throw new JobFieldInconsistentException("Output class must not be empty if present.");
103 		}
104 	}
105 
106 	/**
107 	 * Corresponding {@link Job}
108 	 *
109 	 * @return job
110 	 */
111 	@java.lang.SuppressWarnings("all")
112 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
113 	@lombok.Generated
114 	public Job getJob() {
115 		return this.job;
116 	}
117 
118 	/**
119 	 * The job outputs index inside the jobs list of outputs (starting at 1)
120 	 *
121 	 * @return job output index
122 	 */
123 	@java.lang.SuppressWarnings("all")
124 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
125 	@lombok.Generated
126 	public int getIndex() {
127 		return this.index;
128 	}
129 
130 	/**
131 	 * The job outputs data division name
132 	 *
133 	 * @return job output name
134 	 */
135 	@java.lang.SuppressWarnings("all")
136 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
137 	@lombok.Generated
138 	public String getName() {
139 		return this.name;
140 	}
141 
142 	/**
143 	 * The job outputs content length
144 	 *
145 	 * @return job output length
146 	 */
147 	@java.lang.SuppressWarnings("all")
148 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
149 	@lombok.Generated
150 	public int getLength() {
151 		return this.length;
152 	}
153 
154 	/**
155 	 * The job outputs step name
156 	 *
157 	 * @return step
158 	 */
159 	@java.lang.SuppressWarnings("all")
160 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
161 	@lombok.Generated
162 	public Optional<String> getStep() {
163 		return this.step;
164 	}
165 
166 	/**
167 	 * The job outputs procedure step name
168 	 *
169 	 * @return procedure step
170 	 */
171 	@java.lang.SuppressWarnings("all")
172 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
173 	@lombok.Generated
174 	public Optional<String> getProcedureStep() {
175 		return this.procedureStep;
176 	}
177 
178 	/**
179 	 * The job outputs class
180 	 *
181 	 * @return output class
182 	 */
183 	@java.lang.SuppressWarnings("all")
184 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
185 	@lombok.Generated
186 	public Optional<String> getOutputClass() {
187 		return this.outputClass;
188 	}
189 
190 	@edu.umd.cs.findbugs.annotations.NonNull
191 	@java.lang.Override
192 	@java.lang.SuppressWarnings("all")
193 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
194 	@lombok.Generated
195 	public java.lang.String toString() {
196 		return "JobOutput(job.id=" + this.getJobId() + ", index=" + this.getIndex() + ", name=" + this.getName() + ", length=" + this.getLength() + ", step=" + this.getStep() + ", procedureStep=" + this.getProcedureStep() + ", outputClass=" + this.getOutputClass() + ")";
197 	}
198 
199 	@java.lang.Override
200 	@java.lang.SuppressWarnings("all")
201 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
202 	@lombok.Generated
203 	public boolean equals(@edu.umd.cs.findbugs.annotations.Nullable final java.lang.Object o) {
204 		if (o == this) return true;
205 		if (!(o instanceof JobOutput)) return false;
206 		final JobOutput other = (JobOutput) o;
207 		if (!other.canEqual((java.lang.Object) this)) return false;
208 		if (this.getIndex() != other.getIndex()) return false;
209 		final java.lang.Object this$job = this.getJob();
210 		final java.lang.Object other$job = other.getJob();
211 		if (this$job == null ? other$job != null : !this$job.equals(other$job)) return false;
212 		return true;
213 	}
214 
215 	@java.lang.SuppressWarnings("all")
216 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
217 	@lombok.Generated
218 	protected boolean canEqual(@edu.umd.cs.findbugs.annotations.Nullable final java.lang.Object other) {
219 		return other instanceof JobOutput;
220 	}
221 
222 	@java.lang.Override
223 	@java.lang.SuppressWarnings("all")
224 	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
225 	@lombok.Generated
226 	public int hashCode() {
227 		final int PRIME = 59;
228 		int result = 1;
229 		result = result * PRIME + this.getIndex();
230 		final java.lang.Object $job = this.getJob();
231 		result = result * PRIME + ($job == null ? 43 : $job.hashCode());
232 		return result;
233 	}
234 }