Skip to content

Commit

Permalink
Merge pull request #98 from mpgirro/fix_collectionsextensions_bug
Browse files Browse the repository at this point in the history
Fix all the `asBuilders()` functions
  • Loading branch information
rock3r committed May 26, 2021
2 parents bb4a030 + 8374629 commit 8512191
Show file tree
Hide file tree
Showing 32 changed files with 1,081 additions and 147 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# CHANGELOG

## v1.1.0 (under development)
## v1.1.0

* Add support for PodcastIndex namespace phase 2 tags
* Some APIs have been renamed and their old version has been deprecated (see API changes table below)
* Add support for PodcastIndex namespace
[phase 2 tags](https://github.com/Podcastindex-org/podcast-namespace/blob/4b7e66f/README.md#phase-2-closed-on-13121)
* Fix a major bug: the `asBuilders()` extension functions were returning lists with a single builder repeated, instead of a distinct builder per item
of the source list
* Builders implement `equals()`, `hashCode()` and `toString()`
* Some APIs have been renamed, and their old version has been deprecated (see API changes table below)

### Notable API changes

Expand All @@ -30,7 +34,7 @@ API that has changed | What has changed | Notes
* Adds feed writing support
* Adds additional elements for RSS and iTunes namespace
* Adds support for Podcastindex namespace
* Adds a huge amount of unit tests
* Adds a huge number of unit tests
* Adds builder factory methods to model companion objects
* Changes to java.time representation

Expand All @@ -53,7 +57,8 @@ API that has changed | What has changed | Notes
## v0.5.1

* Fixes the URI for the Podlove Simple Chapter namespace.
* Adds [Travis-CI](https://travis-ci.org/mpgirro/wien), [Codacy](https://app.codacy.com/project/mpgirro/wien), and [CodeCov](https://codecov.io/gh/mpgirro/wien) setup.
* Adds [Travis-CI](https://travis-ci.org/mpgirro/wien), [Codacy](https://app.codacy.com/project/mpgirro/wien),
and [CodeCov](https://codecov.io/gh/mpgirro/wien) setup.

## v0.5.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,25 @@ internal class ValidatingAtomBuilder : AtomBuilder {
links = linkBuilders.mapNotNull { it.build() }.asUnmodifiable()
)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ValidatingAtomBuilder) return false

if (authorBuilders != other.authorBuilders) return false
if (contributorBuilders != other.contributorBuilders) return false
if (linkBuilders != other.linkBuilders) return false

return true
}

override fun hashCode(): Int {
var result = authorBuilders.hashCode()
result = 31 * result + contributorBuilders.hashCode()
result = 31 * result + linkBuilders.hashCode()
return result
}

override fun toString(): String =
"ValidatingAtomBuilder(authorBuilders=$authorBuilders, contributorBuilders=$contributorBuilders, linkBuilders=$linkBuilders)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,49 @@ import dev.stalla.util.InternalAPI
@InternalAPI
internal class ValidatingAtomPersonBuilder : AtomPersonBuilder {

private lateinit var nameValue: String
private var name: String? = null

private var email: String? = null
private var uri: String? = null

override fun name(name: String): AtomPersonBuilder = apply { this.nameValue = name }
override fun name(name: String): AtomPersonBuilder = apply { this.name = name }

override fun email(email: String?): AtomPersonBuilder = apply { this.email = email }

override fun uri(uri: String?): AtomPersonBuilder = apply { this.uri = uri }

override val hasEnoughDataToBuild: Boolean
get() = ::nameValue.isInitialized
get() = name != null

override fun build(): AtomPerson? {
if (!hasEnoughDataToBuild) {
return null
}

return AtomPerson(
name = nameValue,
name = checkRequiredProperty(::name),
email = email,
uri = uri
)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ValidatingAtomPersonBuilder) return false

if (name != other.name) return false
if (email != other.email) return false
if (uri != other.uri) return false

return true
}

override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + (email?.hashCode() ?: 0)
result = 31 * result + (uri?.hashCode() ?: 0)
return result
}

override fun toString(): String = "ValidatingAtomPersonBuilder(name='$name', email=$email, uri=$uri)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,31 @@ import dev.stalla.util.InternalAPI
@InternalAPI
internal class ValidatingHrefOnlyImageBuilder : HrefOnlyImageBuilder {

private lateinit var hrefValue: String
private var href: String? = null

override fun href(href: String): HrefOnlyImageBuilder = apply { this.hrefValue = href }
override fun href(href: String): HrefOnlyImageBuilder = apply { this.href = href }

override val hasEnoughDataToBuild: Boolean
get() = ::hrefValue.isInitialized
get() = href != null

override fun build(): HrefOnlyImage? {
if (!hasEnoughDataToBuild) {
return null
}

return HrefOnlyImage(href = hrefValue)
return HrefOnlyImage(href = checkRequiredProperty(::href))
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ValidatingHrefOnlyImageBuilder) return false

if (href != other.href) return false

return true
}

override fun hashCode(): Int = href.hashCode()

