From 9ad66fd06a7eb54f440966dc4d935179c2cc150a Mon Sep 17 00:00:00 2001 From: j-james Date: Fri, 2 Dec 2022 20:54:57 -0800 Subject: Begin Phase 4 --- src/main/model/util/Event.java | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/model/util/Event.java (limited to 'src/main/model/util/Event.java') diff --git a/src/main/model/util/Event.java b/src/main/model/util/Event.java new file mode 100644 index 0000000..8a42ef8 --- /dev/null +++ b/src/main/model/util/Event.java @@ -0,0 +1,66 @@ +package model.util; + +import java.util.Calendar; +import java.util.Date; + + +/** + * Represents an alarm system event. + */ +public class Event { + private static final int HASH_CONSTANT = 13; + private Date dateLogged; + private String description; + + /** + * Creates an event with the given description + * and the current date/time stamp. + * @param description a description of the event + */ + public Event(String description) { + dateLogged = Calendar.getInstance().getTime(); + this.description = description; + } + + /** + * Gets the date of this event (includes time). + * @return the date of the event + */ + public Date getDate() { + return dateLogged; + } + + /** + * Gets the description of this event. + * @return the description of the event + */ + public String getDescription() { + return description; + } + + @Override + public boolean equals(Object other) { + if (other == null) { + return false; + } + + if (other.getClass() != this.getClass()) { + return false; + } + + Event otherEvent = (Event) other; + + return (this.dateLogged.equals(otherEvent.dateLogged) + && this.description.equals(otherEvent.description)); + } + + @Override + public int hashCode() { + return (HASH_CONSTANT * dateLogged.hashCode() + description.hashCode()); + } + + @Override + public String toString() { + return dateLogged.toString() + "\n" + description; + } +} -- cgit v1.2.3-70-g09d2