1 | package geniusweb.party;
|
---|
2 |
|
---|
3 | import java.util.Set;
|
---|
4 |
|
---|
5 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
---|
6 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
---|
7 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
8 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
9 |
|
---|
10 | import geniusweb.profile.Profile;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * The capabilities of a party
|
---|
14 | */
|
---|
15 | @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
|
---|
16 | public class Capabilities {
|
---|
17 | /**
|
---|
18 | * List of supported protocol names
|
---|
19 | */
|
---|
20 | private final Set<String> behaviours;
|
---|
21 | /**
|
---|
22 | * The profile classes that are supported
|
---|
23 | */
|
---|
24 | private final Set<Class<? extends Profile>> profiles;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | *
|
---|
28 | * @param behaviours the protocols that a Party can handle
|
---|
29 | */
|
---|
30 | @JsonCreator
|
---|
31 | public Capabilities(@JsonProperty("behaviours") Set<String> behaviours,
|
---|
32 | @JsonProperty("profiles") Set<Class<? extends Profile>> profiles) {
|
---|
33 | if (behaviours == null) {
|
---|
34 | throw new IllegalArgumentException("behaviours==null");
|
---|
35 | }
|
---|
36 | for (Class<? extends Profile> prof : profiles) {
|
---|
37 | if (!Profile.class.isAssignableFrom(prof))
|
---|
38 | throw new IllegalArgumentException(
|
---|
39 | "profile " + prof + " must be a subclass of Profile");
|
---|
40 | }
|
---|
41 | this.behaviours = behaviours;
|
---|
42 | this.profiles = profiles;
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | *
|
---|
47 | * @return the behaviours (protocols) that are supported
|
---|
48 | */
|
---|
49 | public Set<String> getBehaviours() {
|
---|
50 | return behaviours;
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | *
|
---|
55 | * @return the profile classes that are supported
|
---|
56 | *
|
---|
57 | */
|
---|
58 | public Set<Class<? extends Profile>> getProfiles() {
|
---|
59 | return profiles;
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public int hashCode() {
|
---|
64 | final int prime = 31;
|
---|
65 | int result = 1;
|
---|
66 | result = prime * result
|
---|
67 | + ((behaviours == null) ? 0 : behaviours.hashCode());
|
---|
68 | return result;
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public boolean equals(Object obj) {
|
---|
73 | if (this == obj)
|
---|
74 | return true;
|
---|
75 | if (obj == null)
|
---|
76 | return false;
|
---|
77 | if (getClass() != obj.getClass())
|
---|
78 | return false;
|
---|
79 | Capabilities other = (Capabilities) obj;
|
---|
80 | if (behaviours == null) {
|
---|
81 | if (other.behaviours != null)
|
---|
82 | return false;
|
---|
83 | } else if (!behaviours.equals(other.behaviours))
|
---|
84 | return false;
|
---|
85 | return true;
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public String toString() {
|
---|
90 | return "Capabilities[" + "Behaviours=" + behaviours + "]";
|
---|
91 | }
|
---|
92 |
|
---|
93 | }
|
---|