Sonar's fixes

This commit is contained in:
Oleg Agafonov 2019-07-06 13:09:27 +04:00
parent f572ace420
commit bce01ce053
6 changed files with 703 additions and 714 deletions

View file

@ -848,7 +848,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
} }
// can save result // can save result
if (isDownloadOK & httpConn != null) { if (isDownloadOK && httpConn != null) {
// save data to temp // save data to temp
try (InputStream in = new BufferedInputStream(httpConn.getInputStream()); try (InputStream in = new BufferedInputStream(httpConn.getInputStream());
OutputStream tfileout = new TFileOutputStream(fileTempImage); OutputStream tfileout = new TFileOutputStream(fileTempImage);

View file

@ -135,6 +135,7 @@ public class TableView implements Serializable {
switch (table.getState()) { switch (table.getState()) {
case WAITING: case WAITING:
stateText.append(" (").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats()).append(')'); stateText.append(" (").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats()).append(')');
break;
case READY_TO_START: case READY_TO_START:
case STARTING: case STARTING:
infoText.append(" Time: ").append(table.getTournament().getOptions().getMatchOptions().getMatchTimeLimit().toString()); infoText.append(" Time: ").append(table.getTournament().getOptions().getMatchOptions().getMatchTimeLimit().toString());
@ -153,6 +154,7 @@ public class TableView implements Serializable {
if (draft != null) { if (draft != null) {
stateText.append(' ').append(draft.getBoosterNum()).append('/').append(draft.getCardNum() - 1); stateText.append(' ').append(draft.getBoosterNum()).append('/').append(draft.getCardNum() - 1);
} }
break;
default: default:
} }
this.additionalInfo = infoText.toString(); this.additionalInfo = infoText.toString();

View file

@ -1,31 +1,26 @@
package mage.server.console;
import mage.remote.Session;
import mage.view.TableView;
import mage.view.UserView;
import org.apache.log4j.Logger;
/* import javax.swing.*;
* ConsolePanel.java import javax.swing.table.AbstractTableModel;
* import javax.swing.table.TableRowSorter;
* Created on 14-May-2011, 6:08:48 PM import java.text.DateFormat;
*/ import java.text.SimpleDateFormat;
package mage.server.console; import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.text.DateFormat; import static javax.swing.JTable.AUTO_RESIZE_NEXT_COLUMN;
import java.text.SimpleDateFormat; import static javax.swing.JTable.AUTO_RESIZE_OFF;
import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.*;
import static javax.swing.JTable.AUTO_RESIZE_NEXT_COLUMN;
import static javax.swing.JTable.AUTO_RESIZE_OFF;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableRowSorter;
import mage.remote.Session;
import mage.view.TableView;
import mage.view.UserView;
import org.apache.log4j.Logger;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class ConsolePanel extends javax.swing.JPanel { public class ConsolePanel extends javax.swing.JPanel {
private static final Logger logger = Logger.getLogger(ConsolePanel.class); private static final Logger logger = Logger.getLogger(ConsolePanel.class);
@ -404,9 +399,9 @@ public class ConsolePanel extends javax.swing.JPanel {
private javax.swing.JTable tblTables; private javax.swing.JTable tblTables;
private javax.swing.JTable tblUsers; private javax.swing.JTable tblUsers;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }
class TableUserModel extends AbstractTableModel { class TableUserModel extends AbstractTableModel {
public static final int POS_USER_NAME = 0; public static final int POS_USER_NAME = 0;
public static final int POS_HOST = 1; public static final int POS_HOST = 1;
@ -487,9 +482,9 @@ class TableUserModel extends AbstractTableModel {
return false; return false;
} }
} }
class TableTableModel extends AbstractTableModel { class TableTableModel extends AbstractTableModel {
private final String[] columnNames = new String[]{"Table Name", "Owner", "Game Type", "Deck Type", "Status"}; private final String[] columnNames = new String[]{"Table Name", "Owner", "Game Type", "Deck Type", "Status"};
private TableView[] tables = new TableView[0]; private TableView[] tables = new TableView[0];
@ -553,15 +548,12 @@ class TableTableModel extends AbstractTableModel {
@Override @Override
public boolean isCellEditable(int rowIndex, int columnIndex) { public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != 5) { return columnIndex == 5;
return false;
}
return true;
} }
} }
class UpdateUsersTask extends SwingWorker<Void, List<UserView>> { class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
private final Session session; private final Session session;
private final ConsolePanel panel; private final ConsolePanel panel;
@ -589,44 +581,35 @@ class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
users = users2; users = users2;
} }
if (previousUsers == null || checkUserListChanged(users)) { checkUserListChanged(users);
logger.debug("Need to update the user list");
this.publish(users); this.publish(users);
previousUsers = users; previousUsers = users;
}
Thread.sleep(2000); Thread.sleep(2000);
} }
return null; return null;
} }
private boolean checkUserListChanged(List<UserView> usersToCheck) { private void checkUserListChanged(List<UserView> usersToCheck) {
if (previousUsers == null || usersToCheck == null) { if (previousUsers == null || usersToCheck == null) {
return true; return;
}
if (previousUsers.size() != usersToCheck.size()) {
// new user appeared
return true;
} }
for (UserView u1 : previousUsers) { for (UserView u1 : previousUsers) {
for (UserView u2 : usersToCheck) {
if (u1.getUserName().equals(u2.getUserName())) {
String s = u1.getUserName() + ',' + u1.getHost(); String s = u1.getUserName() + ',' + u1.getHost();
if (peopleIps.get(s) == null) { if (peopleIps.get(s) == null) {
logger.warn("Found new user: " + u1.getUserName() + ',' + u1.getHost()); logger.warn("Found new user: " + u1.getUserName() + ',' + u1.getHost());
peopleIps.put(s, "1"); peopleIps.put(s, "1");
} }
s = u2.getUserName() + ',' + u2.getHost(); }
for (UserView u1 : usersToCheck) {
String s = u1.getUserName() + ',' + u1.getHost();
if (peopleIps.get(s) == null) { if (peopleIps.get(s) == null) {
logger.warn("Found new user: " + u1.getUserName() + ',' + u1.getHost()); logger.warn("Found new user: " + u1.getUserName() + ',' + u1.getHost());
peopleIps.put(s, "1"); peopleIps.put(s, "1");
} }
break;
} }
} }
}
// seems nothing has been changed
return true;
}
@Override @Override
protected void process(List<List<UserView>> view) { protected void process(List<List<UserView>> view) {
@ -648,9 +631,9 @@ class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
} catch (CancellationException ex) { } catch (CancellationException ex) {
} }
} }
} }
class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> { class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
private final Session session; private final Session session;
private final UUID roomId; private final UUID roomId;
@ -700,4 +683,4 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
} catch (CancellationException ex) { } catch (CancellationException ex) {
} }
} }
} }