override fun toString(): String = "ValidatingHrefOnlyImageBuilder(href='$href')"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dev.stalla.util.InternalAPI
@InternalAPI
internal class ValidatingLinkBuilder : LinkBuilder {

private lateinit var hrefValue: String
private var href: String? = null

private var hrefLang: String? = null
private var hrefResolved: String? = null
Expand All @@ -17,7 +17,7 @@ internal class ValidatingLinkBuilder : LinkBuilder {
private var title: String? = null
private var type: MediaType? = null

override fun href(href: String): LinkBuilder = apply { this.hrefValue = href }
override fun href(href: String): LinkBuilder = apply { this.href = href }

override fun hrefLang(hrefLang: String?): LinkBuilder = apply { this.hrefLang = hrefLang }

Expand All @@ -32,15 +32,15 @@ internal class ValidatingLinkBuilder : LinkBuilder {
override fun type(type: MediaType?): LinkBuilder = apply { this.type = type }

override val hasEnoughDataToBuild: Boolean
get() = ::hrefValue.isInitialized
get() = href != null

override fun build(): Link? {
if (!hasEnoughDataToBuild) {
return null
}

return Link(
href = hrefValue,
href = checkRequiredProperty(::href),
hrefLang = hrefLang,
hrefResolved = hrefResolved,
length = length,
Expand All @@ -49,4 +49,34 @@ internal class ValidatingLinkBuilder : LinkBuilder {
type = type
)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ValidatingLinkBuilder) return false

if (href != other.href) return false
if (hrefLang != other.hrefLang) return false
if (hrefResolved != other.hrefResolved) return false
if (length != other.length) return false
if (rel != other.rel) return false
if (title != other.title) return false
if (type != other.type) return false

return true
}

override fun hashCode(): Int {
var result = href.hashCode()
result = 31 * result + (hrefLang?.hashCode() ?: 0)
result = 31 * result + (hrefResolved?.hashCode() ?: 0)
result = 31 * result + (length?.hashCode() ?: 0)
result = 31 * result + (rel?.hashCode() ?: 0)
result = 31 * result + (title?.hashCode() ?: 0)
result = 31 * result + (type?.hashCode() ?: 0)
return result
}

override fun toString(): String =
"ValidatingLinkBuilder(href='$href', hrefLang=$hrefLang, hrefResolved=$hrefResolved, length=$length, rel=$rel, title=$title, " +
"type=$type)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,43 @@ import dev.stalla.util.InternalAPI
@InternalAPI
internal class ValidatingRssCategoryBuilder : RssCategoryBuilder {

private lateinit var categoryValue: String
private var category: String? = null

private var domain: String? = null

override fun category(category: String): RssCategoryBuilder = apply { this.categoryValue = category }
override fun category(category: String): RssCategoryBuilder = apply { this.category = category }

override fun domain(domain: String?): RssCategoryBuilder = apply { this.domain = domain }

override val hasEnoughDataToBuild: Boolean
get() = ::categoryValue.isInitialized
get() = category != null

override fun build(): RssCategory? {
if (!hasEnoughDataToBuild) {
return null
}

return RssCategory(
name = categoryValue,
name = checkRequiredProperty(::category, "category name is missing"),
domain = domain
)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ValidatingRssCategoryBuilder) return false

if (category != other.category) return false
if (domain != other.domain) return false

return true
}

override fun hashCode(): Int {
var result = category.hashCode()
result = 31 * result + (domain?.hashCode() ?: 0)
return result
}

override fun toString(): String = "ValidatingRssCategoryBuilder(category='$category', domain=$domain)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import dev.stalla.util.InternalAPI
@InternalAPI
internal class ValidatingRssImageBuilder : RssImageBuilder {

private lateinit var urlValue: String
private lateinit var titleValue: String
private lateinit var linkValue: String
private var url: String? = null
private var title: String? = null
private var link: String? = null

private var width: Int? = null
private var height: Int? = null
private var description: String? = null

override fun url(url: String): RssImageBuilder = apply { this.urlValue = url }
override fun url(url: String): RssImageBuilder = apply { this.url = url }

override fun title(title: String): RssImageBuilder = apply { this.titleValue = title }
override fun title(title: String): RssImageBuilder = apply { this.title = title }

override fun link(link: String): RssImageBuilder = apply { this.linkValue = link }
override fun link(link: String): RssImageBuilder = apply { this.link = link }

override fun width(width: Int?): RssImageBuilder = apply { this.width = width }

Expand All @@ -28,20 +28,47 @@ internal class ValidatingRssImageBuilder : RssImageBuilder {
override fun description(description: String?): RssImageBuilder = apply { this.description = description }

override val hasEnoughDataToBuild: Boolean
get() = ::urlValue.isInitialized && ::titleValue.isInitialized && ::linkValue.isInitialized
get() = url != null && title != null && link != null

override fun build(): RssImage? {
if (!hasEnoughDataToBuild) {
return null
}

return RssImage(
url = urlValue,
title = titleValue,
link = linkValue,
url = checkRequiredProperty(::url),
title = checkRequiredProperty(::title),
link = checkRequiredProperty(::link),
width = width,
height = height,
description = description
)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ValidatingRssImageBuilder) return false

if (url != other.url) return false
if (title != other.title) return false
if (link != other.link) return false
if (width != other.width) return false
if (height != other.height) return false
if (description != other.description) return false

return true
}

override fun hashCode(): Int {
var result = url.hashCode()
result = 31 * result + title.hashCode()
result = 31 * result + link.hashCode()
result = 31 * result + (width ?: 0)
result = 31 * result + (height ?: 0)
result = 31 * result + (description?.hashCode() ?: 0)
return result
}

override fun toString(): String =
"ValidatingRssImageBuilder(url='$url', title='$title', link='$link', width=$width, height=$height, description=$description)"
}
Loading

0 comments on commit 8512191

Please sign in to comment.