Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Feb 17, 2021
1 parent 6b52904 commit 27522bf
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/kotlin/dev/stalla/model/StyledDuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,18 @@ public sealed class StyledDuration {
}
}

public companion object Factory {
public companion object Factory : TypeFactory<StyledDuration> {

// Parses the format: [-][HH:]MM:SS
private val hhMmSsRegex = "(-)?(?:(\\d{1,2}):)?(\\d{1,2}):(\\d{1,2})".toRegex()

// Parses the format: [-]SS...[.FFF...]
private val plainSecondsRegex = "(-)?(\\d+)(?:\\.(\\d+))?".toRegex()

public fun of(rawDuration: String?): StyledDuration? {
if (rawDuration.isNullOrBlank()) return null
return tryParsingAsPlainSeconds(rawDuration) ?: tryParsingAsHhMmSs(rawDuration)
@JvmStatic
public override fun of(type: String?): StyledDuration? {
if (type.isNullOrBlank()) return null
return tryParsingAsPlainSeconds(type) ?: tryParsingAsHhMmSs(type)
}

private fun tryParsingAsPlainSeconds(rawDuration: String): StyledDuration? {
Expand Down Expand Up @@ -158,6 +159,7 @@ public sealed class StyledDuration {
}
}

@JvmStatic
@JvmOverloads
public fun secondsAndFraction(seconds: Int = 0, nano: Long = 0, positive: Boolean = true): SecondsAndFraction {
require(seconds >= 0 && nano >= 0) { "Components cannot be negative" }
Expand All @@ -167,12 +169,15 @@ public sealed class StyledDuration {
return SecondsAndFraction(Duration.parse(durationString))
}

@JvmStatic
@JvmOverloads
public fun seconds(seconds: Int = 0, positive: Boolean = true): Seconds {
require(seconds >= 0) { "Seconds cannot be negative" }
val sign = signForPositive(positive)
return Seconds(Duration.ofSeconds(seconds.toLong() * sign))
}

@JvmStatic
@JvmOverloads
public fun minutesSeconds(minutes: Int = 0, seconds: Int = 0, positive: Boolean = true): MinutesSeconds {
require(minutes >= 0 && seconds >= 0) { "Components cannot be negative" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum class ExplicitType(public val type: String) {

public companion object Factory : TypeFactory<ExplicitType> {

@JvmStatic
override fun of(type: String?): ExplicitType? = type?.let {
values().find { t -> t.type.equals(it, ignoreCase = true) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum class GoogleplayCategory(public val type: String) {

public companion object Factory : TypeFactory<GoogleplayCategory> {

@JvmStatic
override fun of(type: String?): GoogleplayCategory? = type?.let {
values().find { t -> t.type.equals(it, ignoreCase = true) }
}
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/dev/stalla/model/itunes/EpisodeType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum class EpisodeType(public val type: String) {

public companion object Factory : TypeFactory<EpisodeType> {

@JvmStatic
override fun of(type: String?): EpisodeType? = type?.let {
values().find { t -> t.type.equals(it, ignoreCase = true) }
}
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/dev/stalla/model/itunes/ShowType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum class ShowType(public val type: String) {

public companion object Factory : TypeFactory<ShowType> {

@JvmStatic
override fun of(type: String?): ShowType? = type?.let {
values().find { t -> t.type.equals(it, ignoreCase = true) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum class TranscriptType(public val type: String) {

public companion object Factory : TypeFactory<TranscriptType> {

@JvmStatic
override fun of(type: String?): TranscriptType? = type?.let {
values().find { t -> t.type.equals(it, ignoreCase = true) }
}
Expand Down

0 comments on commit 27522bf

Please sign in to comment.