Convert Bookmark domain entity to kotlin.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2018-02-22 22:23:48 +01:00
parent 817122c16f
commit 3e3d39e2cd
4 changed files with 28 additions and 115 deletions

View File

@ -1,106 +0,0 @@
package org.moire.ultrasonic.domain;
import org.moire.ultrasonic.domain.MusicDirectory.Entry;
import java.io.Serializable;
import java.util.Date;
public class Bookmark implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 8988990025189807803L;
private int position;
private String username;
private String comment;
private Date created;
private Date changed;
private Entry entry;
public int getPosition()
{
return position;
}
public void setPosition(int position)
{
this.position = position;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getComment()
{
return comment;
}
public void setComment(String comment)
{
this.comment = comment;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getChanged() {
return changed;
}
public void setChanged(Date changed) {
this.changed = changed;
}
public Entry getEntry()
{
return this.entry;
}
public void setEntry(Entry entry)
{
this.entry = entry;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Bookmark bookmark = (Bookmark) o;
if (position != bookmark.position) return false;
if (username != null ? !username.equals(bookmark.username) : bookmark.username != null)
return false;
if (comment != null ? !comment.equals(bookmark.comment) : bookmark.comment != null)
return false;
if (created != null ? !created.equals(bookmark.created) : bookmark.created != null)
return false;
if (changed != null ? !changed.equals(bookmark.changed) : bookmark.changed != null)
return false;
return entry != null ? entry.equals(bookmark.entry) : bookmark.entry == null;
}
@Override
public int hashCode() {
int result = position;
result = 31 * result + (username != null ? username.hashCode() : 0);
result = 31 * result + (comment != null ? comment.hashCode() : 0);
result = 31 * result + (created != null ? created.hashCode() : 0);
result = 31 * result + (changed != null ? changed.hashCode() : 0);
result = 31 * result + (entry != null ? entry.hashCode() : 0);
return result;
}
}

View File

@ -4,13 +4,13 @@ package org.moire.ultrasonic.domain
import org.moire.ultrasonic.api.subsonic.models.Bookmark as ApiBookmark
fun ApiBookmark.toDomainEntity(): Bookmark = Bookmark().apply {
position = this@toDomainEntity.position.toInt()
username = this@toDomainEntity.username
comment = this@toDomainEntity.comment
created = this@toDomainEntity.created?.time
changed = this@toDomainEntity.changed?.time
fun ApiBookmark.toDomainEntity(): Bookmark = Bookmark(
position = this@toDomainEntity.position.toInt(),
username = this@toDomainEntity.username,
comment = this@toDomainEntity.comment,
created = this@toDomainEntity.created?.time,
changed = this@toDomainEntity.changed?.time,
entry = this@toDomainEntity.entry.toDomainEntity()
}
)
fun List<ApiBookmark>.toDomainEntitiesList(): List<Bookmark> = map { it.toDomainEntity() }

View File

@ -0,0 +1,19 @@
package org.moire.ultrasonic.domain
import org.moire.ultrasonic.domain.MusicDirectory.Entry
import java.io.Serializable
import java.util.Date
data class Bookmark(
val position: Int = 0,
val username: String,
val comment: String,
val created: Date? = null,
val changed: Date? = null,
val entry: Entry
) : Serializable {
companion object {
private const val serialVersionUID = 8988990025189807803L
}
}

View File

@ -22,8 +22,8 @@ class APIBookmarkConverterTest {
with(domainEntity) {
position `should equal to` entity.position.toInt()
username `should equal to` entity.username
comment `should equal to` entity.comment
username `should equal` entity.username
comment `should equal` entity.comment
created `should equal` entity.created?.time
changed `should equal` entity.changed?.time
entry `should equal` entity.entry.toDomainEntity()