private void matchClients() { final TIntArrayList ids = new TIntArrayList(clients.size()); clients.forEachEntry( new TIntObjectProcedure<ClientInfo>() { @Override public boolean execute(int id, ClientInfo client) { if (client.readyForGame()) ids.add(id); return true; } }); if (ids.size() < 2) return; ids.sort(); for (int i = 0; i < ids.size(); i += 2) { int idOne = ids.get(i); int idTwo = ids.get(i + 1); ClientInfo clientOne = clients.remove(idOne); ClientInfo clientTwo = clients.remove(idTwo); if (clientOne.getAddress().equals(clientTwo.getAddress()) && clientOne.getPort() == clientTwo.getPort()) { if (clientOne.getLastPingTime() > clientTwo.getLastPingTime()) { clients.put(idOne, clientOne); } else { clients.put(idTwo, clientTwo); } continue; } boolean isHost = isHost(clientOne, clientTwo); NetworkGameInfo networkGameInfo; if (isHost) { networkGameInfo = new NetworkGameInfo( idOne, clientOne, clientTwo, clientOne.getRequestedBoard(), clientOne.getRequestedSpeed()); } else { networkGameInfo = new NetworkGameInfo( idTwo, clientTwo, clientOne, clientTwo.getRequestedBoard(), clientTwo.getRequestedSpeed()); } games.put(idOne, networkGameInfo); games.put(idTwo, networkGameInfo); System.out.println("Made game for " + idOne + " and " + idTwo + " " + networkGameInfo); } }
@Override public void deleteTableById(int tableId) { T table = tablesById.get(tableId); if (table != null) { tablesByIndx.remove(table); tablesById.remove(tableId); } }
public void removeRow(int row) { matrix.remove(row); }