Convert Genre domain entity to kotlin.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2018-02-22 21:57:10 +01:00
parent 9ddd68f941
commit ea5fd0d1be
4 changed files with 17 additions and 62 deletions

View File

@ -1,57 +0,0 @@
package org.moire.ultrasonic.domain;
import java.io.Serializable;
public class Genre implements Serializable
{
/**
*
*/
private static final long serialVersionUID = -3943025175219134028L;
private String name;
private String index;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getIndex()
{
return index;
}
public void setIndex(String index)
{
this.index = index;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Genre genre = (Genre) o;
if (name != null ? !name.equals(genre.name) : genre.name != null) return false;
return index != null ? index.equals(genre.index) : genre.index == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (index != null ? index.hashCode() : 0);
return result;
}
@Override
public String toString()
{
return name;
}
}

View File

@ -4,9 +4,9 @@ package org.moire.ultrasonic.domain
import org.moire.ultrasonic.api.subsonic.models.Genre as APIGenre
fun APIGenre.toDomainEntity(): Genre = Genre().apply {
name = this@toDomainEntity.name
fun APIGenre.toDomainEntity(): Genre = Genre(
name = this@toDomainEntity.name,
index = this@toDomainEntity.name.substring(0, 1)
}
)
fun List<APIGenre>.toDomainEntityList(): List<Genre> = this.map { it.toDomainEntity() }

View File

@ -0,0 +1,12 @@
package org.moire.ultrasonic.domain
import java.io.Serializable
data class Genre(
val name: String,
val index: String
) : Serializable {
companion object {
private const val serialVersionUID = -3943025175219134028L
}
}

View File

@ -18,8 +18,8 @@ class ApiGenreConverterTest {
val domainEntity = entity.toDomainEntity()
with(domainEntity) {
name `should equal to` entity.name
index `should equal to` "s"
name `should equal` entity.name
index `should equal` "s"
}
}