This again is quite declarative, although the switch statement is only found in two places and the behaviour is reasonably self-evident.