JobOutput.java

// Generated by delombok at Mon Apr 14 16:48:01 UTC 2025
package de.larssh.jes;

import java.util.Optional;
import de.larssh.utils.annotations.SuppressJacocoGenerated;
import de.larssh.utils.text.Strings;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
 * Value object containing a job outputs details.
 */
@SuppressWarnings("PMD.DataClass")
public class JobOutput {
	/**
	 * Corresponding {@link Job}
	 */
	private final Job job;
	/**
	 * The job outputs index inside the jobs list of outputs (starting at 1)
	 */
	private final int index;
	/**
	 * The job outputs data division name
	 */
	private final String name;
	/**
	 * The job outputs content length
	 */
	private final int length;
	/**
	 * The job outputs step name
	 */
	private final Optional<String> step;
	/**
	 * The job outputs procedure step name
	 */
	private final Optional<String> procedureStep;
	/**
	 * The job outputs class
	 */
	private final Optional<String> outputClass;

	/**
	 * This constructor creates a {@link JobOutput}. String parameters are trimmed
	 * and converted to upper case.
	 *
	 * @param job           the corresponding job
	 * @param index         the job outputs index inside the jobs list of outputs
	 *                      (starting at 1)
	 * @param name          the job outputs data division name
	 * @param length        the job outputs content length
	 * @param step          the job outputs step name
	 * @param procedureStep the job outputs procedure step name
	 * @param outputClass   the output class
	 * @throws JobFieldInconsistentException on inconsistent field value
	 */
	@SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Fields are initialized prior throwing exceptions")
	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) {
		this.job = job;
		this.index = index;
		this.name = Strings.toUpperCaseNeutral(name.trim());
		this.length = length;
		this.step = step.map(String::trim).map(Strings::toUpperCaseNeutral);
		this.procedureStep = procedureStep.map(String::trim).map(Strings::toUpperCaseNeutral);
		this.outputClass = outputClass.map(String::trim).map(Strings::toUpperCaseNeutral);
		validate();
	}

	/**
	 * Corresponding {@link Job}s ID for {@link lombok.ToString.Include}
	 *
	 * @return the jobs ID
	 */
	@SuppressJacocoGenerated(justification = "private method, used for toString only")
	private String getJobId() {
		return getJob().getId();
	}

	/**
	 * Validates fields to be set in a consistent way.
	 *
	 * @throws JobFieldInconsistentException on inconsistent field value
	 */
	@SuppressWarnings("PMD.CyclomaticComplexity")
	private void validate() {
		if (index < 1) {
			throw new JobFieldInconsistentException("Index must not be less than one.");
		}
		if (name.isEmpty()) {
			throw new JobFieldInconsistentException("Name must not be empty.");
		}
		if (length < 0) {
			throw new JobFieldInconsistentException("Length must not be less than zero.");
		}
		if (step.filter(String::isEmpty).isPresent()) {
			throw new JobFieldInconsistentException("Step must not be empty if present.");
		}
		if (procedureStep.filter(String::isEmpty).isPresent()) {
			throw new JobFieldInconsistentException("Procedure Step must not be empty if present.");
		}
		if (outputClass.filter(String::isEmpty).isPresent()) {
			throw new JobFieldInconsistentException("Output class must not be empty if present.");
		}
	}

	/**
	 * Corresponding {@link Job}
	 *
	 * @return job
	 */
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public Job getJob() {
		return this.job;
	}

	/**
	 * The job outputs index inside the jobs list of outputs (starting at 1)
	 *
	 * @return job output index
	 */
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public int getIndex() {
		return this.index;
	}

	/**
	 * The job outputs data division name
	 *
	 * @return job output name
	 */
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public String getName() {
		return this.name;
	}

	/**
	 * The job outputs content length
	 *
	 * @return job output length
	 */
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public int getLength() {
		return this.length;
	}

	/**
	 * The job outputs step name
	 *
	 * @return step
	 */
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public Optional<String> getStep() {
		return this.step;
	}

	/**
	 * The job outputs procedure step name
	 *
	 * @return procedure step
	 */
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public Optional<String> getProcedureStep() {
		return this.procedureStep;
	}

	/**
	 * The job outputs class
	 *
	 * @return output class
	 */
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public Optional<String> getOutputClass() {
		return this.outputClass;
	}

	@edu.umd.cs.findbugs.annotations.NonNull
	@java.lang.Override
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public java.lang.String toString() {
		return "JobOutput(job.id=" + this.getJobId() + ", index=" + this.getIndex() + ", name=" + this.getName() + ", length=" + this.getLength() + ", step=" + this.getStep() + ", procedureStep=" + this.getProcedureStep() + ", outputClass=" + this.getOutputClass() + ")";
	}

	@java.lang.Override
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public boolean equals(@edu.umd.cs.findbugs.annotations.Nullable final java.lang.Object o) {
		if (o == this) return true;
		if (!(o instanceof JobOutput)) return false;
		final JobOutput other = (JobOutput) o;
		if (!other.canEqual((java.lang.Object) this)) return false;
		if (this.getIndex() != other.getIndex()) return false;
		final java.lang.Object this$job = this.getJob();
		final java.lang.Object other$job = other.getJob();
		if (this$job == null ? other$job != null : !this$job.equals(other$job)) return false;
		return true;
	}

	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	protected boolean canEqual(@edu.umd.cs.findbugs.annotations.Nullable final java.lang.Object other) {
		return other instanceof JobOutput;
	}

	@java.lang.Override
	@java.lang.SuppressWarnings("all")
	@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
	@lombok.Generated
	public int hashCode() {
		final int PRIME = 59;
		int result = 1;
		result = result * PRIME + this.getIndex();
		final java.lang.Object $job = this.getJob();
		result = result * PRIME + ($job == null ? 43 : $job.hashCode());
		return result;
	}
}