2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter.api
|
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
import com.google.android.exoplayer2.Timeline
|
2018-01-20 07:51:14 +01:00
|
|
|
import jp.juggler.subwaytooter.api.entity.*
|
2018-01-04 19:52:25 +01:00
|
|
|
import java.util.ArrayList
|
|
|
|
import java.util.HashSet
|
|
|
|
|
|
|
|
class DuplicateMap {
|
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
private val set_id = HashSet<EntityId>()
|
|
|
|
private val set_uri = HashSet<String>()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
fun clear() {
|
2018-08-26 04:09:34 +02:00
|
|
|
set_id.clear()
|
|
|
|
set_uri.clear()
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-01-20 07:51:14 +01:00
|
|
|
fun isDuplicate(o : TimelineItem) : Boolean {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
if(o is TootStatus) {
|
|
|
|
val uri = o.uri
|
|
|
|
val url = o.url
|
|
|
|
when {
|
|
|
|
uri?.isNotEmpty() == true -> {
|
|
|
|
if(set_uri.contains(uri)) return true
|
|
|
|
set_uri.add(uri)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
url?.isNotEmpty() == true -> {
|
|
|
|
// URIとURLで同じマップを使いまわすが、害はないと思う…
|
|
|
|
if(set_uri.contains(url)) return true
|
|
|
|
set_uri.add(url)
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
2018-08-26 04:09:34 +02:00
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
when(o) {
|
|
|
|
is TootReport,
|
|
|
|
is TootStatus,
|
|
|
|
is TootAccount,
|
|
|
|
is TootNotification -> {
|
|
|
|
val id = o.getOrderId()
|
|
|
|
if(id.notDefault){
|
|
|
|
if(set_id.contains(o.getOrderId())) return true
|
|
|
|
set_id.add(o.getOrderId())
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-01-20 07:51:14 +01:00
|
|
|
fun filterDuplicate(src : Collection<TimelineItem>?) : ArrayList<TimelineItem> {
|
|
|
|
val list_new = ArrayList<TimelineItem>()
|
2018-08-26 04:09:34 +02:00
|
|
|
if(src != null) {
|
2018-01-20 07:51:14 +01:00
|
|
|
for(o in src) {
|
|
|
|
if(isDuplicate(o)) continue
|
|
|
|
list_new.add(o)
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
return list_new
|
|
|
|
}
|
|
|
|
}
|