From 449ee4a476b27a3daec22d22c8dcf29ce46c5d35 Mon Sep 17 00:00:00 2001 From: jendave Date: Tue, 3 Jan 2012 17:42:47 +0000 Subject: [PATCH] checkstyle --- src/main/java/forge/AllZone.java | 5 ++ src/main/java/forge/AllZoneUtil.java | 2 +- src/main/java/forge/Card.java | 39 ++++++--- .../forge/card/replacement/ReplaceDamage.java | 42 +++++++--- .../forge/card/replacement/ReplaceDraw.java | 28 ++++++- .../card/replacement/ReplaceGainLife.java | 25 +++++- .../card/replacement/ReplacementEffect.java | 80 +++++++++++++++---- .../card/replacement/ReplacementHandler.java | 58 +++++++++----- .../forge/card/spellability/SpellAbility.java | 28 +++++++ src/main/java/forge/card/trigger/Trigger.java | 1 - 10 files changed, 243 insertions(+), 65 deletions(-) diff --git a/src/main/java/forge/AllZone.java b/src/main/java/forge/AllZone.java index 9b764804f4d..958c1c4edb1 100644 --- a/src/main/java/forge/AllZone.java +++ b/src/main/java/forge/AllZone.java @@ -455,6 +455,11 @@ public final class AllZone { return Singletons.getModel().getGameState().getTriggerHandler(); } + /** + * Gets the replacement handler. + * + * @return the replacement handler + */ public static ReplacementHandler getReplacementHandler() { return Singletons.getModel().getGameState().getReplacementHandler(); } diff --git a/src/main/java/forge/AllZoneUtil.java b/src/main/java/forge/AllZoneUtil.java index ded8f311729..79bcd636724 100644 --- a/src/main/java/forge/AllZoneUtil.java +++ b/src/main/java/forge/AllZoneUtil.java @@ -397,7 +397,7 @@ public abstract class AllZoneUtil { return false; } - + /** *

* matchesValid. diff --git a/src/main/java/forge/Card.java b/src/main/java/forge/Card.java index 2faf5fecc42..1774413473f 100644 --- a/src/main/java/forge/Card.java +++ b/src/main/java/forge/Card.java @@ -453,7 +453,7 @@ public class Card extends GameEntity implements Comparable { // hacky code below, used to limit the number of times an ability // can be used per turn like Vampire Bats - // should be put in SpellAbility, but it is put here for conveniance + // should be put in SpellAbility, but it is put here for convenience // this is make public just to make things easy // this code presumes that each card only has one ability that can be // used a limited number of times per turn @@ -2569,8 +2569,8 @@ public class Card extends GameEntity implements Comparable { } //Replacement effects - for (final ReplacementEffect RE : this.getCharacteristics().getReplacementEffects()) { - sb.append(RE.toString() + "\r\n"); + for (final ReplacementEffect replacementEffect : this.getCharacteristics().getReplacementEffects()) { + sb.append(replacementEffect.toString() + "\r\n"); } // static abilities @@ -2619,7 +2619,7 @@ public class Card extends GameEntity implements Comparable { sb.insert(sb.indexOf(".) ") + 3, "\r\n"); } - // replace tripple line feeds with double line feeds + // replace triple line feeds with double line feeds int start; final String s = "\r\n\r\n\r\n"; while (sb.toString().contains(s)) { @@ -2670,8 +2670,8 @@ public class Card extends GameEntity implements Comparable { } //Replacement effects - for (final ReplacementEffect RE : this.getCharacteristics().getReplacementEffects()) { - sb.append(RE.toString() + "\r\n"); + for (final ReplacementEffect replacementEffect : this.getCharacteristics().getReplacementEffects()) { + sb.append(replacementEffect.toString() + "\r\n"); } // static abilities @@ -8673,21 +8673,36 @@ public class Card extends GameEntity implements Comparable { return true; } + /** + * Gets the replacement effects. + * + * @return the replacement effects + */ public ArrayList getReplacementEffects() { return this.getCharacteristics().getReplacementEffects(); } + /** + * Sets the replacement effects. + * + * @param res the new replacement effects + */ public void setReplacementEffects(ArrayList res) { this.getCharacteristics().getReplacementEffects().clear(); - for (ReplacementEffect RE : res) { - addReplacementEffect(RE); + for (ReplacementEffect replacementEffect : res) { + addReplacementEffect(replacementEffect); } } - public void addReplacementEffect(ReplacementEffect RE) { - ReplacementEffect RECopy = RE.getCopy(); - RECopy.setHostCard(this); - this.getCharacteristics().getReplacementEffects().add(RECopy); + /** + * Adds the replacement effect. + * + * @param replacementEffect the rE + */ + public void addReplacementEffect(ReplacementEffect replacementEffect) { + ReplacementEffect replacementEffectCopy = replacementEffect.getCopy(); + replacementEffectCopy.setHostCard(this); + this.getCharacteristics().getReplacementEffects().add(replacementEffectCopy); } } // end Card class diff --git a/src/main/java/forge/card/replacement/ReplaceDamage.java b/src/main/java/forge/card/replacement/ReplaceDamage.java index e987d521b73..7ab84fda493 100644 --- a/src/main/java/forge/card/replacement/ReplaceDamage.java +++ b/src/main/java/forge/card/replacement/ReplaceDamage.java @@ -1,3 +1,20 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Nate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package forge.card.replacement; import java.util.HashMap; @@ -15,8 +32,9 @@ public class ReplaceDamage extends ReplacementEffect { /** * TODO: Write javadoc for Constructor. - * @param map - * @param host + * + * @param map the map + * @param host the host */ public ReplaceDamage(HashMap map, Card host) { super(map, host); @@ -30,33 +48,33 @@ public class ReplaceDamage extends ReplacementEffect { if (!runParams.get("Event").equals("DamageDone")) { return false; } - if (mapParams.containsKey("ValidSource")) { - if (!AllZoneUtil.matchesValid(runParams.get("DamageSource"), mapParams.get("ValidSource").split(","), hostCard)) { + if (getMapParams().containsKey("ValidSource")) { + if (!AllZoneUtil.matchesValid(runParams.get("DamageSource"), getMapParams().get("ValidSource").split(","), getHostCard())) { return false; } } - if (mapParams.containsKey("ValidTarget")) { - if (!AllZoneUtil.matchesValid(runParams.get("Affected"), mapParams.get("ValidTarget").split(","), hostCard)) { + if (getMapParams().containsKey("ValidTarget")) { + if (!AllZoneUtil.matchesValid(runParams.get("Affected"), getMapParams().get("ValidTarget").split(","), getHostCard())) { return false; } } - if (mapParams.containsKey("DamageAmount")) { - String full = mapParams.get("DamageAmount"); + if (getMapParams().containsKey("DamageAmount")) { + String full = getMapParams().get("DamageAmount"); String operator = full.substring(0, 2); String operand = full.substring(2); int intoperand = 0; try { intoperand = Integer.parseInt(operand); } catch (NumberFormatException e) { - intoperand = CardFactoryUtil.xCount(hostCard, hostCard.getSVar(operand)); + intoperand = CardFactoryUtil.xCount(getHostCard(), getHostCard().getSVar(operand)); } if (!AllZoneUtil.compare((Integer) runParams.get("DamageAmount"), operator, intoperand)) { return false; } } - if (mapParams.containsKey("IsCombat")) { - if (mapParams.get("IsCombat").equals("True")) { + if (getMapParams().containsKey("IsCombat")) { + if (getMapParams().get("IsCombat").equals("True")) { if (!((Boolean) runParams.get("IsCombat"))) { return false; } @@ -76,7 +94,7 @@ public class ReplaceDamage extends ReplacementEffect { */ @Override public ReplacementEffect getCopy() { - return new ReplaceDamage(this.mapParams, this.hostCard); + return new ReplaceDamage(this.getMapParams(), this.getHostCard()); } /* (non-Javadoc) diff --git a/src/main/java/forge/card/replacement/ReplaceDraw.java b/src/main/java/forge/card/replacement/ReplaceDraw.java index 9a8b5ea9b6e..62a08b72140 100644 --- a/src/main/java/forge/card/replacement/ReplaceDraw.java +++ b/src/main/java/forge/card/replacement/ReplaceDraw.java @@ -1,3 +1,20 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Nate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package forge.card.replacement; import java.util.HashMap; @@ -11,6 +28,12 @@ import forge.Card; */ public class ReplaceDraw extends ReplacementEffect { + /** + * Instantiates a new replace draw. + * + * @param params the params + * @param host the host + */ public ReplaceDraw(final HashMap params, final Card host) { super(params, host); } @@ -32,9 +55,12 @@ public class ReplaceDraw extends ReplacementEffect { return true; } + /* (non-Javadoc) + * @see forge.card.replacement.ReplacementEffect#getCopy() + */ @Override public ReplacementEffect getCopy() { - return new ReplaceDraw(this.getMapParams(), hostCard); + return new ReplaceDraw(this.getMapParams(), getHostCard()); } } diff --git a/src/main/java/forge/card/replacement/ReplaceGainLife.java b/src/main/java/forge/card/replacement/ReplaceGainLife.java index 6bf5ab51cab..fac62d34895 100644 --- a/src/main/java/forge/card/replacement/ReplaceGainLife.java +++ b/src/main/java/forge/card/replacement/ReplaceGainLife.java @@ -1,3 +1,20 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Nate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package forge.card.replacement; import java.util.HashMap; @@ -12,6 +29,12 @@ import forge.card.spellability.SpellAbility; */ public class ReplaceGainLife extends ReplacementEffect { + /** + * Instantiates a new replace gain life. + * + * @param map the map + * @param host the host + */ public ReplaceGainLife(HashMap map, Card host) { super(map, host); } @@ -38,7 +61,7 @@ public class ReplaceGainLife extends ReplacementEffect { */ @Override public ReplacementEffect getCopy() { - return new ReplaceGainLife(this.getMapParams(), hostCard); + return new ReplaceGainLife(this.getMapParams(), getHostCard()); } /* (non-Javadoc) diff --git a/src/main/java/forge/card/replacement/ReplacementEffect.java b/src/main/java/forge/card/replacement/ReplacementEffect.java index c771b5eb473..f4548750867 100644 --- a/src/main/java/forge/card/replacement/ReplacementEffect.java +++ b/src/main/java/forge/card/replacement/ReplacementEffect.java @@ -1,3 +1,20 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Nate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package forge.card.replacement; import java.util.HashMap; @@ -6,7 +23,6 @@ import forge.AllZoneUtil; import forge.Card; import forge.CardList; import forge.CardUtil; -import forge.Player; import forge.Constant.Zone; import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil; @@ -17,9 +33,13 @@ import forge.card.spellability.SpellAbility; * */ public abstract class ReplacementEffect { - protected boolean hasRun = false; + + /** The has run. */ + private boolean hasRun = false; /** + * Checks for run. + * * @return the hasRun */ public final boolean hasRun() { @@ -27,14 +47,16 @@ public abstract class ReplacementEffect { } /** - * @param hasRun0 the hasRun to set + * Sets the checks for run. + * + * @param hasRun the hasRun to set */ - public final void setHasRun(boolean hasRun0) { - this.hasRun = hasRun0; + public final void setHasRun(boolean hasRun) { + this.hasRun = hasRun; } /** The map params, denoting what to replace. */ - protected HashMap mapParams = new HashMap(); + private HashMap mapParams = new HashMap(); /** *

@@ -50,15 +72,15 @@ public abstract class ReplacementEffect { /** * Sets the map params. * - * @param mapParams0 + * @param mapParams * the mapParams to set */ - public final void setMapParams(final HashMap mapParams0) { - this.mapParams = mapParams0; + public final void setMapParams(final HashMap mapParams) { + this.mapParams = mapParams; } /** The host card. */ - protected Card hostCard; + private Card hostCard; /** *

@@ -83,11 +105,20 @@ public abstract class ReplacementEffect { this.hostCard = c; } + /** + * Can replace. + * + * @param runParams the run params + * @return true, if successful + */ public abstract boolean canReplace(final HashMap runParams); + /** + * @return a String + */ public String toString() { - if (mapParams.containsKey("Description")) { - return mapParams.get("Description"); + if (getMapParams().containsKey("Description")) { + return getMapParams().get("Description"); } else { return ""; @@ -289,14 +320,31 @@ public abstract class ReplacementEffect { return true; } + /** + * Gets the copy. + * + * @return the copy + */ public abstract ReplacementEffect getCopy(); - public void setReplacingObjects(HashMap runParams, SpellAbility sa) { - //Should be overriden by replacers that need it. + /** + * Sets the replacing objects. + * + * @param runParams the run params + * @param spellAbility the SpellAbility + */ + public void setReplacingObjects(HashMap runParams, SpellAbility spellAbility) { + //Should be overridden by replacers that need it. } + /** + * Instantiates a new replacement effect. + * + * @param map the map + * @param host the host + */ public ReplacementEffect(final HashMap map, final Card host) { - this.mapParams = map; - this.hostCard = host; + this.setMapParams(map); + this.setHostCard(host); } } diff --git a/src/main/java/forge/card/replacement/ReplacementHandler.java b/src/main/java/forge/card/replacement/ReplacementHandler.java index b8276973b81..c65d739118c 100644 --- a/src/main/java/forge/card/replacement/ReplacementHandler.java +++ b/src/main/java/forge/card/replacement/ReplacementHandler.java @@ -1,9 +1,25 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Nate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package forge.card.replacement; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Stack; import forge.AllZone; import forge.Card; @@ -35,7 +51,7 @@ public class ReplacementHandler { Player decider = null; //Figure out who decides which of multiple replacements to apply - //as well as wether or not to apply optional replacements. + //as well as whether or not to apply optional replacements. if (affected instanceof Player) { decider = (Player) affected; } else { @@ -43,19 +59,19 @@ public class ReplacementHandler { } //Round up Non-static replacement effects ("Until EOT," or "The next time you would..." etc) - for (ReplacementEffect RE : tmpEffects) { - if (!RE.hasRun() && RE.canReplace(runParams)) { - possibleReplacers.add(RE); + for (ReplacementEffect replacementEffect : tmpEffects) { + if (!replacementEffect.hasRun() && replacementEffect.canReplace(runParams)) { + possibleReplacers.add(replacementEffect); } } //Round up Static replacement effects for (Player p : AllZone.getPlayersInGame()) { for (Card crd : p.getCardsIn(Zone.Battlefield)) { - for (ReplacementEffect RE : crd.getReplacementEffects()) { - if (RE.requirementsCheck()) { - if (!RE.hasRun() && RE.canReplace(runParams)) { - possibleReplacers.add(RE); + for (ReplacementEffect replacementEffect : crd.getReplacementEffects()) { + if (replacementEffect.requirementsCheck()) { + if (!replacementEffect.hasRun() && replacementEffect.canReplace(runParams)) { + possibleReplacers.add(replacementEffect); } } } @@ -94,7 +110,7 @@ public class ReplacementHandler { return false; } } else { - //AI-logic for deciding wether or not to apply the optional replacement effect happens here. + //AI-logic for deciding whether or not to apply the optional replacement effect happens here. } } executeReplacement(runParams, chosenRE); @@ -108,37 +124,37 @@ public class ReplacementHandler { /** * * Runs a single replacement effect. - * @param RE the replacment effect to run + * @param replacementEffect the replacement effect to run */ - private void executeReplacement(HashMap runParams, ReplacementEffect RE) { + private void executeReplacement(HashMap runParams, ReplacementEffect replacementEffect) { - HashMap mapParams = RE.getMapParams(); - RE.setHasRun(true); + HashMap mapParams = replacementEffect.getMapParams(); + replacementEffect.setHasRun(true); if (mapParams.containsKey("Prevent")) { if (mapParams.get("Prevent").equals("True")) { - RE.setHasRun(false); + replacementEffect.setHasRun(false); return; //Nothing should replace the event. } } String effectSVar = mapParams.get("ReplaceWith"); - String effectAbString = RE.getHostCard().getSVar(effectSVar); + String effectAbString = replacementEffect.getHostCard().getSVar(effectSVar); - AbilityFactory AF = new AbilityFactory(); + AbilityFactory abilityFactory = new AbilityFactory(); - SpellAbility effectSA = AF.getAbility(effectAbString, RE.getHostCard()); + SpellAbility effectSA = abilityFactory.getAbility(effectAbString, replacementEffect.getHostCard()); - RE.setReplacingObjects(runParams, effectSA); + replacementEffect.setReplacingObjects(runParams, effectSA); - if (RE.getHostCard().getController().isHuman()) { + if (replacementEffect.getHostCard().getController().isHuman()) { AllZone.getGameAction().playSpellAbilityNoStack(effectSA, false); } else { ComputerUtil.playNoStack(effectSA); } - RE.setHasRun(false); + replacementEffect.setHasRun(false); } /** diff --git a/src/main/java/forge/card/spellability/SpellAbility.java b/src/main/java/forge/card/spellability/SpellAbility.java index f60b0109bd3..914d1f62782 100644 --- a/src/main/java/forge/card/spellability/SpellAbility.java +++ b/src/main/java/forge/card/spellability/SpellAbility.java @@ -964,23 +964,51 @@ public abstract class SpellAbility { this.triggeringObjects = new HashMap(); } + /** + * Gets the replacing objects. + * + * @return the replacing objects + */ public HashMap getReplacingObjects() { return this.replacingObjects; } + /** + * Sets the all replacing objects. + * + * @param replacedObjects the replaced objects + */ public void setAllReplacingObjects(final HashMap replacedObjects) { this.replacingObjects = replacedObjects; } + /** + * Sets the replacing object. + * + * @param type the type + * @param o the o + */ public void setReplacingObject(final String type, final Object o) { this.replacingObjects.put(type, o); } + /** + * Gets the replacing object. + * + * @param type the type + * @return the replacing object + */ public Object getReplacingObject(final String type) { Object res = this.replacingObjects.get(type); return res; } + /** + * Checks for replacing object. + * + * @param type the type + * @return true, if successful + */ public boolean hasReplacingObject(final String type) { return this.replacingObjects.containsKey(type); } diff --git a/src/main/java/forge/card/trigger/Trigger.java b/src/main/java/forge/card/trigger/Trigger.java index 77dc2aa3a86..6180d4e61d2 100644 --- a/src/main/java/forge/card/trigger/Trigger.java +++ b/src/main/java/forge/card/trigger/Trigger.java @@ -28,7 +28,6 @@ import forge.Card; import forge.CardList; import forge.CardUtil; import forge.Constant.Zone; -import forge.Player; import forge.PlayerZone; import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil;