Commit a9324986 authored by Ricki Hirner's avatar Ricki Hirner

Improve generics/variance

parent 3e849953
Pipeline #9889724 failed with stage
buildscript {
ext.kotlin_version = '1.1.3'
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
......
......@@ -19,10 +19,10 @@ class TestAddressBook(
object ContactFactory: AndroidContactFactory<AndroidContact> {
override fun newInstance(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, id: Long, fileName: String?, eTag: String?) =
override fun newInstance(addressBook: AndroidAddressBook<AndroidContact, *>, id: Long, fileName: String?, eTag: String?) =
AndroidContact(addressBook, id, fileName, eTag)
override fun newInstance(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, contact: Contact, fileName: String?, eTag: String?): AndroidContact =
override fun newInstance(addressBook: AndroidAddressBook<AndroidContact, *>, contact: Contact, fileName: String?, eTag: String?): AndroidContact =
AndroidContact(addressBook, contact, fileName, eTag)
}
......@@ -30,10 +30,10 @@ class TestAddressBook(
object GroupFactory: AndroidGroupFactory<AndroidGroup> {
override fun newInstance(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, id: Long, fileName: String?, eTag: String?) =
override fun newInstance(addressBook: AndroidAddressBook<*, AndroidGroup>, id: Long, fileName: String?, eTag: String?) =
AndroidGroup(addressBook, id, fileName, eTag)
override fun newInstance(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, contact: Contact, fileName: String?, eTag: String?) =
override fun newInstance(addressBook: AndroidAddressBook<*, AndroidGroup>, contact: Contact, fileName: String?, eTag: String?) =
AndroidGroup(addressBook, contact, fileName, eTag)
}
......
......@@ -21,7 +21,7 @@ import android.provider.ContactsContract.RawContacts
import java.io.FileNotFoundException
import java.util.*
open class AndroidAddressBook<out T1: AndroidContact, out T2: AndroidGroup>(
open class AndroidAddressBook<T1: AndroidContact, T2: AndroidGroup>(
var account: Account,
val provider: ContentProviderClient?,
val contactFactory: AndroidContactFactory<T1>,
......
......@@ -43,7 +43,7 @@ import java.util.*
import java.util.logging.Level
open class AndroidContact(
val addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>
val addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup>
) {
companion object {
......@@ -85,13 +85,13 @@ open class AndroidContact(
val photoMaxDimensions: Int by lazy { queryPhotoMaxDimensions() }
constructor(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, id: Long, fileName: String?, eTag: String?): this(addressBook) {
constructor(addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup>, id: Long, fileName: String?, eTag: String?): this(addressBook) {
this.id = id
this.fileName = fileName
this.eTag = eTag
}
constructor(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, contact: Contact, fileName: String?, eTag: String?): this(addressBook) {
constructor(addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup>, contact: Contact, fileName: String?, eTag: String?): this(addressBook) {
this.contact = contact
this.fileName = fileName
this.eTag = eTag
......
......@@ -8,9 +8,9 @@
package at.bitfire.vcard4android
interface AndroidContactFactory<out T: AndroidContact> {
interface AndroidContactFactory<T: AndroidContact> {
fun newInstance(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, id: Long, fileName: String?, eTag: String?): T
fun newInstance(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, contact: Contact, fileName: String?, eTag: String?): T
fun newInstance(addressBook: AndroidAddressBook<T, out AndroidGroup>, id: Long, fileName: String?, eTag: String?): T
fun newInstance(addressBook: AndroidAddressBook<T, out AndroidGroup>, contact: Contact, fileName: String?, eTag: String?): T
}
......@@ -22,7 +22,7 @@ import java.io.FileNotFoundException
//FIXME @ToString(of={"id","fileName","contact"},doNotUseGetters=true)
open class AndroidGroup(
val addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>
val addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup>
) {
companion object {
......@@ -32,16 +32,17 @@ open class AndroidGroup(
}
var id: Long? = null
var fileName: String? = null
var eTag: String? = null
constructor(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, id: Long, fileName: String?, eTag: String?): this(addressBook) {
constructor(addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup>, id: Long, fileName: String?, eTag: String?): this(addressBook) {
this.id = id
this.fileName = fileName
this.eTag = eTag
}
constructor(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, contact: Contact, fileName: String? = null, eTag: String? = null): this(addressBook) {
constructor(addressBook: AndroidAddressBook<out AndroidContact, out AndroidGroup>, contact: Contact, fileName: String? = null, eTag: String? = null): this(addressBook) {
this.contact = contact
this.fileName = fileName
this.eTag = eTag
......@@ -63,7 +64,7 @@ open class AndroidGroup(
addressBook.provider!!.query(addressBook.syncAdapterURI(ContentUris.withAppendedId(Groups.CONTENT_URI, id)),
arrayOf(COLUMN_UID, Groups.TITLE, Groups.NOTES), null, null, null)?.use { cursor ->
if (!cursor.moveToNext())
throw FileNotFoundException ("Contact group not found")
throw FileNotFoundException("Contact group not found")
c.uid = cursor.getString(0)
c.group = true
......
......@@ -8,23 +8,9 @@
package at.bitfire.vcard4android
interface AndroidGroupFactory<out T: AndroidGroup> {
interface AndroidGroupFactory<T: AndroidGroup> {
/*public static final AndroidGroupFactory INSTANCE = new AndroidGroupFactory();
public AndroidGroup newInstance(AndroidAddressBook addressBook, long id, String fileName, String eTag) {
return new AndroidGroup(addressBook, id, fileName, eTag);
}
public AndroidGroup newInstance(AndroidAddressBook addressBook, Contact contact, String fileName, String eTag) {
return new AndroidGroup(addressBook, contact, fileName, eTag);
}
public AndroidGroup[] newArray(int size) {
return new AndroidGroup[size];
}*/
fun newInstance(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, id: Long, fileName: String?, eTag: String?): T
fun newInstance(addressBook: AndroidAddressBook<AndroidContact, AndroidGroup>, contact: Contact, fileName: String?, eTag: String?): T
fun newInstance(addressBook: AndroidAddressBook<out AndroidContact, T>, id: Long, fileName: String?, eTag: String?): T
fun newInstance(addressBook: AndroidAddressBook<out AndroidContact, T>, contact: Contact, fileName: String?, eTag: String?): T
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment