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