fix couple of sonar issues

This commit is contained in:
Ingmar Goudt 2019-06-23 23:22:21 +02:00
parent 41357c15ff
commit 1cf6d99515
5 changed files with 21 additions and 30 deletions

View file

@ -40,7 +40,7 @@ public enum TableManager {
// protected static ScheduledExecutorService expireExecutor = ThreadExecutor.getInstance().getExpireExecutor(); // protected static ScheduledExecutorService expireExecutor = ThreadExecutor.getInstance().getExpireExecutor();
private final Logger logger = Logger.getLogger(TableManager.class); private final Logger logger = Logger.getLogger(TableManager.class);
private static final DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); private final DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
private final ConcurrentHashMap<UUID, TableController> controllers = new ConcurrentHashMap<>(); private final ConcurrentHashMap<UUID, TableController> controllers = new ConcurrentHashMap<>();
private final ReadWriteLock controllersLock = new ReentrantReadWriteLock(); private final ReadWriteLock controllersLock = new ReentrantReadWriteLock();

View file

@ -50,13 +50,13 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
// checks for compatibility // checks for compatibility
EffectType needType = EffectType.CONTINUOUS; EffectType needType = EffectType.CONTINUOUS;
if (effect != null && !effect.getEffectType().equals(needType)) { if (effect.getEffectType() != needType) {
Assert.fail("ConditionalContinuousEffect supports only " + needType.toString() + " but found " + effect.getEffectType().toString()); Assert.fail("ConditionalContinuousEffect supports only " + needType.toString() + " but found " + effect.getEffectType().toString());
} }
if (otherwiseEffect != null && !otherwiseEffect.getEffectType().equals(needType)) { if (otherwiseEffect != null && otherwiseEffect.getEffectType() != needType) {
Assert.fail("ConditionalContinuousEffect supports only " + needType.toString() + " but found " + effect.getEffectType().toString()); Assert.fail("ConditionalContinuousEffect supports only " + needType.toString() + " but found " + effect.getEffectType().toString());
} }
if (effect != null && otherwiseEffect != null && !effect.getEffectType().equals(otherwiseEffect.getEffectType())) { if (otherwiseEffect != null && effect.getEffectType() != otherwiseEffect.getEffectType()) {
Assert.fail("ConditionalContinuousEffect must be same but found " + effect.getEffectType().toString() + " and " + otherwiseEffect.getEffectType().toString()); Assert.fail("ConditionalContinuousEffect must be same but found " + effect.getEffectType().toString() + " and " + otherwiseEffect.getEffectType().toString());
} }
} }
@ -119,7 +119,7 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
if (condition == null && baseCondition != null) { if (condition == null && baseCondition != null) {
condition = baseCondition; condition = baseCondition;
} }
boolean conditionState = condition.apply(game, source); boolean conditionState = condition != null && condition.apply(game, source);
if (conditionState) { if (conditionState) {
effect.setTargetPointer(this.targetPointer); effect.setTargetPointer(this.targetPointer);
return effect.apply(game, source); return effect.apply(game, source);
@ -127,10 +127,10 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
otherwiseEffect.setTargetPointer(this.targetPointer); otherwiseEffect.setTargetPointer(this.targetPointer);
return otherwiseEffect.apply(game, source); return otherwiseEffect.apply(game, source);
} }
if (!conditionState && effect.getDuration() == Duration.OneUse) { if (effect.getDuration() == Duration.OneUse) {
used = true; used = true;
} }
if (!conditionState && effect.getDuration() == Duration.Custom) { if (effect.getDuration() == Duration.Custom) {
this.discard(); this.discard();
} }
return false; return false;

View file

@ -1,6 +1,5 @@
package mage.abilities.effects.common; package mage.abilities.effects.common;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode; import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
@ -9,8 +8,9 @@ import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import java.util.UUID;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class FightTargetsEffect extends OneShotEffect { public class FightTargetsEffect extends OneShotEffect {
@ -57,27 +57,23 @@ public class FightTargetsEffect extends OneShotEffect {
return creature1.fight(creature2, source, game); return creature1.fight(creature2, source, game);
} }
} }
}
if (!game.isSimulation()) { if (!game.isSimulation()) {
game.informPlayers(card.getName() + " has been fizzled."); game.informPlayers(card.getName() + " has been fizzled.");
} }
}
return false; return false;
} }
@Override @Override
public FightTargetsEffect public FightTargetsEffect copy() {
copy() {
return new FightTargetsEffect(this); return new FightTargetsEffect(this);
} }
@Override @Override
public String public String getText(Mode mode) {
getText(Mode mode if (staticText != null && !staticText.isEmpty()) {
) {
if (staticText
!= null && !staticText
.isEmpty()) {
return staticText; return staticText;
} }

View file

@ -10,7 +10,6 @@ import mage.game.permanent.Permanent;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class LoseAbilityAttachedEffect extends ContinuousEffectImpl { public class LoseAbilityAttachedEffect extends ContinuousEffectImpl {
@ -59,11 +58,7 @@ public class LoseAbilityAttachedEffect extends ContinuousEffectImpl {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(attachmentType.verb()); sb.append(attachmentType.verb());
sb.append(" creature "); sb.append(" creature ");
if (duration == Duration.WhileOnBattlefield) {
sb.append("loses "); sb.append("loses ");
} else {
sb.append("loses ");
}
sb.append(ability.getRule()); sb.append(ability.getRule());
staticText = sb.toString(); staticText = sb.toString();
} }

View file

@ -118,7 +118,7 @@ public class TurnMods extends ArrayList<TurnMod> {
ListIterator<TurnMod> it = this.listIterator(this.size()); ListIterator<TurnMod> it = this.listIterator(this.size());
while (it.hasPrevious()) { while (it.hasPrevious()) {
TurnMod turnMod = it.previous(); TurnMod turnMod = it.previous();
if (turnMod.getExtraPhase() != null && turnMod.getPlayerId().equals(playerId) && turnMod.getExtraPhase() != null && (turnMod.getAfterPhase() == null || turnMod.getAfterPhase() == afterPhase)) { if (turnMod.getExtraPhase() != null && turnMod.getPlayerId().equals(playerId) && (turnMod.getAfterPhase() == null || turnMod.getAfterPhase() == afterPhase)) {
it.remove(); it.remove();
return turnMod; return turnMod;
} }