-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHeroStat.java
More file actions
78 lines (67 loc) · 1.85 KB
/
HeroStat.java
File metadata and controls
78 lines (67 loc) · 1.85 KB
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
package valueobject;
/**
* HeroStat is a value object
*/
public class HeroStat {
private final int strength;
private final int intelligence;
private final int luck;
private HeroStat(int strength, int intelligence, int luck){
this.strength = strength;
this.intelligence = intelligence;
this.luck = luck;
}
/**
* Static factory method to create new instances
* @param strength strength of hero
* @param intelligence intelligence of hero
* @param luck luck of hero
* @return
*/
public static HeroStat valueOf(int strength, int intelligence, int luck){
return new HeroStat(strength, intelligence, luck);
}
public int getStrength(){
return strength;
}
public int getIntelligence(){
return intelligence;
}
public int getLuck(){
return luck;
}
@Override
public String toString(){
return "HeroStat [strength=" + strength + ", intelligence=" + intelligence
+ ", luck = " + luck + "]";
}
@Override
public int hashCode(){
final int prime = 31;
int result = 1;
result = prime * result + intelligence;
result = prime * result + luck;
result = prime * result + strength;
return result;
}
@Override
public boolean equals(Object obj){
if(this == obj){
return true;
}
if(obj == null){
return false;
}
if(getClass() != obj.getClass()){
return false;
}
HeroStat other = (HeroStat) obj;
if(intelligence != other.intelligence){
return false;
}
if(luck != other.luck){
return false;
}
return strength == other.strength;
}
}