mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-22 10:57:58 +01:00
Add ImageEncoding enum
This commit is contained in:
parent
de9a161252
commit
3399551cec
2 changed files with 49 additions and 0 deletions
|
@ -0,0 +1,25 @@
|
|||
// SPDX-FileCopyrightText: 2024 Paul Schaub <info@pgpainless.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.algorithm
|
||||
|
||||
/**
|
||||
* Image encoding schemes for user attribute image headers.
|
||||
* Currently, only [JPEG] is defined.
|
||||
*/
|
||||
enum class ImageEncoding(val id: Int) {
|
||||
|
||||
/** JPEG File Interchange Format (JFIF). */
|
||||
JPEG(1)
|
||||
;
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun requireFromId(id: Int): ImageEncoding =
|
||||
fromId(id) ?: throw NoSuchElementException("No ImageEncoding found for id $id")
|
||||
|
||||
@JvmStatic
|
||||
fun fromId(id: Int): ImageEncoding? = values().firstOrNull { id == it.id }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// SPDX-FileCopyrightText: 2024 Paul Schaub <info@pgpainless.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.algorithm
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
|
||||
class ImageEncodingTest {
|
||||
|
||||
@Test
|
||||
fun parseJpeg() {
|
||||
assertEquals(ImageEncoding.JPEG, ImageEncoding.requireFromId(1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseUnknown() {
|
||||
assertNull(ImageEncoding.fromId(11))
|
||||
assertThrows<NoSuchElementException> { ImageEncoding.requireFromId(11) }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue