Merge pull request #2868 from kubikrubikvkube/master

Functional interfaces annotation and bugfixes
This commit is contained in:
ingmargoudt 2017-02-15 20:27:21 +01:00 committed by GitHub
commit a1bc43d33e
96 changed files with 215 additions and 157 deletions

View file

@ -28,6 +28,8 @@
package mage;
import java.io.Serializable;
import java.util.Objects;
import mage.util.Copyable;
public class MageInt implements Serializable, Copyable<MageInt> {
@ -75,7 +77,7 @@ public class MageInt implements Serializable, Copyable<MageInt> {
@Override
public MageInt copy() {
if (this == EmptyMageInt) {
if (Objects.equals(this, EmptyMageInt)) {
return this;
}
return new MageInt(baseValue, baseValueModified, boostedValue, cardValue);

View file

@ -35,6 +35,7 @@ import java.util.UUID;
*
* @author BetaSteward_at_googlemail.com
*/
@FunctionalInterface
public interface MageItem extends Serializable {
UUID getId();

View file

@ -30,6 +30,8 @@ package mage;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import mage.constants.ColoredManaSymbol;
import mage.util.Copyable;
@ -89,11 +91,11 @@ public class ObjectColor implements Serializable, Copyable<ObjectColor>, Compara
*/
public ObjectColor union(ObjectColor other) {
ObjectColor newColor = new ObjectColor();
newColor.white = white | other.white;
newColor.blue = blue | other.blue;
newColor.black = black | other.black;
newColor.red = red | other.red;
newColor.green = green | other.green;
newColor.white = white || other.white;
newColor.blue = blue || other.blue;
newColor.black = black || other.black;
newColor.red = red || other.red;
newColor.green = green || other.green;
return newColor;
}
@ -168,20 +170,20 @@ public class ObjectColor implements Serializable, Copyable<ObjectColor>, Compara
}
public boolean hasColor() {
return white | blue | black | red | green;
return white || blue || black || red || green;
}
public boolean isMulticolored() {
if (isColorless()) {
return false;
}
if (white && (blue | black | red | green)) {
if (white && (blue || black || red || green)) {
return true;
}
if (blue && (black | red | green)) {
if (blue && (black || red || green)) {
return true;
}
if (black && (red | green)) {
if (black && (red || green)) {
return true;
}
return red && green;
@ -307,22 +309,22 @@ public class ObjectColor implements Serializable, Copyable<ObjectColor>, Compara
}
public boolean contains(ObjectColor color) {
if (this == color) {
if (Objects.equals(this, color)) {
return true;
}
if (color.white & this.white) {
if (color.white && this.white) {
return true;
}
if (color.blue & this.blue) {
if (color.blue && this.blue) {
return true;
}
if (color.black & this.black) {
if (color.black && this.black) {
return true;
}
if (color.red & this.red) {
if (color.red && this.red) {
return true;
}
if (color.green & this.green) {
if (color.green && this.green) {
return true;
}
return false;

View file

@ -27,6 +27,7 @@
*/
package mage.abilities.common;
import java.util.Objects;
import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
@ -65,7 +66,7 @@ public class AttacksAloneTriggeredAbility extends TriggeredAbilityImpl {
if(game.getActivePlayerId().equals(this.controllerId) ) {
UUID creatureId = this.getSourceId();
if(creatureId != null) {
if(game.getCombat().attacksAlone() && creatureId == game.getCombat().getAttackers().get(0)) {
if(game.getCombat().attacksAlone() && Objects.equals(creatureId, game.getCombat().getAttackers().get(0))) {
UUID defender = game.getCombat().getDefenderId(creatureId);
if(defender != null) {
for(Effect effect: getEffects()) {

View file

@ -10,6 +10,7 @@ import mage.game.Game;
*
* @author nantuko, noxx
*/
@FunctionalInterface
public interface Condition extends Serializable {
public enum ComparisonType {

View file

@ -27,6 +27,7 @@
*/
package mage.abilities.condition.common;
import java.util.Objects;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
@ -50,7 +51,7 @@ public class SourceOnBattlefieldControlUnchangedCondition implements Condition {
controllerId = source.getControllerId();
}
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
return (permanent != null && controllerId == source.getControllerId());
return (permanent != null && Objects.equals(controllerId, source.getControllerId()));
}
}

View file

@ -1,3 +1,4 @@
/*
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
@ -38,6 +39,7 @@ import mage.game.Game;
*
* @author nantuko
*/
@FunctionalInterface
public interface AdjustingSourceCosts {
void adjustCosts(Ability ability, Game game);
}

View file

@ -38,6 +38,7 @@ import mage.game.Game;
*
* @author LevelX2
*/
@FunctionalInterface
public interface AlternateManaPaymentAbility {
/**
* Adds the special action to the state, that allows the user to do the alternate mana payment

View file

@ -36,6 +36,8 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import java.util.Objects;
/**
*
* @author jeffwadsworth
@ -67,7 +69,7 @@ public class CantBeRegeneratedSourceEffect extends ContinuousRuleModifyingEffect
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return source.getSourceId() == event.getTargetId();
return Objects.equals(source.getSourceId(), event.getTargetId());
}
@Override

View file

@ -19,6 +19,8 @@ import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.players.Player;
import java.util.Objects;
/**
*
* @author jeffwadsworth
@ -112,7 +114,7 @@ class EpicReplacementEffect extends ContinuousRuleModifyingEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (source.getControllerId() == event.getPlayerId()) {
if (Objects.equals(source.getControllerId(), event.getPlayerId())) {
MageObject object = game.getObject(event.getSourceId());
if (object != null) {
return true;

View file

@ -32,6 +32,7 @@ import java.io.Serializable;
/**
* @author noxx
*/
@FunctionalInterface
public interface Builder<T> extends Serializable {
T build(Object... options);

View file

@ -78,4 +78,9 @@ public abstract class FilterImpl<E> implements Filter<E> {
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return message;
}
}

View file

@ -32,5 +32,6 @@ package mage.filter.predicate;
* @author North
* @param <T>
*/
@FunctionalInterface
public interface ObjectPlayerPredicate<T extends ObjectPlayer> extends Predicate<T> {
}

View file

@ -32,5 +32,6 @@ package mage.filter.predicate;
* @author North
* @param <T>
*/
@FunctionalInterface
public interface ObjectSourcePlayerPredicate<T extends ObjectSourcePlayer> extends ObjectPlayerPredicate<T> {
}

View file

@ -36,6 +36,7 @@ import mage.game.Game;
* @author North
* @param <T>
*/
@FunctionalInterface
public interface Predicate <T> extends Serializable {
/**
* Returns the result of applying this predicate to {@code input}. This method is <i>generally

View file

@ -29,20 +29,9 @@ package mage.game;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Stack;
import java.util.UUID;
import mage.MageException;
import mage.MageObject;
import mage.abilities.Ability;
@ -2010,7 +1999,7 @@ public abstract class GameImpl implements Game, Serializable {
}
}
for (Permanent permanent : worldEnchantment) {
if (newestPermanent != permanent) {
if (!Objects.equals(newestPermanent, permanent)) {
movePermanentToGraveyardWithInfo(permanent);
somethingHappened = true;
}

View file

@ -28,18 +28,8 @@
package mage.game;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import mage.MageObject;
import mage.abilities.Abilities;
import mage.abilities.Ability;
@ -360,7 +350,7 @@ public class GameState implements Serializable, Copyable<GameState> {
for (Player player : players.values()) {
sb.append("player").append(player.isPassed()).append(player.getLife()).append("hand");
if (playerId == player.getId()) {
if (Objects.equals(playerId, player.getId())) {
sb.append(player.getHand().getValue(game));
} else {
sb.append(player.getHand().size());

View file

@ -64,6 +64,7 @@ public class Table implements Serializable {
private Tournament tournament;
private TableRecorder recorder;
@FunctionalInterface
public interface TableRecorder {
void record(Table table);
}

View file

@ -184,9 +184,9 @@ public class ZonesHandler {
ZoneChangeInfo subInfo = itr.next();
if (!maybeRemoveFromSourceZone(subInfo, game)) {
itr.remove();
} else if (subInfo.event.getTargetId() == meld.getTopHalfCard().getId()) {
} else if (Objects.equals(subInfo.event.getTargetId(), meld.getTopHalfCard().getId())) {
meld.setTopLastZoneChangeCounter(meld.getTopHalfCard().getZoneChangeCounter(game));
} else if (subInfo.event.getTargetId() == meld.getBottomHalfCard().getId()) {
} else if (Objects.equals(subInfo.event.getTargetId(), meld.getBottomHalfCard().getId())) {
meld.setBottomLastZoneChangeCounter(meld.getBottomHalfCard().getZoneChangeCounter(game));
}
}

View file

@ -29,6 +29,7 @@ package mage.game.draft;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import mage.cards.Card;
import mage.cards.repository.CardCriteria;
@ -146,7 +147,7 @@ public abstract class DraftCube {
}
for (int i = leftCubeCards.size() - 1; i >= 0; i--) {
if (leftCubeCards.get(i) == cardId) {
if (Objects.equals(leftCubeCards.get(i), cardId)) {
leftCubeCards.remove(i);
return;
}

View file

@ -28,13 +28,8 @@
package mage.game.draft;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.game.draft.DraftOptions.TimingOption;
@ -197,7 +192,7 @@ public abstract class DraftImpl implements Draft {
while (true) {
List<Card> nextBooster = next.booster;
next.setBooster(currentBooster);
if (nextId == startId) {
if (Objects.equals(nextId, startId)) {
break;
}
currentBooster = nextBooster;
@ -218,7 +213,7 @@ public abstract class DraftImpl implements Draft {
while (true) {
List<Card> prevBooster = prev.booster;
prev.setBooster(currentBooster);
if (prevId == startId) {
if (Objects.equals(prevId, startId)) {
break;
}
currentBooster = prevBooster;

View file

@ -28,6 +28,7 @@
package mage.game.draft;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import mage.cards.Card;
import mage.cards.ExpansionSet;
@ -69,7 +70,7 @@ public class RichManBoosterDraft extends DraftImpl {
while (true) {
List<Card> nextBooster = sets.get(cardNum % sets.size()).createBooster();
next.setBooster(nextBooster);
if (nextId == startId) {
if (Objects.equals(nextId, startId)) {
break;
}
nextId = table.getNext();

View file

@ -27,10 +27,8 @@
*/
package mage.game.draft;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.game.draft.DraftCube.CardIdentity;
@ -90,7 +88,7 @@ public class RichManCubeBoosterDraft extends DraftImpl {
List<Card> nextBooster = draftCube.createBooster();
next.setBooster(nextBooster);
if (nextId == startId) {
if (Objects.equals(nextId, startId)) {
break;
}
nextId = table.getNext();

View file

@ -34,6 +34,7 @@ import java.io.Serializable;
*
* @author BetaSteward_at_googlemail.com
*/
@FunctionalInterface
public interface Listener<E extends ExternalEvent> extends Serializable {
void event(E event);
}

View file

@ -27,14 +27,8 @@
*/
package mage.game.permanent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import mage.MageObject;
import mage.MageObjectReference;
import mage.ObjectColor;
@ -667,7 +661,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public void attachTo(UUID permanentId, Game game) {
if (this.attachedTo != null && this.attachedTo != permanentId) {
if (this.attachedTo != null && !Objects.equals(this.attachedTo, permanentId)) {
Permanent attachment = game.getPermanent(this.attachedTo);
if (attachment != null) {
attachment.removeAttachment(this.objectId, game);

View file

@ -1291,7 +1291,7 @@ public abstract class PlayerImpl implements Player, Serializable {
if (zone != Zone.BATTLEFIELD && game.getContinuousEffects().asThough(object.getId(), AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, this.getId(), game)) {
for (Ability ability : object.getAbilities()) {
if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) {
if (ability.getManaCosts().isEmpty() && ability.getCosts().isEmpty() && ability instanceof SpellAbility && !(ability.getSourceId() == getCastSourceIdWithAlternateMana())) {
if (ability.getManaCosts().isEmpty() && ability.getCosts().isEmpty() && ability instanceof SpellAbility && !(Objects.equals(ability.getSourceId(), getCastSourceIdWithAlternateMana()))) {
continue; // You can't play spells that have no costs, unless you can play them without paying their mana costs
}
ability.setControllerId(this.getId());
@ -1679,7 +1679,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public boolean isLifeTotalCanChange() {
return canGainLife | canLoseLife;
return canGainLife || canLoseLife;
}
@Override
@ -3247,7 +3247,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// move cards to graveyard in order the owner decides
if (!cards.isEmpty()) {
Player choosingPlayer = this;
if (ownerId != this.getId()) {
if (!Objects.equals(ownerId, this.getId())) {
choosingPlayer = game.getPlayer(ownerId);
}
if (choosingPlayer == null) {

View file

@ -27,6 +27,8 @@
*/
package mage.util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

View file

@ -32,7 +32,7 @@ package mage.util;
*
* @author BetaSteward_at_googlemail.com
*/
@FunctionalInterface
public interface Copyable<T> {
T copy();
}

View file

@ -30,6 +30,7 @@ package mage.util.functions;
/**
* @author nantuko
*/
@FunctionalInterface
public interface Function<X, Y> {
X apply(Y in);
}

View file

@ -1,6 +1,7 @@
package mage.watchers.common;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import mage.constants.WatcherScope;
@ -32,7 +33,7 @@ public class CastFromHandWatcher extends Watcher {
* reset if the game comes to a new step
*/
if (step != null && game.getTurn().getStep() != step) {
if (step != null && !Objects.equals(game.getTurn().getStep(), step)) {
spellsCastFromHand.clear();
step = null;
}