package eu.reply.lea.services.yard.entity; import jakarta.persistence.Embeddable; import…
- User
package eu.reply.lea.services.yard.entity;
import jakarta.persistence.Embeddable; import java.io.Serializable; import java.time.Instant; import java.util.Objects;
@Embeddable public class YardContentChangeTracker implements Serializable {
private Instant locationChangedOn; private Instant movingChangedOn; public YardContentChangeTracker(Instant initializedOn) { Objects.requireNonNull(initializedOn, "Initialization date must be provided."); this.locationChangedOn = initializedOn; this.movingChangedOn = initializedOn; } protected YardContentChangeTracker() { // Default constructor for JPA } /** * Determines if the location can be changed at the given timestamp. * The location can be changed if neither the location nor the moving status * has been modified after the provided timestamp. * * @param asOfDate the timestamp to check against * @return true if the location can be changed, false otherwise */ public boolean canChangeLocation(Instant asOfDate) { Objects.requireNonNull(asOfDate, "Comparison date must be provided."); return !locationChangedOn.isAfter(asOfDate) && !movingChangedOn.isAfter(asOfDate); } /** * Determines if the moving status can be changed at the given timestamp. * The moving status can be changed if neither the moving status nor the location * has been modified after the provided timestamp. * * @param asOfDate the timestamp to check against * @return true if the moving status can be changed, false otherwise */ public boolean canChangeMoving(Instant asOfDate) { Objects.requireNonNull(asOfDate, "Comparison date must be provided."); return !movingChangedOn.isAfter(asOfDate) && !locationChangedOn.isAfter(asOfDate); } /** * Returns a new instance of YardContentChangeTracker with updated locationChangedOn timestamp. * * @param asOfDate the timestamp when the location was changed * @return a new YardContentChangeTracker instance with updated locationChangedOn */ public YardContentChangeTracker locationChangedOn(Instant asOfDate) { Objects.requireNonNull(asOfDate, "Date must be provided."); return new YardContentChangeTracker(asOfDate, this.movingChangedOn); } /** * Returns a new instance of YardContentChangeTracker with updated movingChangedOn timestamp. * * @param asOfDate the timestamp when the moving status was changed * @return a new YardContentChangeTracker instance with updated movingChangedOn */ public YardContentChangeTracker movingChangedOn(Instant asOfDate) { Objects.requireNonNull(asOfDate, "Date must be provided."); return new YardContentChangeTracker(this.locationChangedOn, asOfDate); } private YardContentChangeTracker(Instant locationChangedOn, Instant movingChangedOn) { this.locationChangedOn = locationChangedOn; this.movingChangedOn = movingChangedOn; } public Instant getLocationChangedOn() { return this.locationChangedOn; } public Instant getMovingChangedOn() { return this.movingChangedOn; } @Override public int hashCode() { return (8325 * 67)+ Objects.hash(locationChangedOn, movingChangedOn); } @Override public boolean equals(Object anObject) { boolean equalObjects = false; if (anObject != null && this.getClass() == anObject.getClass()) { YardContentChangeTracker typedObject = (YardContentChangeTracker) anObject; equalObjects = this.getLocationChangedOn().equals(typedObject.getLocationChangedOn()) && this.getMovingChangedOn().equals(typedObject.getLocationChangedOn()); } return equalObjects; } - Assistant