-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da1be17
commit bcf8c96
Showing
2 changed files
with
54 additions
and
50 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
app/src/main/kotlin/no/nav/aap/brev/prosessering/ProsesseringFlyt.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package no.nav.aap.brev.prosessering | ||
|
||
import no.nav.aap.brev.domene.ProsesseringStatus | ||
import no.nav.aap.brev.prosessering.steg.Steg | ||
|
||
class ProsesseringFlyt private constructor( | ||
private val rekkefølge: List<Steg>, | ||
private val stegTilUtfall: HashMap<Steg, ProsesseringStatus>, | ||
private val utfallTilSteg: HashMap<ProsesseringStatus, Steg>, | ||
) { | ||
|
||
fun fraStatus(prosesseringStatus: ProsesseringStatus?): List<Steg> { | ||
if (prosesseringStatus == null) { | ||
return rekkefølge | ||
} | ||
val stegForUtfall = utfallTilSteg[prosesseringStatus] | ||
?: throw IllegalStateException("Uforventet oppslag av udefinert steg for status $prosesseringStatus") | ||
return rekkefølge.dropWhile { it != stegForUtfall }.drop(1) | ||
} | ||
|
||
fun utfall(steg: Steg): ProsesseringStatus { | ||
return stegTilUtfall[steg] | ||
?: throw IllegalStateException("Uforventet oppslag av udefinert utfall for steg $steg") | ||
} | ||
|
||
class Builder { | ||
private val rekkefølge = mutableListOf<Steg>() | ||
private val stegTilUtfall = mutableMapOf<Steg, ProsesseringStatus>() | ||
private val utfallTilSteg = mutableMapOf<ProsesseringStatus, Steg>() | ||
|
||
fun med(steg: Steg, utfall: ProsesseringStatus): Builder { | ||
if (rekkefølge.contains(steg)) { | ||
throw IllegalStateException("Steg $steg er allerede lagt til: $rekkefølge") | ||
} | ||
rekkefølge.add(steg) | ||
stegTilUtfall.put(steg, utfall) | ||
utfallTilSteg.put(utfall, steg) | ||
|
||
return this | ||
} | ||
|
||
fun build(): ProsesseringFlyt { | ||
if (rekkefølge.isEmpty()) { | ||
throw IllegalStateException("Ingen steg å prosessere.") | ||
} | ||
|
||
return ProsesseringFlyt( | ||
rekkefølge = rekkefølge, | ||
stegTilUtfall = HashMap(stegTilUtfall), | ||
utfallTilSteg = HashMap(utfallTilSteg), | ||
) | ||
} | ||
} | ||
} |