Added equals implementations on model classes.
This commit is contained in:
		@@ -10,4 +10,22 @@ public class Performance implements Serializable {
 | 
			
		||||
    String drummer
 | 
			
		||||
    String guitarist
 | 
			
		||||
    String leader
 | 
			
		||||
 | 
			
		||||
    @Override public boolean equals(Object thatObj) {
 | 
			
		||||
        if (thatObj == null) return false
 | 
			
		||||
        if (!(thatObj instanceof Performance)) return false
 | 
			
		||||
 | 
			
		||||
        Performance that = (Performance) thatObj
 | 
			
		||||
 | 
			
		||||
        return (this.serviceId == that.serviceId &&
 | 
			
		||||
                this.songId == that.songId &&
 | 
			
		||||
                this.pianist == that.pianist &&
 | 
			
		||||
                this.organist == that.organist &&
 | 
			
		||||
                this.bassist == that.bassist &&
 | 
			
		||||
                this.drummer == that.drummer &&
 | 
			
		||||
                this.guitarist == that.guitarist &&
 | 
			
		||||
                this.leader == that.leader) }
 | 
			
		||||
 | 
			
		||||
    @Override String toString() {
 | 
			
		||||
        return "($serviceId, $songId): $leader - $pianist" }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,28 @@
 | 
			
		||||
package com.jdbernard.nlsongs.model
 | 
			
		||||
 | 
			
		||||
import org.joda.time.LocalDate
 | 
			
		||||
 | 
			
		||||
public class Service implements Serializable {
 | 
			
		||||
 | 
			
		||||
    int id
 | 
			
		||||
    Date date
 | 
			
		||||
    private LocalDate date
 | 
			
		||||
    ServiceType serviceType
 | 
			
		||||
 | 
			
		||||
    public boolean equals(Object thatObj) {
 | 
			
		||||
        if (thatObj == null) return false
 | 
			
		||||
        if (!(thatObj instanceof Service)) return false
 | 
			
		||||
 | 
			
		||||
        Service that = (Service) thatObj
 | 
			
		||||
 | 
			
		||||
        return (this.id == that.id &&
 | 
			
		||||
                this.date == (that.@date) &&
 | 
			
		||||
                this.serviceType == that.serviceType) }
 | 
			
		||||
 | 
			
		||||
    public void setDate(Date date) { this.date = LocalDate.fromDateFields(date) }
 | 
			
		||||
 | 
			
		||||
    public void setDate(LocalDate date) { this.date = date }
 | 
			
		||||
 | 
			
		||||
    public Date getDate() { return this.date.toDate() }
 | 
			
		||||
 | 
			
		||||
    public String toString() { return "$id: $date - $serviceType" }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,4 +5,15 @@ public class Song implements Serializable {
 | 
			
		||||
    int id
 | 
			
		||||
    String name
 | 
			
		||||
    List<String> artists
 | 
			
		||||
 | 
			
		||||
    @Override public boolean equals(Object thatObj) {
 | 
			
		||||
        if (thatObj == null) return false
 | 
			
		||||
        if (!(thatObj instanceof Song)) return false
 | 
			
		||||
 | 
			
		||||
        Song that = (Song) thatObj
 | 
			
		||||
        return (this.id == that.id &&
 | 
			
		||||
                this.name == that.name &&
 | 
			
		||||
                this.artists == that.artists) }
 | 
			
		||||
 | 
			
		||||
    @Override public String toString() { return "$id: $name ($artists)" }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,26 @@ package com.jdbernard.nlsongs.model
 | 
			
		||||
 | 
			
		||||
public class Token implements Serializable {
 | 
			
		||||
 | 
			
		||||
    public static final long EXPIRY_WINDOW = 1000 * 60 * 60 * 24;
 | 
			
		||||
 | 
			
		||||
    String token
 | 
			
		||||
    User user
 | 
			
		||||
    Date expires
 | 
			
		||||
 | 
			
		||||
    public Token(Map namedArgs) {
 | 
			
		||||
        if (!namedArgs.user) throw new IllegalArgumentException(
 | 
			
		||||
            "Cannot create Token object: missing user property.")
 | 
			
		||||
 | 
			
		||||
        if (namedArgs.expire) this.expires = namedArgs.expires
 | 
			
		||||
        else this.expires = new Date((new Date()).time + EXPIRY_WINDOW)
 | 
			
		||||
 | 
			
		||||
        if (namedArgs.token) this.token = namedArgs.token
 | 
			
		||||
        else this.token = UUID.randomUUID().toString() }
 | 
			
		||||
 | 
			
		||||
    public Token(User user) { this([user: user]) }
 | 
			
		||||
 | 
			
		||||
    public void refresh() { this.expires = new Date((new Date()).time + EXPIRY_WINDOW) }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean equals(Object thatObj) {
 | 
			
		||||
        if (thatObj == null) return false
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user