Created
February 7, 2021 14:53
-
-
Save john-evangelist/b1083fd0833f605d9d792ea1ecc4c71f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.IllegalArgumentException | |
class Video(private val data: Array<Byte>, private val encoding: VideoEncoding) { | |
fun compress(compressor: VideoCompressor): Sequence<Byte> { | |
if (compressor.supports(encoding)) { | |
compressor.compress(data) | |
} | |
throw IllegalArgumentException("compressor does not support encoding $encoding") | |
} | |
} | |
enum class VideoEncoding { | |
H264, MP4, Webm | |
} | |
interface VideoCompressor { | |
fun compress(data: Array<Byte>): Sequence<Byte> | |
fun supports(encoding: VideoEncoding): Boolean | |
} | |
class H264VideoCompressor : VideoCompressor { | |
override fun compress(data: Array<Byte>): Sequence<Byte> { | |
TODO("Not yet implemented") | |
} | |
override fun supports(encoding: VideoEncoding) = encoding == VideoEncoding.H264 | |
} | |
class WebmVideoCompressor : VideoCompressor { | |
override fun compress(data: Array<Byte>): Sequence<Byte> { | |
TODO("Not yet implemented") | |
} | |
override fun supports(encoding: VideoEncoding) = encoding == VideoEncoding.Webm | |
} | |
class MP4VideoCompressor : VideoCompressor { | |
override fun compress(data: Array<Byte>): Sequence<Byte> { | |
TODO("Not yet implemented") | |
} | |
override fun supports(encoding: VideoEncoding) = encoding == VideoEncoding.MP4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment