From ab86c33ec3bf3e7180e85043e7b128b9c37c17ee Mon Sep 17 00:00:00 2001 From: David Bauer Date: Wed, 23 Nov 2022 11:06:26 -0500 Subject: [PATCH] Use lombok to generate override implementations --- .../attendance/api/model/AttendanceEvent.java | 33 ++--------- .../attendance/api/model/AttendanceGrade.java | 34 ++---------- .../api/model/AttendanceRecord.java | 34 ++---------- .../attendance/api/model/AttendanceSite.java | 25 ++------- .../api/model/AttendanceStatus.java | 25 ++------- .../attendance/api/model/GradingRule.java | 25 ++------- .../api/model/ImportConfirmList.java | 55 +++++-------------- 7 files changed, 51 insertions(+), 180 deletions(-) diff --git a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceEvent.java b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceEvent.java index d68a1cf..45fedd5 100644 --- a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceEvent.java +++ b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceEvent.java @@ -17,10 +17,10 @@ package org.sakaiproject.attendance.api.model; import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.Hibernate; +import lombok.ToString; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.Type; @@ -30,7 +30,6 @@ import java.io.Serializable; import java.time.Instant; import java.util.HashSet; -import java.util.Objects; import java.util.Set; /** @@ -43,8 +42,9 @@ @Entity @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Table(name = "ATTENDANCE_EVENT_T") -@Getter -@Setter +@Data +@ToString(exclude = {"attendanceSite", "records"}) +@EqualsAndHashCode(of = "id") @NoArgsConstructor @AllArgsConstructor public class AttendanceEvent implements Serializable, PersistableEntity { @@ -76,25 +76,4 @@ public AttendanceEvent(AttendanceEvent attendanceEvent) { this.startDateTime = attendanceEvent.startDateTime; this.attendanceSite = attendanceEvent.attendanceSite; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; - AttendanceEvent that = (AttendanceEvent) o; - return id != null && Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return getClass().hashCode(); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(" + - "id = " + id + ", " + - "name = " + name + ", " + - "startDateTime = " + startDateTime + ")"; - } } diff --git a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceGrade.java b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceGrade.java index 2023a8b..688bb42 100644 --- a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceGrade.java +++ b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceGrade.java @@ -17,17 +17,16 @@ package org.sakaiproject.attendance.api.model; import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.Hibernate; +import lombok.ToString; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.sakaiproject.springframework.data.PersistableEntity; import javax.persistence.*; import java.io.Serializable; -import java.util.Objects; /** * The AttendanceGrade earned for the all AttendanceItems @@ -39,8 +38,9 @@ @Entity @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Table(name = "ATTENDANCE_GRADE_T") -@Getter -@Setter +@Data +@ToString(exclude = {"attendanceSite"}) +@EqualsAndHashCode(of = "id") @NoArgsConstructor @AllArgsConstructor public class AttendanceGrade implements Serializable, PersistableEntity { @@ -69,26 +69,4 @@ public AttendanceGrade(AttendanceSite aS, String userId) { this.attendanceSite = aS; this.userID = userId; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; - AttendanceGrade that = (AttendanceGrade) o; - return id != null && Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return getClass().hashCode(); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(" + - "id = " + id + ", " + - "grade = " + grade + ", " + - "userID = " + userID + ", " + - "override = " + override + ")"; - } } diff --git a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceRecord.java b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceRecord.java index 2ad96b7..33e6a0d 100644 --- a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceRecord.java +++ b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceRecord.java @@ -17,17 +17,16 @@ package org.sakaiproject.attendance.api.model; import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.Hibernate; +import lombok.ToString; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.sakaiproject.springframework.data.PersistableEntity; import javax.persistence.*; import java.io.Serializable; -import java.util.Objects; /** * An AttendanceRecord for a specific user for a specific AttendanceEvent @@ -43,8 +42,9 @@ @Index(name = "ATTEN_EVENT_STATUS_I", columnList = "A_EVENT_ID, STATUS"), @Index(name = "ATTEN_EVENT_USER_STATUS_I", columnList = "A_EVENT_ID, USER_ID, STATUS") }) -@Getter -@Setter +@Data +@ToString(exclude = {"attendanceEvent"}) +@EqualsAndHashCode(of = "id") @NoArgsConstructor @AllArgsConstructor public class AttendanceRecord implements Serializable, PersistableEntity { @@ -76,26 +76,4 @@ public AttendanceRecord(AttendanceEvent e, String uId, Status s) { this.userID = uId; this.status = s; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; - AttendanceRecord that = (AttendanceRecord) o; - return id != null && Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return getClass().hashCode(); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(" + - "id = " + id + ", " + - "userID = " + userID + ", " + - "status = " + status + ", " + - "comment = " + comment + ")"; - } } diff --git a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceSite.java b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceSite.java index 81a368d..167a51d 100644 --- a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceSite.java +++ b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceSite.java @@ -17,10 +17,10 @@ package org.sakaiproject.attendance.api.model; import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.Hibernate; +import lombok.ToString; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.sakaiproject.attendance.api.util.AttendanceConstants; @@ -29,7 +29,6 @@ import javax.persistence.*; import java.io.Serializable; import java.util.HashSet; -import java.util.Objects; import java.util.Set; /** @@ -43,8 +42,9 @@ @Entity @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Table(name = "ATTENDANCE_SITE_T") -@Getter -@Setter +@Data +@ToString +@EqualsAndHashCode(of = "id") @NoArgsConstructor @AllArgsConstructor public class AttendanceSite implements Serializable, PersistableEntity { @@ -91,17 +91,4 @@ public AttendanceSite(String siteID) { this.siteID = siteID; this.gradebookItemName = AttendanceConstants.GRADEBOOK_ITEM_NAME; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; - AttendanceSite that = (AttendanceSite) o; - return id != null && Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return getClass().hashCode(); - } } diff --git a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceStatus.java b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceStatus.java index d6c4c33..145d7e5 100644 --- a/api/src/java/org/sakaiproject/attendance/api/model/AttendanceStatus.java +++ b/api/src/java/org/sakaiproject/attendance/api/model/AttendanceStatus.java @@ -17,17 +17,16 @@ package org.sakaiproject.attendance.api.model; import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.Hibernate; +import lombok.ToString; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.sakaiproject.springframework.data.PersistableEntity; import javax.persistence.*; import java.io.Serializable; -import java.util.Objects; /** * An AttendanceStatus is a wrapper around the Status enum type defining meta information on individual Statuses. @@ -38,8 +37,9 @@ @Entity @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Table(name = "ATTENDANCE_STATUS_T") -@Getter -@Setter +@Data +@ToString(exclude = {"attendanceSite"}) +@EqualsAndHashCode(of = "id") @NoArgsConstructor @AllArgsConstructor public class AttendanceStatus implements Serializable, PersistableEntity { @@ -72,17 +72,4 @@ public AttendanceStatus(AttendanceStatus attendanceStatus) { this.sortOrder = attendanceStatus.getSortOrder(); this.attendanceSite = attendanceStatus.getAttendanceSite(); } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; - AttendanceStatus that = (AttendanceStatus) o; - return id != null && Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return getClass().hashCode(); - } } diff --git a/api/src/java/org/sakaiproject/attendance/api/model/GradingRule.java b/api/src/java/org/sakaiproject/attendance/api/model/GradingRule.java index 4de7143..0aeb18a 100644 --- a/api/src/java/org/sakaiproject/attendance/api/model/GradingRule.java +++ b/api/src/java/org/sakaiproject/attendance/api/model/GradingRule.java @@ -16,17 +16,16 @@ package org.sakaiproject.attendance.api.model; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.Hibernate; +import lombok.ToString; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.sakaiproject.springframework.data.PersistableEntity; import javax.persistence.*; import java.io.Serializable; -import java.util.Objects; /** * @author David P. Bauer [dbauer1 (at) udayton (dot) edu] @@ -34,8 +33,9 @@ @Entity @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Table(name = "ATTENDANCE_RULE_T") -@Getter -@Setter +@Data +@ToString(exclude = {"attendanceSite", "records"}) +@EqualsAndHashCode(of = "id") @NoArgsConstructor public class GradingRule implements Serializable, PersistableEntity { private static final long serialVersionUID = 1L; @@ -66,17 +66,4 @@ public class GradingRule implements Serializable, PersistableEntity { public GradingRule(AttendanceSite attendanceSite) { this.attendanceSite = attendanceSite; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; - GradingRule that = (GradingRule) o; - return id != null && Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return getClass().hashCode(); - } } diff --git a/api/src/java/org/sakaiproject/attendance/api/model/ImportConfirmList.java b/api/src/java/org/sakaiproject/attendance/api/model/ImportConfirmList.java index f0d005a..7bdd4d8 100644 --- a/api/src/java/org/sakaiproject/attendance/api/model/ImportConfirmList.java +++ b/api/src/java/org/sakaiproject/attendance/api/model/ImportConfirmList.java @@ -17,58 +17,33 @@ package org.sakaiproject.attendance.api.model; import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; import java.io.Serializable; -import java.util.Objects; /** * Holds the records that are being changed by the Import function. * * Created by james on 6/9/17. */ +@Data +@EqualsAndHashCode(of = {"id","attendanceEvent","userID","status","comment","oldComment","oldStatus"}) @NoArgsConstructor @AllArgsConstructor public class ImportConfirmList implements Serializable { private static final long serialVersionUID = 1L; - @Getter @Setter private Long id; - @Getter @Setter private AttendanceEvent attendanceEvent; - @Getter @Setter private AttendanceRecord attendanceRecord; - @Getter @Setter private AttendanceSite attendanceSite; - @Getter @Setter private String userID; - @Getter @Setter private Status status; - @Getter @Setter private Status oldStatus; - @Getter @Setter private String comment; - @Getter @Setter private String oldComment; - @Getter @Setter private String eventName; - @Getter @Setter private String eventDate; - - - public ImportConfirmList(AttendanceEvent e, String uId, Status newStatus) { - this.attendanceEvent = e; - this.userID = uId; - this.status = newStatus; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final ImportConfirmList that = (ImportConfirmList) o; - return Objects.equals(id, that.id) && - Objects.equals(attendanceEvent, that.attendanceEvent) && - Objects.equals(userID, that.userID) && - status == that.status && - Objects.equals(comment, that.comment) && - Objects.equals(oldComment, that.oldComment) && - Objects.equals(oldStatus, that.oldStatus); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } + private Long id; + private AttendanceEvent attendanceEvent; + private AttendanceRecord attendanceRecord; + private AttendanceSite attendanceSite; + private String userID; + private Status status; + private Status oldStatus; + private String comment; + private String oldComment; + private String eventName; + private String eventDate; }