Added equals implementations on model classes.

This commit is contained in:
Jonathan Bernard 2015-03-07 14:16:52 -06:00
parent f55cabe242
commit 66cd8f579a
5 changed files with 67 additions and 1 deletions

View File

@ -18,6 +18,7 @@ dependencies {
compile 'com.zaxxer:HikariCP-java6:2.3.2'
compile 'javax:javaee-api:7.0'
compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
compile 'joda-time:joda-time:2.7'
compile 'org.codehaus.groovy:groovy-all:2.3.6'
compile 'org.slf4j:slf4j-api:1.7.10'
runtime 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.2'

View File

@ -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" }
}

View File

@ -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" }
}

View File

@ -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)" }
}

View File

@ -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