1 package cz.cuni.amis.pogamut.ut2004.agent.module.sensor;
2
3 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weapon;
4 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
5 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;
6 import cz.cuni.amis.utils.HashCode;
7 import cz.cuni.amis.utils.NullCheck;
8
9
10
11
12
13
14
15
16
17
18 public class WeaponPref {
19
20 private ItemType weapon;
21 private boolean primary;
22 private int hashCode;
23
24
25
26
27
28
29 public WeaponPref(ItemType weapon, boolean primary) {
30 this.weapon = weapon;
31 this.primary = primary;
32 NullCheck.check(this.weapon, "weapon");
33 if (weapon.getCategory() != Category.WEAPON) {
34 throw new IllegalArgumentException("passed 'weapon' is not of ItemType.Category.WEAPON but " + weapon.getCategory().toString());
35 }
36 hashCode = new HashCode().add(weapon).add(primary).getHash();
37 }
38
39
40
41
42
43
44 public WeaponPref(ItemType weapon) {
45 this.weapon = weapon;
46 this.primary = true;
47 NullCheck.check(this.weapon, "weapon");
48 if (weapon.getCategory() != Category.WEAPON) {
49 throw new IllegalArgumentException("passed 'weapon' is not of ItemType.Category.WEAPON but " + weapon.getCategory().toString());
50 }
51 hashCode = new HashCode().add(weapon).add(primary).getHash();
52 }
53
54 @Override
55 public int hashCode() {
56 return hashCode;
57 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (obj == this) return true;
62 if (obj == null) return false;
63 if (!(obj instanceof WeaponPref)) return false;
64 WeaponPref pref = (WeaponPref)obj;
65 return pref.weapon == weapon && pref.primary == primary;
66 }
67
68
69
70
71
72
73 public WeaponPref(Weapon weapon, boolean primary) {
74 this.weapon = weapon.getType();
75 this.primary = primary;
76 NullCheck.check(this.weapon, "weapon");
77 }
78
79
80
81
82
83 public ItemType getWeapon() {
84 return weapon;
85 }
86
87
88
89
90
91 public boolean isPrimary() {
92 return primary;
93 }
94
95
96
97
98
99 public boolean isSecondary() {
100 return !primary;
101 }
102
103 @Override
104 public String toString() {
105 return "WeaponPref[type=" + weapon.getName() + ", " + (primary ? "primary mode" : "secondary mode") + "]";
106 }
107
108 }