Skip to content

Commit

Permalink
Uniform naming, and some final sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgirro committed Mar 7, 2021
1 parent 6918b92 commit 47ad176
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/dev/stalla/model/MediaType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public open class MediaType private constructor(
return result
}

private fun hasParameter(attribute: String, value: String): Boolean = when (parameters.size) {
private fun hasParameter(key: String, value: String): Boolean = when (parameters.size) {
0 -> false
1 -> parameters[0].let { param ->
param.key.equalsIgnoreCase(attribute) && param.value.equalsIgnoreCase(value)
param.key.equalsIgnoreCase(key) && param.value.equalsIgnoreCase(value)
}
else -> parameters.any { param ->
param.key.equalsIgnoreCase(attribute) && param.value.equalsIgnoreCase(value)
param.key.equalsIgnoreCase(key) && param.value.equalsIgnoreCase(value)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/dev/stalla/parser/MediaTypeParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ internal object MediaTypeParser {
while (position <= text.lastIndex) {
when (text[position]) {
'=' -> {
val paramAttr = text.subtrim(start, position)
val paramKey = text.subtrim(start, position)
val (paramEnd, paramValue) = parseParameterValue(text, position + 1)
if (!paramAttr.containsMediaTypeSeparatorSymbol() && paramValue.isNotBlank()) {
if (!paramKey.containsMediaTypeSeparatorSymbol() && paramValue.isNotBlank()) {
addParam(text, start, position, paramValue)
}
return paramEnd
Expand Down
28 changes: 0 additions & 28 deletions src/main/kotlin/dev/stalla/util/AnyExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ internal fun allNotNull(a: Any?, b: Any?, c: Any?): Boolean {
return a != null && b != null && c != null
}

/** Check if all argument elements are not null. */
@InternalApi
internal fun allNotNull(a: Any?, b: Any?, c: Any?, d: Any?): Boolean {
contract {
returns(true) implies (
a != null &&
b != null &&
c != null &&
d != null
)
}
return a != null && b != null && c != null && d != null
}

/** Check if all argument elements are not null. */
@InternalApi
internal fun allNotNull(vararg elements: Any?): Boolean = elements.all { p -> p != null }
Expand Down Expand Up @@ -88,20 +74,6 @@ internal fun allNull(a: Any?, b: Any?, c: Any?): Boolean {
return a == null && b == null && c == null
}

/** Check if all argument elements are null. */
@InternalApi
internal fun allNull(a: Any?, b: Any?, c: Any?, d: Any?): Boolean {
contract {
returns(true) implies (
a == null &&
b == null &&
c == null &&
d == null
)
}
return a == null && b == null && c == null && d == null
}

/** Check if all argument elements are null. */
@InternalApi
internal fun allNull(vararg elements: Any?): Boolean = elements.all { p -> p == null }
Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/dev/stalla/model/EpisodeTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ internal class EpisodeTypeTest {
.prop(EpisodeType::type).isEqualTo("bonus")
}

@Test
fun `should not parse null to an instance in the factory nethod`() {
assertThat(EpisodeType.of(null)).isNull()
}

companion object {

@JvmStatic
Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/dev/stalla/model/ExplicitTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ internal class ExplicitTypeTest {
.prop(ExplicitType::type).isEqualTo("clean")
}

@Test
fun `should not parse null to an instance in the factory nethod`() {
assertThat(ExplicitType.of(null)).isNull()
}

companion object {

@JvmStatic
Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/dev/stalla/model/GoogleplayCategoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ internal class GoogleplayCategoryTest {
.prop(GoogleplayCategory::type).isEqualTo("Arts")
}

@Test
fun `should not parse null to an instance in the factory nethod`() {
assertThat(GoogleplayCategory.of(null)).isNull()
}

companion object {

@JvmStatic
Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/dev/stalla/model/ItunesCategoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ internal class ItunesCategoryTest {
.prop(ItunesCategory::type).isEqualTo("Arts")
}

@Test
fun `should not parse null to an instance in the factory nethod`() {
assertThat(ItunesCategory.of(null)).isNull()
}

companion object {

@JvmStatic
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/dev/stalla/model/MediaTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal class MediaTypeTest {
}

@Test
fun `should not parse null to an instance`() {
fun `should not parse null to an instance in the factory nethod`() {
assertThat(MediaType.of(null)).isNull()
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/dev/stalla/model/ShowTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ internal class ShowTypeTest {
.prop(ShowType::type).isEqualTo("episodic")
}

@Test
fun `should not parse null to an instance in the factory nethod`() {
assertThat(ShowType.of(null)).isNull()
}

companion object {

@JvmStatic
Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/dev/stalla/model/TranscriptTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ internal class TranscriptTypeTest {
.prop("toString") { TranscriptType::toString.call(it) }.isEqualTo("text/plain")
}

@Test
fun `should not parse null to an instance in the factory nethod`() {
assertThat(TranscriptType.of(null)).isNull()
}

companion object {

@JvmStatic
Expand Down

0 comments on commit 47ad176

Please sign in to comment.