Created
May 10, 2018 15:49
-
-
Save sellmair/78a4a12ddc785915cc3f470e6deeda46 to your computer and use it in GitHub Desktop.
Phantom Types in Kotlin: Modelling a Pipeline Request with static accessor
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
class Request<T>( | |
private val image: Image?, | |
private val timestamp: Timestamp?, | |
private val measureSettings: MeasureSettings?, | |
private val preparedImage: Mat?, | |
private val scaledPreparedImage: Mat?, | |
private val shapes: List<Shape>?, | |
private val features: List<Feature>?, | |
private val people: List<Person>?) { | |
companion object { | |
fun imageOf(request: Request<out ReadRawImage>): Image = | |
request.image ?: throw StageException() | |
fun timestampOf(request: Request<out ReadTimestamp>): Timestamp = | |
request.timestamp ?: throw StageException() | |
fun measureSettingsOf(request: Request<out ReadMeasureSettings>): MeasureSettings = | |
request.measureSettings ?: throw StageException() | |
fun preparedImageOf(request: Request<out ReadPreparedImage>): Mat = | |
request.preparedImage ?: throw StageException() | |
fun scaledPreparedImageOf(request: Request<out ReadPreparedImage>) = | |
request.scaledPreparedImage ?: throw StageException() | |
fun shapesOf(request: Request<out ReadShapes>) = | |
request.shapes ?: throw StageException() | |
fun featuresOf(request: Request<out ReadFeatures>) = | |
request.features ?: throw StageException() | |
fun peopleOf(request: Request<out ReadPeople>) = | |
request.people ?: throw StageException() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment