Parcelable: Support SortedSet, NavigableSet, SortedMap, NavigableMap

This commit is contained in:
Yan Zhulanow
2017-07-06 17:25:09 +03:00
parent cf607a0f14
commit d0e4b236a7
4 changed files with 24 additions and 4 deletions
@@ -82,6 +82,8 @@ interface ParcelSerializer {
|| className == ArrayList::class.java.canonicalName
|| className == LinkedList::class.java.canonicalName
|| className == Set::class.java.canonicalName
|| className == SortedSet::class.java.canonicalName
|| className == NavigableSet::class.java.canonicalName
|| className == HashSet::class.java.canonicalName
|| className == LinkedHashSet::class.java.canonicalName
|| className == TreeSet::class.java.canonicalName
@@ -93,6 +95,8 @@ interface ParcelSerializer {
}
className == Map::class.java.canonicalName
|| className == SortedMap::class.java.canonicalName
|| className == NavigableMap::class.java.canonicalName
|| className == HashMap::class.java.canonicalName
|| className == LinkedHashMap::class.java.canonicalName
|| className == TreeMap::class.java.canonicalName
@@ -204,7 +204,11 @@ abstract internal class AbstractCollectionParcelSerializer(
protected val collectionType: Type = Type.getObjectType(when (asmType.internalName) {
"java/util/List" -> "java/util/ArrayList"
"java/util/Set" -> "java/util/LinkedHashSet"
"java/util/SortedSet" -> "java/util/TreeSet"
"java/util/NavigableSet" -> "java/util/TreeSet"
"java/util/Map" -> "java/util/LinkedHashMap"
"java/util/SortedMap" -> "java/util/TreeMap"
"java/util/NavigableMap" -> "java/util/TreeMap"
else -> asmType.internalName
})
@@ -19,7 +19,9 @@ data class Test(
val f: MutableSet<String>,
val g: TreeSet<String>,
val h: HashSet<String>,
val i: LinkedHashSet<String>
val i: LinkedHashSet<String>,
val j: NavigableSet<String>,
val k: SortedSet<String>
) : Parcelable
fun box() = parcelTest { parcel ->
@@ -32,7 +34,9 @@ fun box() = parcelTest { parcel ->
f = mutableSetOf("F"),
g = TreeSet<String>().apply { this += "G" },
h = HashSet<String>().apply { this += "H" },
i = LinkedHashSet<String>().apply { this += "I" }
i = LinkedHashSet<String>().apply { this += "I" },
j = TreeSet<String>().apply { this += "J" },
k = TreeSet<String>().apply { this += "K" }
)
first.writeToParcel(parcel, 0)
@@ -45,4 +49,6 @@ fun box() = parcelTest { parcel ->
assert(first == first2)
assert((first.d as LinkedList<*>).size == 1)
assert((first2.h as HashSet<*>).size == 1)
assert(first2.j is NavigableSet<*>)
assert(first2.k is SortedSet<*>)
}
@@ -15,7 +15,9 @@ data class Test(
val b: MutableMap<String, String>,
val c: HashMap<String, String>,
val d: LinkedHashMap<String, String>,
val e: TreeMap<String, String>
val e: TreeMap<String, String>,
val f: SortedMap<String, String>,
val g: NavigableMap<String, String>
) : Parcelable
fun box() = parcelTest { parcel ->
@@ -24,7 +26,9 @@ fun box() = parcelTest { parcel ->
b = mutableMapOf("A" to "B"),
c = HashMap<String, String>().apply { put("A", "B") },
d = LinkedHashMap<String, String>().apply { put("A", "B") },
e = TreeMap<String, String>().apply { put("A", "B") }
e = TreeMap<String, String>().apply { put("A", "B") },
f = TreeMap<String, String>().apply { put("A", "B") },
g = TreeMap<String, String>().apply { put("A", "B") }
)
first.writeToParcel(parcel, 0)
@@ -37,4 +41,6 @@ fun box() = parcelTest { parcel ->
assert(first == first2)
assert((first.c as HashMap<*, *>).size == 1)
assert((first2.e as TreeMap<*, *>).size == 1)
assert(first2.f is SortedMap<*, *>)
assert(first2.g is NavigableMap<*, *>)
}