talk to interfaces rather than implementations

This commit is contained in:
igoudt 2017-07-16 11:04:20 +02:00
parent 0c80172c2d
commit 905829561e
32 changed files with 259 additions and 299 deletions

View file

@ -27,10 +27,6 @@
*/
package mage.server;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.server.exceptions.UserNotFoundException;
@ -40,6 +36,11 @@ import mage.view.ChatMessage.MessageType;
import mage.view.ChatMessage.SoundToPlay;
import org.apache.log4j.Logger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -290,7 +291,7 @@ public enum ChatManager {
}
}
public ArrayList<ChatSession> getChatSessions() {
public List<ChatSession> getChatSessions() {
return new ArrayList<>(chatSessions.values());
}

View file

@ -36,10 +36,7 @@ import mage.view.ChatMessage.SoundToPlay;
import org.apache.log4j.Logger;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
@ -119,7 +116,7 @@ public class ChatSession {
public void broadcast(String userName, String message, MessageColor color, boolean withTime, MessageType messageType, SoundToPlay soundToPlay) {
if (!message.isEmpty()) {
HashSet<UUID> clientsToRemove = new HashSet<>();
Set<UUID> clientsToRemove = new HashSet<>();
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(userName, message, (withTime ? timeFormatter.format(new Date()) : ""), color, messageType, soundToPlay));
for (UUID userId : clients.keySet()) {
Optional<User> user = UserManager.instance.getUser(userId);

View file

@ -369,7 +369,7 @@ public enum TableManager {
+ " | " + sessionState
+ " | " + user.getName() + " (" + user.getUserState().toString() + " - " + user.getPingInfo() + ')');
}
ArrayList<ChatSession> chatSessions = ChatManager.instance.getChatSessions();
List<ChatSession> chatSessions = ChatManager.instance.getChatSessions();
logger.debug("------- ChatSessions: " + chatSessions.size() + " ----------------------------------");
for (ChatSession chatSession : chatSessions) {
logger.debug(chatSession.getChatId() + " " + formatter.format(chatSession.getCreateTime()) + ' ' + chatSession.getInfo() + ' ' + chatSession.getClients().values().toString());
@ -387,7 +387,7 @@ public enum TableManager {
debugServerState();
}
logger.debug("TABLE HEALTH CHECK");
ArrayList<Table> tableCopy = new ArrayList<>(tables.values());
List<Table> tableCopy = new ArrayList<>(tables.values());
for (Table table : tableCopy) {
try {
if (table.getState() != TableState.FINISHED) {

View file

@ -73,7 +73,7 @@ public class User {
private final String host;
private final Date connectionTime;
private final Map<UUID, Table> tables;
private final ArrayList<UUID> tablesToDelete;
private final List<UUID> tablesToDelete;
private final Map<UUID, GameSessionPlayer> gameSessions;
private final Map<UUID, DraftSession> draftSessions;
private final Map<UUID, UUID> userTournaments; // playerId, tournamentId

View file

@ -88,8 +88,8 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
private void update() {
List<Table> allTables = new ArrayList<>(tables.values());
allTables.sort(new TableListSorter());
ArrayList<MatchView> matchList = new ArrayList<>();
ArrayList<TableView> tableList = new ArrayList<>();
List<MatchView> matchList = new ArrayList<>();
List<TableView> tableList = new ArrayList<>();
for (Table table : allTables) {
if (table.getState() != TableState.FINISHED) {
tableList.add(new TableView(table));

View file

@ -18,6 +18,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public enum UserStatsRepository {
@ -107,7 +108,7 @@ public enum UserStatsRepository {
// updateUserStats reads tables finished after the last DB update and reflects it to the DB.
// It returns the list of user names that are upated.
public List<String> updateUserStats() {
HashSet<String> updatedUsers = new HashSet<>();
Set<String> updatedUsers = new HashSet<>();
// Lock the DB so that no other updateUserStats runs at the same time.
synchronized(this) {
long latestEndTimeMs = this.getLatestEndTimeMs();