2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter.api
|
|
|
|
|
|
|
|
import java.util.ArrayList
|
|
|
|
import java.util.HashSet
|
|
|
|
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootAccount
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootNotification
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootReport
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootStatus
|
|
|
|
|
|
|
|
class DuplicateMap {
|
|
|
|
|
|
|
|
private val set_status_id = HashSet<Long>()
|
|
|
|
private val set_notification_id = HashSet<Long>()
|
|
|
|
private val set_report_id = HashSet<Long>()
|
|
|
|
private val set_account_id = HashSet<Long>()
|
|
|
|
private val set_status_uri = HashSet<String>()
|
|
|
|
|
|
|
|
fun clear() {
|
|
|
|
set_status_id.clear()
|
|
|
|
set_notification_id.clear()
|
|
|
|
set_report_id.clear()
|
|
|
|
set_account_id.clear()
|
|
|
|
set_status_uri.clear()
|
|
|
|
}
|
|
|
|
|
2018-01-12 10:01:25 +01:00
|
|
|
fun isDuplicate(o : Any) : Boolean {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
when(o) {
|
|
|
|
|
|
|
|
is TootStatus ->{
|
|
|
|
val uri = o.uri
|
2018-01-12 10:01:25 +01:00
|
|
|
val url = o.url
|
|
|
|
when {
|
|
|
|
uri?.isNotEmpty() == true -> {
|
|
|
|
if(set_status_uri.contains(uri)) return true
|
|
|
|
set_status_uri.add(uri)
|
|
|
|
}
|
|
|
|
url?.isNotEmpty() == true -> {
|
|
|
|
// URIとURLで同じマップを使いまわすが、害はないと思う…
|
|
|
|
if(set_status_uri.contains(url)) return true
|
|
|
|
set_status_uri.add(url)
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
if(set_status_id.contains(o.id)) return true
|
|
|
|
set_status_id.add(o.id)
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
is TootNotification -> {
|
|
|
|
if(set_notification_id.contains(o.id)) return true
|
|
|
|
set_notification_id.add(o.id)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
is TootReport -> {
|
|
|
|
if(set_report_id.contains(o.id)) return true
|
|
|
|
set_report_id.add(o.id)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
is TootAccount -> {
|
|
|
|
if(set_account_id.contains(o.id)) return true
|
|
|
|
set_account_id.add(o.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
fun filterDuplicate(src : Collection<Any>) : ArrayList<Any> {
|
|
|
|
val list_new = ArrayList<Any>()
|
|
|
|
for(o in src) {
|
|
|
|
if(isDuplicate(o)) continue
|
|
|
|
list_new.add(o)
|
|
|
|
}
|
|
|
|
return list_new
|
|
|
|
}
|
|
|
|
}
|