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() {
if (isInstant() || isSorcery()) {
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");
}
}
StringBuilder sb = abilityTextInstantSorcery();
if (haunting != null) {
sb.append("Haunting: ").append(haunting);
@@ -2452,6 +2352,115 @@ public class Card extends GameEntity implements Comparable<Card> {
return sb.toString().replaceAll("CARDNAME", getName()).trim();
} // 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>
* Getter for the field <code>manaAbility</code>.

View File

@@ -212,6 +212,7 @@ public class CardList implements Iterable<Card> {
}
/** {@inheritDoc} */
@Override
public final boolean equals(final Object a) {
if (a instanceof CardList) {
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
/**
* <p>

View File

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

View File

@@ -115,7 +115,12 @@ public class SetInfo {
} else {
return false;
}
}
/** {@inheritDoc} */
@Override
public int hashCode() {
return (41 * (41 + this.getCode().hashCode()));
}
/**
@@ -130,7 +135,8 @@ public class SetInfo {
/**
* Sets the code.
*
* @param code the code to set
* @param code
* the code to set
*/
public void setCode(final String code) {
this.code = code; // TODO: Add 0 to parameter's name.
@@ -148,7 +154,8 @@ public class SetInfo {
/**
* Sets the rarity.
*
* @param rarity the rarity to set
* @param rarity
* the rarity to set
*/
public void setRarity(final String rarity) {
this.rarity = rarity; // TODO: Add 0 to parameter's name.
@@ -166,7 +173,8 @@ public class SetInfo {
/**
* Sets the url.
*
* @param url the url to set
* @param url
* the url to set
*/
public void setUrl(final String url) {
this.url = url; // TODO: Add 0 to parameter's name.
@@ -184,7 +192,8 @@ public class SetInfo {
/**
* Sets the pic count.
*
* @param picCount the picCount to set
* @param picCount
* the picCount to set
*/
public void setPicCount(final int picCount) {
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());
}
/** {@inheritDoc} */
@Override
public int hashCode() {
return (41 * (41 + this.getType().hashCode()));
}
} // end class Ability_Mana

View File

@@ -135,7 +135,7 @@ public class AbilityTriggered extends Ability implements Command {
/** {@inheritDoc} */
@Override
public final boolean equals(final Object o) {
// TODO triggers affecting other
// TODO triggers affecting other
// cards
if (!(o instanceof AbilityTriggered)) {
return false;
@@ -145,6 +145,12 @@ public class AbilityTriggered extends Ability implements Command {
&& 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>
* isBasic.

View File

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

View File

@@ -97,7 +97,8 @@ public abstract class Trigger {
/**
* 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) {
this.mapParams = mapParams; // TODO: Add 0 to parameter's name.
@@ -581,6 +582,12 @@ public abstract class Trigger {
return this.getId() == ((Trigger) o).getId();
}
/** {@inheritDoc} */
@Override
public int hashCode() {
return 41 * (41 + this.getId());
}
/**
* <p>
* performTest.
@@ -680,7 +687,8 @@ public abstract class Trigger {
/**
* Sets the intrinsic.
*
* @param isIntrinsic the isIntrinsic to set
* @param isIntrinsic
* the isIntrinsic to set
*/
public void setIntrinsic(final boolean isIntrinsic) {
this.isIntrinsic = isIntrinsic; // TODO: Add 0 to parameter's name.
@@ -698,7 +706,8 @@ public abstract class Trigger {
/**
* Sets the run params.
*
* @param runParams the runParams to set
* @param runParams
* the runParams to set
*/
public void setRunParams(final Map<String, Object> runParams) {
this.runParams = runParams; // TODO: Add 0 to parameter's name.
@@ -716,7 +725,8 @@ public abstract class Trigger {
/**
* Sets the overriding ability.
*
* @param overridingAbility the overridingAbility to set
* @param overridingAbility
* the overridingAbility to set
*/
public void setOverridingAbility(final SpellAbility overridingAbility) {
this.overridingAbility = overridingAbility; // TODO: Add 0 to
@@ -735,7 +745,8 @@ public abstract class Trigger {
/**
* Sets the id.
*
* @param id the id to set
* @param id
* the id to set
*/
public void setId(final int id) {
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
* @param obj Object
* @param obj
* Object
*/
@Override
public final boolean equals(final Object obj) {
@@ -74,4 +75,10 @@ public class FrozenCall<T> implements Thunk<T> {
return true;
}
/** {@inheritDoc} */
@Override
public int hashCode() {
return 41 * (41 + this.args.hashCode());
}
}