1717
1818import java .io .IOException ;
1919import java .net .Socket ;
20- import java .util .ArrayList ;
21- import java .util .Collections ;
22- import java .util .List ;
20+ import java .util .*;
2321
2422/**
2523 * This class is used to handle all communication with a server.
3129 */
3230public final class LobbyClient extends XStreamClient implements IPollsHistory {
3331 private static final Logger logger = LoggerFactory .getLogger (LobbyClient .class );
34- private final List <String > rooms = new ArrayList <>();
3532 private final AsyncResultManager asyncManager = new AsyncResultManager ();
3633 private final List <ILobbyClientListener > listeners = new ArrayList <>();
3734 private final List <IHistoryListener > historyListeners = new ArrayList <>();
@@ -52,10 +49,6 @@ private static INetworkInterface createTcpNetwork(String host, int port) throws
5249 return new TcpNetwork (new Socket (host , port ));
5350 }
5451
55- public List <String > getRooms () {
56- return Collections .unmodifiableList (this .rooms );
57- }
58-
5952 @ Override
6053 protected final void onObject (ProtocolMessage o ) {
6154 if (o == null ) {
@@ -83,26 +76,21 @@ protected final void onObject(ProtocolMessage o) {
8376 onRoomMessage (roomId , data );
8477 }
8578 } else if (o instanceof GamePreparedResponse ) {
86- GamePreparedResponse preparation = (GamePreparedResponse ) o ;
87- onGamePrepared (preparation );
79+ onGamePrepared ((GamePreparedResponse ) o );
8880 } else if (o instanceof JoinedRoomResponse ) {
89- String roomId = (( JoinedRoomResponse ) o ).getRoomId ();
90- this . rooms . add ( roomId );
91- onGameJoined (roomId );
81+ onGameJoined ((( JoinedRoomResponse ) o ).getRoomId () );
82+ } else if ( o instanceof RoomWasJoinedEvent ) {
83+ onGameJoined ((( RoomWasJoinedEvent ) o ). getRoomId () );
9284 } else if (o instanceof LeftGameEvent ) {
93- String roomId = ((LeftGameEvent ) o ).getRoomId ();
94- this .rooms .remove (roomId );
95- onGameLeft (roomId );
96- } else if (o instanceof ProtocolErrorMessage ) {
97- ProtocolErrorMessage response = (ProtocolErrorMessage ) o ;
98-
99- onError (response .getMessage (), response );
85+ onGameLeft (((LeftGameEvent ) o ).getRoomId ());
10086 } else if (o instanceof ObservationResponse ) {
101- String roomId = ((ObservationResponse ) o ).getRoomId ();
102- onGameObserved (roomId );
103- } else if (o instanceof TestModeResponse ) { // for handling testing
87+ onGameObserved (((ObservationResponse ) o ).getRoomId ());
88+ } else if (o instanceof TestModeResponse ) {
10489 boolean testMode = (((TestModeResponse ) o ).getTestMode ());
10590 logger .info ("TestMode was set to {} " , testMode );
91+ } else if (o instanceof ProtocolErrorMessage ) {
92+ ProtocolErrorMessage response = (ProtocolErrorMessage ) o ;
93+ onError (response .getMessage (), response );
10694 } else {
10795 onCustomObject (o );
10896 }
@@ -259,8 +247,8 @@ protected void request(ProtocolMessage request, Class<? extends ProtocolMessage>
259247 protected RequestResult blockingRequest (ProtocolMessage request ,
260248 Class <? extends ProtocolMessage > response ) throws InterruptedException {
261249 // TODO return a proper future here
262- // This is really old async code, so the variable needs to be final but still manipulatable - IDEA suggested to
263- // use an array and we'll stay with that until we reimplement it properly.
250+ // This is really old async code, so the variable needs to be final but still mutable
251+ // IDEA suggested to use an array and we'll stay with that until we reimplement it properly.
264252 final RequestResult [] requestResult = {null };
265253 final Object beacon = new Object ();
266254 synchronized (beacon ) {
0 commit comments