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