Migrate Share entity to kotlin.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
cb02582740
commit
20773761fa
|
@ -1,158 +0,0 @@
|
||||||
package org.moire.ultrasonic.domain;
|
|
||||||
|
|
||||||
import org.moire.ultrasonic.domain.MusicDirectory.Entry;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class Share implements Serializable {
|
|
||||||
private static final long serialVersionUID = 1487561657691009668L;
|
|
||||||
private static final Pattern urlPattern = Pattern.compile(".*/([^/?]+).*");
|
|
||||||
private String id;
|
|
||||||
private String url;
|
|
||||||
private String description;
|
|
||||||
private String username;
|
|
||||||
private String created;
|
|
||||||
private String lastVisited;
|
|
||||||
private String expires;
|
|
||||||
private Long visitCount;
|
|
||||||
private List<Entry> entries;
|
|
||||||
|
|
||||||
public Share()
|
|
||||||
{
|
|
||||||
entries = new ArrayList<Entry>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName()
|
|
||||||
{
|
|
||||||
return urlPattern.matcher(url).replaceFirst("$1");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId()
|
|
||||||
{
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id)
|
|
||||||
{
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl()
|
|
||||||
{
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url)
|
|
||||||
{
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription()
|
|
||||||
{
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description)
|
|
||||||
{
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername()
|
|
||||||
{
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username)
|
|
||||||
{
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCreated()
|
|
||||||
{
|
|
||||||
return this.created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreated(String created)
|
|
||||||
{
|
|
||||||
this.created = created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastVisited()
|
|
||||||
{
|
|
||||||
return lastVisited;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastVisited(String lastVisited)
|
|
||||||
{
|
|
||||||
this.lastVisited = lastVisited;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExpires()
|
|
||||||
{
|
|
||||||
return expires;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExpires(String expires)
|
|
||||||
{
|
|
||||||
this.expires = expires;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getVisitCount()
|
|
||||||
{
|
|
||||||
return visitCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVisitCount(Long visitCount)
|
|
||||||
{
|
|
||||||
this.visitCount = visitCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Entry> getEntries()
|
|
||||||
{
|
|
||||||
return this.entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEntry(Entry entry)
|
|
||||||
{
|
|
||||||
entries.add(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
|
|
||||||
Share share = (Share) o;
|
|
||||||
|
|
||||||
if (id != null ? !id.equals(share.id) : share.id != null) return false;
|
|
||||||
if (url != null ? !url.equals(share.url) : share.url != null) return false;
|
|
||||||
if (description != null ? !description.equals(share.description) : share.description != null)
|
|
||||||
return false;
|
|
||||||
if (username != null ? !username.equals(share.username) : share.username != null)
|
|
||||||
return false;
|
|
||||||
if (created != null ? !created.equals(share.created) : share.created != null) return false;
|
|
||||||
if (lastVisited != null ? !lastVisited.equals(share.lastVisited) : share.lastVisited != null)
|
|
||||||
return false;
|
|
||||||
if (expires != null ? !expires.equals(share.expires) : share.expires != null) return false;
|
|
||||||
if (visitCount != null ? !visitCount.equals(share.visitCount) : share.visitCount != null)
|
|
||||||
return false;
|
|
||||||
return entries != null ? entries.equals(share.entries) : share.entries == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = id != null ? id.hashCode() : 0;
|
|
||||||
result = 31 * result + (url != null ? url.hashCode() : 0);
|
|
||||||
result = 31 * result + (description != null ? description.hashCode() : 0);
|
|
||||||
result = 31 * result + (username != null ? username.hashCode() : 0);
|
|
||||||
result = 31 * result + (created != null ? created.hashCode() : 0);
|
|
||||||
result = 31 * result + (lastVisited != null ? lastVisited.hashCode() : 0);
|
|
||||||
result = 31 * result + (expires != null ? expires.hashCode() : 0);
|
|
||||||
result = 31 * result + (visitCount != null ? visitCount.hashCode() : 0);
|
|
||||||
result = 31 * result + (entries != null ? entries.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,14 +12,14 @@ fun List<APIShare>.toDomainEntitiesList(): List<Share> = this.map {
|
||||||
it.toDomainEntity()
|
it.toDomainEntity()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun APIShare.toDomainEntity(): Share = Share().apply {
|
fun APIShare.toDomainEntity(): Share = Share(
|
||||||
created = this@toDomainEntity.created?.let { shareTimeFormat.format(it.time) }
|
created = this@toDomainEntity.created?.let { shareTimeFormat.format(it.time) },
|
||||||
description = this@toDomainEntity.description
|
description = this@toDomainEntity.description,
|
||||||
expires = this@toDomainEntity.expires?.let { shareTimeFormat.format(it.time) }
|
expires = this@toDomainEntity.expires?.let { shareTimeFormat.format(it.time) },
|
||||||
id = this@toDomainEntity.id
|
id = this@toDomainEntity.id,
|
||||||
lastVisited = this@toDomainEntity.lastVisited?.let { shareTimeFormat.format(it.time) }
|
lastVisited = this@toDomainEntity.lastVisited?.let { shareTimeFormat.format(it.time) },
|
||||||
url = this@toDomainEntity.url
|
url = this@toDomainEntity.url,
|
||||||
username = this@toDomainEntity.username
|
username = this@toDomainEntity.username,
|
||||||
visitCount = this@toDomainEntity.visitCount.toLong()
|
visitCount = this@toDomainEntity.visitCount.toLong(),
|
||||||
entries.addAll(this@toDomainEntity.items.toDomainEntityList())
|
entries = this@toDomainEntity.items.toDomainEntityList().toMutableList()
|
||||||
}
|
)
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.moire.ultrasonic.domain
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.domain.MusicDirectory.Entry
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
data class Share(
|
||||||
|
var id: String? = null,
|
||||||
|
var url: String? = null,
|
||||||
|
var description: String? = null,
|
||||||
|
var username: String? = null,
|
||||||
|
var created: String? = null,
|
||||||
|
var lastVisited: String? = null,
|
||||||
|
var expires: String? = null,
|
||||||
|
var visitCount: Long? = null,
|
||||||
|
private val entries: MutableList<Entry> = mutableListOf()
|
||||||
|
) : Serializable {
|
||||||
|
val name: String?
|
||||||
|
get() = url?.let { urlPattern.matcher(url).replaceFirst("$1") }
|
||||||
|
|
||||||
|
fun getEntries(): List<Entry> {
|
||||||
|
return entries.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addEntry(entry: Entry) {
|
||||||
|
entries.add(entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val serialVersionUID = 1487561657691009668L
|
||||||
|
private val urlPattern = ".*/([^/?]+).*".toPattern()
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,15 +20,15 @@ class APIShareConverterTest {
|
||||||
val domainEntity = entity.toDomainEntity()
|
val domainEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
with(domainEntity) {
|
with(domainEntity) {
|
||||||
id `should equal to` entity.id
|
id `should equal` entity.id
|
||||||
url `should equal to` entity.url
|
url `should equal` entity.url
|
||||||
description `should equal to` entity.description
|
description `should equal` entity.description
|
||||||
username `should equal to` entity.username
|
username `should equal` entity.username
|
||||||
created `should equal to` shareTimeFormat.format(entity.created?.time)
|
created `should equal` shareTimeFormat.format(entity.created?.time)
|
||||||
lastVisited `should equal to` shareTimeFormat.format(entity.lastVisited?.time)
|
lastVisited `should equal` shareTimeFormat.format(entity.lastVisited?.time)
|
||||||
expires `should equal to` shareTimeFormat.format(entity.expires?.time)
|
expires `should equal` shareTimeFormat.format(entity.expires?.time)
|
||||||
visitCount `should equal to` entity.visitCount.toLong()
|
visitCount `should equal` entity.visitCount.toLong()
|
||||||
entries `should equal` entity.items.toDomainEntityList()
|
this.getEntries() `should equal` entity.items.toDomainEntityList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue