Added equals implementations on model classes.
This commit is contained in:
parent
f55cabe242
commit
66cd8f579a
@ -18,6 +18,7 @@ dependencies {
|
|||||||
compile 'com.zaxxer:HikariCP-java6:2.3.2'
|
compile 'com.zaxxer:HikariCP-java6:2.3.2'
|
||||||
compile 'javax:javaee-api:7.0'
|
compile 'javax:javaee-api:7.0'
|
||||||
compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
|
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.codehaus.groovy:groovy-all:2.3.6'
|
||||||
compile 'org.slf4j:slf4j-api:1.7.10'
|
compile 'org.slf4j:slf4j-api:1.7.10'
|
||||||
runtime 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.2'
|
runtime 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.2'
|
||||||
|
@ -10,4 +10,22 @@ public class Performance implements Serializable {
|
|||||||
String drummer
|
String drummer
|
||||||
String guitarist
|
String guitarist
|
||||||
String leader
|
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
|
package com.jdbernard.nlsongs.model
|
||||||
|
|
||||||
|
import org.joda.time.LocalDate
|
||||||
|
|
||||||
public class Service implements Serializable {
|
public class Service implements Serializable {
|
||||||
|
|
||||||
int id
|
int id
|
||||||
Date date
|
private LocalDate date
|
||||||
ServiceType serviceType
|
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
|
int id
|
||||||
String name
|
String name
|
||||||
List<String> artists
|
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 class Token implements Serializable {
|
||||||
|
|
||||||
|
public static final long EXPIRY_WINDOW = 1000 * 60 * 60 * 24;
|
||||||
|
|
||||||
String token
|
String token
|
||||||
User user
|
User user
|
||||||
Date expires
|
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
|
@Override
|
||||||
public boolean equals(Object thatObj) {
|
public boolean equals(Object thatObj) {
|
||||||
if (thatObj == null) return false
|
if (thatObj == null) return false
|
||||||
|
Loading…
Reference in New Issue
Block a user