package Ġde . hav em ann . l uk as . nim . domain . service Ċ Ċ import Ġde . hav em ann . l uk as . nim . domain . ent ites . Nim Game Ċ import Ġde . hav em ann . l uk as . nim . domain . ent ites . Nim Game Impl Ċ import Ġde . hav em ann . l uk as . nim . domain . value type . Match Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . stereotype . Service Ċ import Ġorg . springframework . web . bind . annotation . ResponseStatus Ċ import Ġjava . util . concurrent . Concurrent HashMap Ċ import Ġjava . util . concurrent . Concurrent Map Ċ import Ġjava . util . concurrent . atomic . Atomic Long Ċ import Ġjavax . validation . constraints . Min ĊĊ Ċ /** Ċ Ġ* ĠService Ġfor Ġmanagement Ġof Ġ{@ link ĠNim Game } Ċ Ġ*/ Ċ interface ĠNim Game Service Ġ{ ĊĠĠĠ Ġfun Ġcreate New Game ( player 1 : ĠNim Game . Player , Ġplayer 2 : ĠNim Game . Player ): ĠNim Game ĊĠĠĠ Ġfun Ġdelete Game ( id : ĠLong ): ĠNim Game ĊĠĠĠ Ġfun Ġfind Game ( game Id : ĠLong ): ĠNim Game Ċ } Ċ Ċ @ Service Ċ class ĠNim Game Service InMemory Ġ: ĠNim Game Service Ġ{ ĊĊĠĠĠ Ġ@ Min ( value Ġ= Ġ 2 ) ĊĠĠĠ Ġ@ Value ("\ ${ de . hav em ann . l uk as . nim . game . default Matches }") ĊĠĠĠ Ġprivate Ġvar Ġdefault Match Count : ĠInt Ġ= Ġ 0 ĊĊĠĠĠ Ġprivate Ġval Ġunique Game Id Ġ= ĠAtomic Long () ĊĠĠĠ Ġprivate Ġval Ġgames : ĠConcurrent Map < Long , ĠNim Game > Ġ= ĠConcurrent HashMap () ĊĊĠĠĠ Ġoverride Ġfun Ġcreate New Game ( player 1 : ĠNim Game . Player , Ġplayer 2 : ĠNim Game . Player ): ĠNim Game Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġgame Id Ġ= Ġunique Game Id . increment AndGet () ĊĠĠĠĠĠĠĠ Ġval Ġgame Ġ= ĠNim Game Impl ( game Id , Ġplayer 1 , Ġplayer 2 , ĠMatch ( default Match Count )) ĊĠĠĠĠĠĠĠ Ġgames [ game Id ] Ġ= Ġgame ĊĠĠĠĠĠĠĠ Ġreturn Ġgame ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġdelete Game ( id : ĠLong ): ĠNim Game Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgames . remove ( id ) Ġ?: Ġthrow ĠGame NotFoundException ( id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġfind Game ( game Id : ĠLong ): ĠNim Game Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgames [ game Id ] Ġ?: Ġthrow ĠGame NotFoundException ( game Id ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ ResponseStatus ( code Ġ= ĠHttpStatus . NOT _ FOUND ) Ċ class ĠGame NotFoundException ( game Id : ĠLong ) Ġ: ĠRuntimeException (" game Ġnot Ġfound Ġgame Id =$ game Id ") Ċ