aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/cards/Card.java
blob: 37cc13e697ffe0d94bf2ab111c60f8a8223e3261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package eu.equalparts.cardbase.cards;

import com.fasterxml.jackson.annotation.JsonAutoDetect;

import eu.equalparts.cardbase.comparator.SpecialFields.DirtyNumber;
import eu.equalparts.cardbase.comparator.SpecialFields.Rarity;

@JsonAutoDetect
public class Card {
	
	public String name;
	public String layout;
	public String manaCost;
	public Integer cmc;
	public String type;
	@Rarity
	public String rarity;
	public String text;
	public String flavor;
	public String artist;
	@DirtyNumber
	public String number;
	@DirtyNumber
	public String power;
	@DirtyNumber
	public String toughness;
	public Integer loyalty;
	public Integer multiverseid;
	public String imageName;
	public String watermark;

	// Not part of upstream JSON
	public String setCode;
	public String imageCode;
	
	@Override
	public Card clone() {
		Card clone = new Card();
		
		clone.name = this.name;
		clone.layout = this.layout;
		clone.manaCost = this.manaCost;
		clone.cmc = this.cmc;
		clone.type = this.type;
		clone.rarity = this.rarity;
		clone.text = this.text;
		clone.flavor = this.flavor;
		clone.artist = this.artist;
		clone.number = this.number;
		clone.power = this.power;
		clone.toughness = this.toughness;
		clone.loyalty = this.loyalty;
		clone.multiverseid = this.multiverseid;
		clone.imageName = this.imageName;
		clone.watermark = this.watermark;
		clone.setCode = this.setCode;
		clone.imageCode = this.imageCode;
		
		return clone;
	}

	public static int makeHash(String setCode, String number) {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((number == null) ? 0 : number.hashCode());
		result = prime * result + ((setCode == null) ? 0 : setCode.hashCode());
		return result;
	}
	
	@Override
	public int hashCode() {
		return makeHash(setCode, number);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Card other = (Card) obj;
		if (number == null) {
			if (other.number != null)
				return false;
		} else if (!number.equals(other.number))
			return false;
		if (setCode == null) {
			if (other.setCode != null)
				return false;
		} else if (!setCode.equals(other.setCode))
			return false;
		return true;
	}
}