@@ -14,7 +14,7 @@ public final class ReservationManager {
1414 private static Logger logger = LoggerFactory .getLogger (ReservationManager .class );
1515 private static Map <String , PlayerSlot > reservations = new HashMap <String , PlayerSlot >();
1616
17- /** create Object as singleton */
17+ /** Create Object as singleton. */
1818 private ReservationManager () {
1919 // singleton
2020 }
@@ -32,14 +32,12 @@ private ReservationManager() {
3232 public static synchronized PlayerSlot redeemReservationCode (Client client , String reservation )
3333 throws RescuableClientException {
3434 PlayerSlot result = reservations .remove (reservation );
35-
36- if (result == null ) {
35+ if (result == null )
3736 throw new UnknownReservationException ();
38- } else {
39- logger .info ("Reservation {} was redeemed." , reservation );
40- result .getRoom ().fillSlot (result , client );
41- return result ;
42- }
37+
38+ logger .info ("Reservation {} was redeemed." , reservation );
39+ result .getRoom ().fillSlot (result , client );
40+ return result ;
4341 }
4442
4543 /**
@@ -52,32 +50,29 @@ public static synchronized PlayerSlot redeemReservationCode(Client client, Strin
5250 * @throws RuntimeException if the slot is already reserved
5351 */
5452 public synchronized static String reserve (PlayerSlot playerSlot ) {
55- if (reservations .containsValue (playerSlot )) {
53+ if (reservations .containsValue (playerSlot ))
5654 throw new RuntimeException ("This slot is already reserved." );
57- }
5855
5956 String key = generateUniqueId ();
6057 reservations .put (key , playerSlot );
6158 return key ;
6259 }
6360
6461 /**
65- * Generate a uniqe String ID
62+ * Generate a unique String ID.
6663 *
6764 * @return the unique ID
6865 */
6966 private synchronized static String generateUniqueId () {
70- String key = UUID .randomUUID ().toString ();
71-
72- while (reservations .containsKey (key )) {
67+ String key ;
68+ do {
7369 key = UUID .randomUUID ().toString ();
74- }
75-
70+ } while (reservations .containsKey (key ));
7671 return key ;
7772 }
7873
7974 /**
80- * Remove reservation with given redeem code and free that slot
75+ * Remove reservation with given redeem code and free that slot.
8176 *
8277 * @param reservation the redeem code
8378 */
0 commit comments