Skip to content

Commit

Permalink
Use lists instead of varargs which have to be spread
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulWoitaschek committed Jul 19, 2017
1 parent 6826223 commit a10987d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class MatroskaChapter(
val children: List<MatroskaChapter>
) {

fun getName(vararg preferredLanguages: String): String? = preferredLanguages
fun getName(preferredLanguages: List<String> = emptyList<String>()): String? = preferredLanguages
.mapNotNull { language ->
names.find { language in it.languages }
?.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.util.SparseArray

object MatroskaChapterFlattener {

fun toSparseArray(list: List<MatroskaChapter>, vararg preferredLanguages: String): SparseArray<String> {
fun toSparseArray(list: List<MatroskaChapter>, preferredLanguages: List<String>): SparseArray<String> {
val res = SparseArray<String>()

fun addChapter(chapters: List<MatroskaChapter>, depth: Int) {
Expand All @@ -14,7 +14,7 @@ object MatroskaChapterFlattener {
if (i == 0) depth else 0
// Simple hack with adding depth is needed because chapter
// and it's first sub-chapter have usually the same starting time.
val name = "+ ".repeat(depth) + (chapter.getName(*preferredLanguages) ?: "Chapter ${i + 1}")
val name = "+ ".repeat(depth) + (chapter.getName(preferredLanguages) ?: "Chapter ${i + 1}")
res.put(duration, name)
addChapter(chapter.children, depth + 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object MatroskaChapterReader {
fun read(file: File): SparseArray<String> {
try {
val chapters = ReadAsMatroskaChapters.read(file)
return MatroskaChapterFlattener.toSparseArray(chapters, Locale.getDefault().isO3Language, "eng")
return MatroskaChapterFlattener.toSparseArray(chapters, listOf(Locale.getDefault().isO3Language, "eng"))
} catch (ex: RuntimeException) {
// JEBML documentation just say's that it throws RuntimeException.
// For example NullPointerException is thrown if unknown EBML Element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class MatroskaChapterReadingTest {
MatroskaChapterName("サブパート1", setOf("jpn"))
), listOf())
assertThat(chapter.getName()).isEqualTo("Podczęść 1")
assertThat(chapter.getName("ger", "jpn")).isEqualTo("Subpart 1")
assertThat(chapter.getName("ind", "kac", "jpn", "eng")).isEqualTo("サブパート1")
assertThat(chapter.getName(listOf("ger", "jpn"))).isEqualTo("Subpart 1")
assertThat(chapter.getName(listOf("ind", "kac", "jpn", "eng"))).isEqualTo("サブパート1")
}

@Test
fun flattenMatroskaChapterListTest() {
assertThat(MatroskaChapterFlattener.toSparseArray(testFileMatroskaChapters, "pol", "eng")
assertThat(MatroskaChapterFlattener.toSparseArray(testFileMatroskaChapters, listOf("pol", "eng"))
.toMap()).isEqualTo(testFileChapters)
}

Expand Down

0 comments on commit a10987d

Please sign in to comment.