fix hashcodes

This commit is contained in:
jendave
2011-11-03 17:08:26 +00:00
parent c380e6dd37
commit e2d2d3ce36
9 changed files with 195 additions and 129 deletions

View File

@@ -2208,107 +2208,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*/ */
public String getAbilityText() { public String getAbilityText() {
if (isInstant() || isSorcery()) { if (isInstant() || isSorcery()) {
String s = getSpellText(); StringBuilder sb = abilityTextInstantSorcery();
StringBuilder sb = new StringBuilder();
// Give spellText line breaks for easier reading
sb.append(s.replaceAll("\\\\r\\\\n", "\r\n"));
// NOTE:
if (sb.toString().contains(" (NOTE: ")) {
sb.insert(sb.indexOf("(NOTE: "), "\r\n");
}
if (sb.toString().contains("(NOTE: ") && sb.toString().endsWith(".)") && !sb.toString().endsWith("\r\n")) {
sb.append("\r\n");
}
// Add SpellAbilities
SpellAbility[] sa = getSpellAbility();
for (int i = 0; i < sa.length; i++) {
sb.append(sa[i].toString() + "\r\n");
}
// Add Keywords
ArrayList<String> kw = getKeyword();
// Triggered abilities
for (Trigger trig : getCharacteristics().getTriggers()) {
if (!trig.isSecondary()) {
sb.append(trig.toString() + "\r\n");
}
}
// static abilities
for (StaticAbility stAb : getCharacteristics().getStaticAbilities()) {
String stAbD = stAb.toString();
if (!stAbD.equals("")) {
sb.append(stAbD + "\r\n");
}
}
// Ripple + Dredge + Madness + CARDNAME is {color} + Recover.
for (int i = 0; i < kw.size(); i++) {
if ((kw.get(i).startsWith("Ripple") && !sb.toString().contains("Ripple"))
|| (kw.get(i).startsWith("Dredge") && !sb.toString().contains("Dredge"))
|| (kw.get(i).startsWith("Madness") && !sb.toString().contains("Madness"))
|| (kw.get(i).startsWith("CARDNAME is ") && !sb.toString().contains("CARDNAME is "))
|| (kw.get(i).startsWith("Recover") && !sb.toString().contains("Recover"))) {
sb.append(kw.get(i).replace(":", " ")).append("\r\n");
}
}
// Changeling + CARDNAME can't be countered. + Cascade + Multikicker
for (int i = 0; i < kw.size(); i++) {
if ((kw.get(i).contains("CARDNAME can't be countered.") && !sb.toString().contains(
"CARDNAME can't be countered."))
|| (kw.get(i).contains("Cascade") && !sb.toString().contains("Cascade"))
|| (kw.get(i).contains("Multikicker") && !sb.toString().contains("Multikicker"))) {
sb.append(kw.get(i)).append("\r\n");
}
}
// Storm
if (hasKeyword("Storm") && !sb.toString().contains("Storm (When you ")) {
if (sb.toString().endsWith("\r\n\r\n")) {
sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
}
sb.append("Storm (When you cast this spell, copy it for each spell cast before it this turn.");
if (sb.toString().contains("Target") || sb.toString().contains("target")) {
sb.append(" You may choose new targets for the copies.");
}
sb.append(")\r\n");
}
// Replicate
for (String keyw : kw) {
if (keyw.contains("Replicate") && !sb.toString().contains("you paid its replicate cost.")) {
if (sb.toString().endsWith("\r\n\r\n")) {
sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
}
sb.append(keyw);
sb.append(" (When you cast this spell, copy it for each time you paid its replicate cost.");
if (sb.toString().contains("Target") || sb.toString().contains("target")) {
sb.append(" You may choose new targets for the copies.");
}
sb.append(")\r\n");
}
}
for (String keyw : kw) {
if (keyw.startsWith("Haunt")) {
if (sb.toString().endsWith("\r\n\r\n")) {
sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
}
sb.append("Haunt (");
if (isCreature()) {
sb.append("When this creature dies, exile it haunting target creature.");
} else {
sb.append("When this spell card is put into a graveyard after resolving, ");
sb.append("exile it haunting target creature.");
}
sb.append(")\r\n");
}
}
if (haunting != null) { if (haunting != null) {
sb.append("Haunting: ").append(haunting); sb.append("Haunting: ").append(haunting);
@@ -2452,6 +2352,115 @@ public class Card extends GameEntity implements Comparable<Card> {
return sb.toString().replaceAll("CARDNAME", getName()).trim(); return sb.toString().replaceAll("CARDNAME", getName()).trim();
} // getText() } // getText()
/**
* TODO: Write javadoc for this method.
* @return
*/
private StringBuilder abilityTextInstantSorcery() {
String s = getSpellText();
StringBuilder sb = new StringBuilder();
// Give spellText line breaks for easier reading
sb.append(s.replaceAll("\\\\r\\\\n", "\r\n"));
// NOTE:
if (sb.toString().contains(" (NOTE: ")) {
sb.insert(sb.indexOf("(NOTE: "), "\r\n");
}
if (sb.toString().contains("(NOTE: ") && sb.toString().endsWith(".)") && !sb.toString().endsWith("\r\n")) {
sb.append("\r\n");
}
// Add SpellAbilities
SpellAbility[] sa = getSpellAbility();
for (int i = 0; i < sa.length; i++) {
sb.append(sa[i].toString() + "\r\n");
}
// Add Keywords
ArrayList<String> kw = getKeyword();
// Triggered abilities
for (Trigger trig : getCharacteristics().getTriggers()) {
if (!trig.isSecondary()) {
sb.append(trig.toString() + "\r\n");
}
}
// static abilities
for (StaticAbility stAb : getCharacteristics().getStaticAbilities()) {
String stAbD = stAb.toString();
if (!stAbD.equals("")) {
sb.append(stAbD + "\r\n");
}
}
// Ripple + Dredge + Madness + CARDNAME is {color} + Recover.
for (int i = 0; i < kw.size(); i++) {
if ((kw.get(i).startsWith("Ripple") && !sb.toString().contains("Ripple"))
|| (kw.get(i).startsWith("Dredge") && !sb.toString().contains("Dredge"))
|| (kw.get(i).startsWith("Madness") && !sb.toString().contains("Madness"))
|| (kw.get(i).startsWith("CARDNAME is ") && !sb.toString().contains("CARDNAME is "))
|| (kw.get(i).startsWith("Recover") && !sb.toString().contains("Recover"))) {
sb.append(kw.get(i).replace(":", " ")).append("\r\n");
}
}
// Changeling + CARDNAME can't be countered. + Cascade + Multikicker
for (int i = 0; i < kw.size(); i++) {
if ((kw.get(i).contains("CARDNAME can't be countered.") && !sb.toString().contains(
"CARDNAME can't be countered."))
|| (kw.get(i).contains("Cascade") && !sb.toString().contains("Cascade"))
|| (kw.get(i).contains("Multikicker") && !sb.toString().contains("Multikicker"))) {
sb.append(kw.get(i)).append("\r\n");
}
}
// Storm
if (hasKeyword("Storm") && !sb.toString().contains("Storm (When you ")) {
if (sb.toString().endsWith("\r\n\r\n")) {
sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
}
sb.append("Storm (When you cast this spell, copy it for each spell cast before it this turn.");
if (sb.toString().contains("Target") || sb.toString().contains("target")) {
sb.append(" You may choose new targets for the copies.");
}
sb.append(")\r\n");
}
// Replicate
for (String keyw : kw) {
if (keyw.contains("Replicate") && !sb.toString().contains("you paid its replicate cost.")) {
if (sb.toString().endsWith("\r\n\r\n")) {
sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
}
sb.append(keyw);
sb.append(" (When you cast this spell, copy it for each time you paid its replicate cost.");
if (sb.toString().contains("Target") || sb.toString().contains("target")) {
sb.append(" You may choose new targets for the copies.");
}
sb.append(")\r\n");
}
}
for (String keyw : kw) {
if (keyw.startsWith("Haunt")) {
if (sb.toString().endsWith("\r\n\r\n")) {
sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
}
sb.append("Haunt (");
if (isCreature()) {
sb.append("When this creature dies, exile it haunting target creature.");
} else {
sb.append("When this spell card is put into a graveyard after resolving, ");
sb.append("exile it haunting target creature.");
}
sb.append(")\r\n");
}
}
return sb;
}
/** /**
* <p> * <p>
* Getter for the field <code>manaAbility</code>. * Getter for the field <code>manaAbility</code>.

View File

@@ -212,6 +212,7 @@ public class CardList implements Iterable<Card> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public final boolean equals(final Object a) { public final boolean equals(final Object a) {
if (a instanceof CardList) { if (a instanceof CardList) {
CardList b = (CardList) a; CardList b = (CardList) a;
@@ -231,6 +232,11 @@ public class CardList implements Iterable<Card> {
} }
} }
@Override
public int hashCode() {
return (41 * (41 + list.size() + list.hashCode()));
}
// removes one copy of that card // removes one copy of that card
/** /**
* <p> * <p>

View File

@@ -2489,4 +2489,10 @@ public abstract class Player extends GameEntity {
return false; return false;
} }
} }
/** {@inheritDoc} */
@Override
public int hashCode() {
return (41 * (41 + getName().hashCode()));
}
} }

View File

@@ -115,12 +115,17 @@ public class SetInfo {
} else { } else {
return false; return false;
} }
}
/** {@inheritDoc} */
@Override
public int hashCode() {
return (41 * (41 + this.getCode().hashCode()));
} }
/** /**
* Gets the code. * Gets the code.
* *
* @return the code * @return the code
*/ */
public String getCode() { public String getCode() {
@@ -129,8 +134,9 @@ public class SetInfo {
/** /**
* Sets the code. * Sets the code.
* *
* @param code the code to set * @param code
* the code to set
*/ */
public void setCode(final String code) { public void setCode(final String code) {
this.code = code; // TODO: Add 0 to parameter's name. this.code = code; // TODO: Add 0 to parameter's name.
@@ -138,7 +144,7 @@ public class SetInfo {
/** /**
* Gets the rarity. * Gets the rarity.
* *
* @return the rarity * @return the rarity
*/ */
public String getRarity() { public String getRarity() {
@@ -147,8 +153,9 @@ public class SetInfo {
/** /**
* Sets the rarity. * Sets the rarity.
* *
* @param rarity the rarity to set * @param rarity
* the rarity to set
*/ */
public void setRarity(final String rarity) { public void setRarity(final String rarity) {
this.rarity = rarity; // TODO: Add 0 to parameter's name. this.rarity = rarity; // TODO: Add 0 to parameter's name.
@@ -156,7 +163,7 @@ public class SetInfo {
/** /**
* Gets the url. * Gets the url.
* *
* @return the url * @return the url
*/ */
public String getUrl() { public String getUrl() {
@@ -165,8 +172,9 @@ public class SetInfo {
/** /**
* Sets the url. * Sets the url.
* *
* @param url the url to set * @param url
* the url to set
*/ */
public void setUrl(final String url) { public void setUrl(final String url) {
this.url = url; // TODO: Add 0 to parameter's name. this.url = url; // TODO: Add 0 to parameter's name.
@@ -174,7 +182,7 @@ public class SetInfo {
/** /**
* Gets the pic count. * Gets the pic count.
* *
* @return the picCount * @return the picCount
*/ */
public int getPicCount() { public int getPicCount() {
@@ -183,8 +191,9 @@ public class SetInfo {
/** /**
* Sets the pic count. * Sets the pic count.
* *
* @param picCount the picCount to set * @param picCount
* the picCount to set
*/ */
public void setPicCount(final int picCount) { public void setPicCount(final int picCount) {
this.picCount = picCount; // TODO: Add 0 to parameter's name. this.picCount = picCount; // TODO: Add 0 to parameter's name.

View File

@@ -359,5 +359,11 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
return abm.toUnsuppressedString().equals(this.toUnsuppressedString()); return abm.toUnsuppressedString().equals(this.toUnsuppressedString());
} }
/** {@inheritDoc} */
@Override
public int hashCode() {
return (41 * (41 + this.getType().hashCode()));
}
} // end class Ability_Mana } // end class Ability_Mana

View File

@@ -135,7 +135,7 @@ public class AbilityTriggered extends Ability implements Command {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final boolean equals(final Object o) { public final boolean equals(final Object o) {
// TODO triggers affecting other // TODO triggers affecting other
// cards // cards
if (!(o instanceof AbilityTriggered)) { if (!(o instanceof AbilityTriggered)) {
return false; return false;
@@ -145,6 +145,12 @@ public class AbilityTriggered extends Ability implements Command {
&& tmp.todo.equals(this.todo) && Arrays.equals(tmp.restrictions, this.restrictions); && tmp.todo.equals(this.todo) && Arrays.equals(tmp.restrictions, this.restrictions);
} }
/** {@inheritDoc} */
@Override
public int hashCode() {
return (41 * (41 + this.getSourceCard().hashCode() + this.trigger.hashCode() + this.todo.hashCode() + this.restrictions.hashCode()));
}
/** /**
* <p> * <p>
* isBasic. * isBasic.

View File

@@ -150,4 +150,10 @@ public class SpellAbilityList {
} }
return this.toString().equals(o.toString()); return this.toString().equals(o.toString());
} }
/** {@inheritDoc} */
@Override
public int hashCode() {
return (41 * (41 + this.toString().hashCode()));
}
} }

View File

@@ -96,8 +96,9 @@ public abstract class Trigger {
/** /**
* Sets the map params. * Sets the map params.
* *
* @param mapParams the mapParams to set * @param mapParams
* the mapParams to set
*/ */
public final void setMapParams(final HashMap<String, String> mapParams) { public final void setMapParams(final HashMap<String, String> mapParams) {
this.mapParams = mapParams; // TODO: Add 0 to parameter's name. this.mapParams = mapParams; // TODO: Add 0 to parameter's name.
@@ -581,6 +582,12 @@ public abstract class Trigger {
return this.getId() == ((Trigger) o).getId(); return this.getId() == ((Trigger) o).getId();
} }
/** {@inheritDoc} */
@Override
public int hashCode() {
return 41 * (41 + this.getId());
}
/** /**
* <p> * <p>
* performTest. * performTest.
@@ -670,7 +677,7 @@ public abstract class Trigger {
/** /**
* Checks if is intrinsic. * Checks if is intrinsic.
* *
* @return the isIntrinsic * @return the isIntrinsic
*/ */
public boolean isIntrinsic() { public boolean isIntrinsic() {
@@ -679,8 +686,9 @@ public abstract class Trigger {
/** /**
* Sets the intrinsic. * Sets the intrinsic.
* *
* @param isIntrinsic the isIntrinsic to set * @param isIntrinsic
* the isIntrinsic to set
*/ */
public void setIntrinsic(final boolean isIntrinsic) { public void setIntrinsic(final boolean isIntrinsic) {
this.isIntrinsic = isIntrinsic; // TODO: Add 0 to parameter's name. this.isIntrinsic = isIntrinsic; // TODO: Add 0 to parameter's name.
@@ -688,7 +696,7 @@ public abstract class Trigger {
/** /**
* Gets the run params. * Gets the run params.
* *
* @return the runParams * @return the runParams
*/ */
public Map<String, Object> getRunParams() { public Map<String, Object> getRunParams() {
@@ -697,8 +705,9 @@ public abstract class Trigger {
/** /**
* Sets the run params. * Sets the run params.
* *
* @param runParams the runParams to set * @param runParams
* the runParams to set
*/ */
public void setRunParams(final Map<String, Object> runParams) { public void setRunParams(final Map<String, Object> runParams) {
this.runParams = runParams; // TODO: Add 0 to parameter's name. this.runParams = runParams; // TODO: Add 0 to parameter's name.
@@ -706,7 +715,7 @@ public abstract class Trigger {
/** /**
* Gets the overriding ability. * Gets the overriding ability.
* *
* @return the overridingAbility * @return the overridingAbility
*/ */
public SpellAbility getOverridingAbility() { public SpellAbility getOverridingAbility() {
@@ -715,8 +724,9 @@ public abstract class Trigger {
/** /**
* Sets the overriding ability. * Sets the overriding ability.
* *
* @param overridingAbility the overridingAbility to set * @param overridingAbility
* the overridingAbility to set
*/ */
public void setOverridingAbility(final SpellAbility overridingAbility) { public void setOverridingAbility(final SpellAbility overridingAbility) {
this.overridingAbility = overridingAbility; // TODO: Add 0 to this.overridingAbility = overridingAbility; // TODO: Add 0 to
@@ -725,7 +735,7 @@ public abstract class Trigger {
/** /**
* Gets the id. * Gets the id.
* *
* @return the id * @return the id
*/ */
public int getId() { public int getId() {
@@ -734,8 +744,9 @@ public abstract class Trigger {
/** /**
* Sets the id. * Sets the id.
* *
* @param id the id to set * @param id
* the id to set
*/ */
public void setId(final int id) { public void setId(final int id) {
this.id = id; // TODO: Add 0 to parameter's name. this.id = id; // TODO: Add 0 to parameter's name.

View File

@@ -51,7 +51,8 @@ public class FrozenCall<T> implements Thunk<T> {
*/ */
/** /**
* @return boolean * @return boolean
* @param obj Object * @param obj
* Object
*/ */
@Override @Override
public final boolean equals(final Object obj) { public final boolean equals(final Object obj) {
@@ -74,4 +75,10 @@ public class FrozenCall<T> implements Thunk<T> {
return true; return true;
} }
/** {@inheritDoc} */
@Override
public int hashCode() {
return 41 * (41 + this.args.hashCode());
}
} }