source: src/main/java/geniusweb/partiesserver/repository/AvailableParty.java@ 9

Last change on this file since 9 was 1, checked in by bart, 5 years ago

Initial Release

File size: 2.4 KB
Line 
1package geniusweb.partiesserver.repository;
2
3import geniusweb.actions.PartyId;
4import geniusweb.party.Capabilities;
5import geniusweb.party.Party;
6import tudelft.utilities.repository.RepoElement;
7
8public class AvailableParty implements RepoElement<String> {
9
10 private final Class<? extends Party> partyclass;
11 private final String name;
12 private final transient Capabilities capabilities;
13 private final transient String description;
14
15 /**
16 *
17 * @param name the filename. This is not a {@link PartyId}.
18 * @param partyclass the class of the party.
19 * @throws IllegalAccessException
20 * @throws InstantiationException
21 */
22 public AvailableParty(String name, Class<? extends Party> partyclass)
23 throws ClassNotFoundException {
24 this.name = name;
25 this.partyclass = partyclass;
26
27 Party party;
28 try {
29 party = partyclass.newInstance();
30 } catch (Throwable e) {
31 throw new ClassNotFoundException(
32 "Could not instantiate " + partyclass, e);
33 }
34 capabilities = party.getCapabilities();
35 description = party.getDescription();
36
37 }
38
39 @Override
40 public String getID() {
41 return name;
42 }
43
44 public String getName() {
45 return name;
46 }
47
48 public Class<? extends Party> getPartyClass() {
49 return partyclass;
50 }
51
52 /**
53 *
54 * @return cached copy of what was received from a call to
55 * {@link Party#getDescription()}.
56 */
57 public String getDescription() {
58 return description;
59 }
60
61 /**
62 *
63 * @return cached copy of what was received from a call to
64 * {@link AvailableParty#getCapabilities()}
65 */
66 public Capabilities getCapabilities() {
67 return capabilities;
68 }
69
70 @Override
71 public int hashCode() {
72 final int prime = 31;
73 int result = 1;
74 result = prime * result + ((name == null) ? 0 : name.hashCode());
75 result = prime * result
76 + ((partyclass == null) ? 0 : partyclass.hashCode());
77 return result;
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj)
83 return true;
84 if (obj == null)
85 return false;
86 if (getClass() != obj.getClass())
87 return false;
88 AvailableParty other = (AvailableParty) obj;
89 if (name == null) {
90 if (other.name != null)
91 return false;
92 } else if (!name.equals(other.name))
93 return false;
94 if (partyclass == null) {
95 if (other.partyclass != null)
96 return false;
97 } else if (!partyclass.equals(other.partyclass))
98 return false;
99 return true;
100 }
101
102 @Override
103 public String toString() {
104 return name + " (" + partyclass + ")";
105 }
106
107}
Note: See TracBrowser for help on using the repository browser.