Skip to content

Commit

Permalink
Made HrefListProperty static
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora Gras <[email protected]>
  • Loading branch information
ArnyminerZ committed Dec 5, 2024
1 parent b05fd76 commit d7c2051
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ package at.bitfire.dav4jvm.property.caldav

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.property.webdav.HrefListProperty
import java.util.LinkedList
import org.xmlpull.v1.XmlPullParser

data class CalendarHomeSet(
override val hrefs: LinkedList<String> = LinkedList<String>()
override val hrefs: List<String> = emptyList()
): HrefListProperty(hrefs) {

companion object {
Expand All @@ -27,7 +26,7 @@ data class CalendarHomeSet(

override fun getName() = NAME

override fun create(parser: XmlPullParser) = create(parser, CalendarHomeSet())
override fun create(parser: XmlPullParser) = create(parser, ::CalendarHomeSet)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ package at.bitfire.dav4jvm.property.caldav

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.property.webdav.HrefListProperty
import java.util.LinkedList
import org.xmlpull.v1.XmlPullParser

data class CalendarProxyReadFor(
override val hrefs: LinkedList<String> = LinkedList<String>()
override val hrefs: List<String> = emptyList()
): HrefListProperty(hrefs) {

companion object {
Expand All @@ -25,7 +24,7 @@ data class CalendarProxyReadFor(

override fun getName() = NAME

override fun create(parser: XmlPullParser) = create(parser, CalendarProxyReadFor())
override fun create(parser: XmlPullParser) = create(parser, ::CalendarProxyReadFor)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ package at.bitfire.dav4jvm.property.caldav

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.property.webdav.HrefListProperty
import java.util.LinkedList
import org.xmlpull.v1.XmlPullParser

data class CalendarProxyWriteFor(
override val hrefs: LinkedList<String> = LinkedList<String>()
override val hrefs: List<String> = emptyList()
): HrefListProperty(hrefs) {

companion object {
Expand All @@ -25,7 +24,7 @@ data class CalendarProxyWriteFor(

override fun getName() = NAME

override fun create(parser: XmlPullParser) = create(parser, CalendarProxyWriteFor())
override fun create(parser: XmlPullParser) = create(parser, ::CalendarProxyWriteFor)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ package at.bitfire.dav4jvm.property.caldav

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.property.webdav.HrefListProperty
import java.util.LinkedList
import org.xmlpull.v1.XmlPullParser

data class CalendarUserAddressSet(
override val hrefs: LinkedList<String> = LinkedList<String>()
override val hrefs: List<String> = emptyList()
): HrefListProperty(hrefs) {

companion object {
Expand All @@ -25,7 +24,7 @@ data class CalendarUserAddressSet(

override fun getName() = NAME

override fun create(parser: XmlPullParser) = create(parser, CalendarUserAddressSet())
override fun create(parser: XmlPullParser) = create(parser, ::CalendarUserAddressSet)

}

Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/at/bitfire/dav4jvm/property/caldav/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ package at.bitfire.dav4jvm.property.caldav

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.property.webdav.HrefListProperty
import java.util.LinkedList
import org.xmlpull.v1.XmlPullParser

class Source(
override val hrefs: LinkedList<String> = LinkedList<String>()
override val hrefs: List<String> = emptyList()
): HrefListProperty(hrefs) {

companion object {
Expand All @@ -27,7 +26,7 @@ class Source(

override fun getName() = NAME

override fun create(parser: XmlPullParser) = create(parser, Source())
override fun create(parser: XmlPullParser) = create(parser, ::Source)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ package at.bitfire.dav4jvm.property.carddav

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.property.webdav.HrefListProperty
import java.util.LinkedList
import org.xmlpull.v1.XmlPullParser

class AddressbookHomeSet(
override val hrefs: LinkedList<String> = LinkedList<String>()
override val hrefs: List<String> = emptyList()
): HrefListProperty(hrefs) {

companion object {
Expand All @@ -27,7 +26,7 @@ class AddressbookHomeSet(

override fun getName() = NAME

override fun create(parser: XmlPullParser) = create(parser, AddressbookHomeSet())
override fun create(parser: XmlPullParser) = create(parser, ::AddressbookHomeSet)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package at.bitfire.dav4jvm.property.webdav
import at.bitfire.dav4jvm.Property
import org.xmlpull.v1.XmlPullParser

class GroupMembership: HrefListProperty() {
class GroupMembership: HrefListProperty(emptyList()) {

companion object {

Expand All @@ -23,7 +23,7 @@ class GroupMembership: HrefListProperty() {

override fun getName() = NAME

override fun create(parser: XmlPullParser) = create(parser, GroupMembership())
override fun create(parser: XmlPullParser) = create(parser) { GroupMembership() }

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import at.bitfire.dav4jvm.DavResource
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlReader
import java.util.LinkedList
import org.xmlpull.v1.XmlPullParser

/**
Expand All @@ -19,19 +18,30 @@ import org.xmlpull.v1.XmlPullParser
* Every [HrefListProperty] must be a data class.
*/
abstract class HrefListProperty(
open val hrefs: LinkedList<String> = LinkedList<String>()
open val hrefs: List<String>
): Property {

val href get() = hrefs.firstOrNull()


abstract class Factory : PropertyFactory {

@Deprecated("hrefs is no longer mutable.", level = DeprecationLevel.ERROR)
fun create(parser: XmlPullParser, list: HrefListProperty): HrefListProperty {
XmlReader(parser).readTextPropertyList(DavResource.HREF, list.hrefs)
val hrefs = list.hrefs.toMutableList()
XmlReader(parser).readTextPropertyList(DavResource.HREF, hrefs)
return list
}

fun <PropertyType> create(
parser: XmlPullParser,
constructor: (hrefs: List<String>
) -> PropertyType): PropertyType {
val hrefs = mutableListOf<String>()
XmlReader(parser).readTextPropertyList(DavResource.HREF, hrefs)
return constructor(hrefs)
}

}

}
4 changes: 2 additions & 2 deletions src/main/kotlin/at/bitfire/dav4jvm/property/webdav/Owner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package at.bitfire.dav4jvm.property.webdav
import at.bitfire.dav4jvm.Property
import org.xmlpull.v1.XmlPullParser

class Owner: HrefListProperty() {
class Owner: HrefListProperty(emptyList()) {

companion object {

Expand All @@ -23,7 +23,7 @@ class Owner: HrefListProperty() {

override fun getName() = NAME

override fun create(parser: XmlPullParser) = create(parser, Owner())
override fun create(parser: XmlPullParser) = create(parser) { Owner() }

}

Expand Down

0 comments on commit d7c2051

Please sign in to comment.