From b4ce76063b905b0215ba64891b89bb5b7cf6fa0e Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Fri, 12 Feb 2016 17:18:37 -0600 Subject: [PATCH] Added a base Model class which implements equals. --- .../com/jdbernard/wdiwtlt/db/models/Album.java | 6 +----- .../com/jdbernard/wdiwtlt/db/models/Artist.java | 6 +----- .../com/jdbernard/wdiwtlt/db/models/Bookmark.java | 6 +----- .../com/jdbernard/wdiwtlt/db/models/Image.java | 6 +----- .../jdbernard/wdiwtlt/db/models/MediaFile.java | 6 +----- .../com/jdbernard/wdiwtlt/db/models/Model.java | 15 +++++++++++++++ .../com/jdbernard/wdiwtlt/db/models/Playlist.java | 5 +---- .../java/com/jdbernard/wdiwtlt/db/models/Tag.java | 6 +----- 8 files changed, 22 insertions(+), 34 deletions(-) create mode 100644 core/src/main/java/com/jdbernard/wdiwtlt/db/models/Model.java diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Album.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Album.java index 9a910e1..d5b39f0 100644 --- a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Album.java +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Album.java @@ -1,10 +1,6 @@ package com.jdbernard.wdiwtlt.db.models; -import javax.persistence.Entity; - -@Entity -public class Album { - public int id; +public class Album extends Model { public String name; public Integer trackTotal; public Integer year; diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Artist.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Artist.java index 5980c7f..4358a98 100644 --- a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Artist.java +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Artist.java @@ -1,10 +1,6 @@ package com.jdbernard.wdiwtlt.db.models; -import javax.persistence.Entity; - -@Entity -public class Artist { - public int id; +public class Artist extends Model { public String name; public String toString() { return name; } diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Bookmark.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Bookmark.java index ba9da2f..3860ba4 100644 --- a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Bookmark.java +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Bookmark.java @@ -1,10 +1,6 @@ package com.jdbernard.wdiwtlt.db.models; -import javax.persistence.Entity; - -@Entity -public class Bookmark { - public int id; +public class Bookmark extends Model { public String name; public int playlistId; public int mediaFileId; diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Image.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Image.java index 6bbec12..a0d2d42 100644 --- a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Image.java +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Image.java @@ -1,10 +1,6 @@ package com.jdbernard.wdiwtlt.db.models; -import javax.persistence.Entity; - -@Entity -public class Image { - public int id; +public class Image extends Model { public String url; public String toString() { return url; } diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/MediaFile.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/MediaFile.java index ecf9558..c581f21 100644 --- a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/MediaFile.java +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/MediaFile.java @@ -2,14 +2,10 @@ package com.jdbernard.wdiwtlt.db.models; import java.util.Date; -import javax.persistence.Entity; - -@Entity -public class MediaFile { +public class MediaFile extends Model { public static final String TAG_INFO = "tag info"; public static final String FILE_LOCATION = "file location"; - public int id; public String name; public Integer trackNumber; public int playCount = 0; diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Model.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Model.java new file mode 100644 index 0000000..281a803 --- /dev/null +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Model.java @@ -0,0 +1,15 @@ +package com.jdbernard.wdiwtlt.db.models; + +import javax.persistence.Entity; + +@Entity +public class Model { + public int id; + + public boolean equals(Object thatObj) { + if (thatObj == null) return false; + if (!(thatObj instanceof Model)) return false; + + Model that = (Model) thatObj; + return this.id == that.id; } +} diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Playlist.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Playlist.java index 634be54..04f4259 100644 --- a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Playlist.java +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Playlist.java @@ -1,11 +1,8 @@ package com.jdbernard.wdiwtlt.db.models; import java.util.Date; -import javax.persistence.Entity; -@Entity -public class Playlist { - public int id; +public class Playlist extends Model { public boolean userCreated; public Date lastUsed; public String name; diff --git a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Tag.java b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Tag.java index 9ef594f..9584361 100644 --- a/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Tag.java +++ b/core/src/main/java/com/jdbernard/wdiwtlt/db/models/Tag.java @@ -1,10 +1,6 @@ package com.jdbernard.wdiwtlt.db.models; -import javax.persistence.Entity; - -@Entity -public class Tag { - public int id; +public class Tag extends Model { public String name; public String toString() { return name; }