View file

@ -1999,8 +1999,10 @@ public class HumanPlayer extends PlayerImpl {
tResponse.setString("resolveStack"); tResponse.setString("resolveStack");
actionQueueSaved.add(tResponse); actionQueueSaved.add(tResponse);
} }
break;
default: default:
super.sendPlayerAction(playerAction, game, data); super.sendPlayerAction(playerAction, game, data);
break;
} }
} }

View file

@ -97,12 +97,13 @@ class BondOfPassionEffect extends OneShotEffect {
Permanent permanent2 = game.getPermanent(source.getTargets().get(1).getFirstTarget()); Permanent permanent2 = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (permanent2 != null) { if (permanent2 != null) {
permanent2.damage(2, source.getSourceId(), game); permanent2.damage(2, source.getSourceId(), game);
return true; } else {
}
Player player = game.getPlayer(source.getTargets().get(1).getFirstTarget()); Player player = game.getPlayer(source.getTargets().get(1).getFirstTarget());
if (player != null) { if (player != null) {
player.damage(2, source.getSourceId(), game); player.damage(2, source.getSourceId(), game);
} }
}
return true; return true;
} }
} }

View file

@ -1,10 +1,5 @@
package mage; package mage;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.condition.Condition; import mage.abilities.condition.Condition;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
@ -14,6 +9,11 @@ import mage.filter.Filter;
import mage.filter.FilterMana; import mage.filter.FilterMana;
import mage.game.Game; import mage.game.Game;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/** /**
* @author nantuko * @author nantuko
*/ */
@ -192,6 +192,7 @@ public class ConditionalMana extends Mana implements Serializable {
break; break;
case COLORLESS: case COLORLESS:
colorless += amount; colorless += amount;
break;
case GENERIC: case GENERIC:
generic += amount; generic += amount;
break; break;