1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-14 00:12:06 +01:00

Add ImageEncoding enum

This commit is contained in:
Paul Schaub 2024-01-20 19:23:55 +01:00
parent de9a161252
commit 3399551cec
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 49 additions and 0 deletions

View file

@ -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 }
}
}

View file

@ -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) }
}
}