1 | package schedframe.resources; |
---|
2 | |
---|
3 | import java.util.HashMap; |
---|
4 | import java.util.Map; |
---|
5 | import java.util.Set; |
---|
6 | |
---|
7 | |
---|
8 | /** |
---|
9 | * |
---|
10 | * @author Marcin Krystek |
---|
11 | * |
---|
12 | */ |
---|
13 | public class ResourceProvider { |
---|
14 | |
---|
15 | protected String administrationDomain; |
---|
16 | protected String id; |
---|
17 | protected String location; |
---|
18 | protected String type; |
---|
19 | protected Object description; |
---|
20 | protected String commonName; |
---|
21 | |
---|
22 | protected Map<String, String> properties; |
---|
23 | |
---|
24 | public ResourceProvider(String id, |
---|
25 | String administrationDomain, |
---|
26 | String location, |
---|
27 | String type) { |
---|
28 | this.id = id; |
---|
29 | this.administrationDomain = administrationDomain; |
---|
30 | this.location = location; |
---|
31 | this.type = type; |
---|
32 | this.description = null; |
---|
33 | this.properties = null; |
---|
34 | } |
---|
35 | |
---|
36 | public ResourceProvider(){ |
---|
37 | this.id = null; |
---|
38 | this.administrationDomain = null; |
---|
39 | this.location = null; |
---|
40 | this.description = null; |
---|
41 | this.type = null; |
---|
42 | this.properties = null; |
---|
43 | } |
---|
44 | |
---|
45 | public String getAdministrationDomain() { |
---|
46 | return this.administrationDomain; |
---|
47 | } |
---|
48 | |
---|
49 | public String getProviderId() { |
---|
50 | return this.id; |
---|
51 | } |
---|
52 | |
---|
53 | public String getProviderLocation() { |
---|
54 | return this.location; |
---|
55 | } |
---|
56 | |
---|
57 | public Object getDescription(){ |
---|
58 | return this.description; |
---|
59 | } |
---|
60 | |
---|
61 | public String getType(){ |
---|
62 | return this.type; |
---|
63 | } |
---|
64 | |
---|
65 | public String getCommonName(){ |
---|
66 | return this.commonName; |
---|
67 | } |
---|
68 | |
---|
69 | public void setCommonName(String name){ |
---|
70 | this.commonName = name; |
---|
71 | } |
---|
72 | |
---|
73 | public void addProperty(String key, String value){ |
---|
74 | if(this.properties == null){ |
---|
75 | this.properties = new HashMap<String, String>(); |
---|
76 | } |
---|
77 | |
---|
78 | this.properties.put(key, value); |
---|
79 | } |
---|
80 | |
---|
81 | public String getProperty(String key){ |
---|
82 | if(this.properties == null) |
---|
83 | return null; |
---|
84 | String value = this.properties.get(key); |
---|
85 | return value; |
---|
86 | } |
---|
87 | |
---|
88 | public Set<String> getPropertyKeys(){ |
---|
89 | if(this.properties == null) |
---|
90 | return null; |
---|
91 | |
---|
92 | Set<String> keys = this.properties.keySet(); |
---|
93 | |
---|
94 | return keys; |
---|
95 | } |
---|
96 | |
---|
97 | public boolean equals(Object r){ |
---|
98 | if (r instanceof ResourceProvider == false) |
---|
99 | return false; |
---|
100 | |
---|
101 | ResourceProvider resProvider = (ResourceProvider) r; |
---|
102 | |
---|
103 | if(type != null && !type.equals(resProvider.getType())) |
---|
104 | return false; |
---|
105 | |
---|
106 | if(administrationDomain != null && !administrationDomain.equals(resProvider.getAdministrationDomain())) |
---|
107 | return false; |
---|
108 | |
---|
109 | if(location != null && !location.equals(resProvider.getProviderLocation())) |
---|
110 | return false; |
---|
111 | |
---|
112 | if(id != null && !id.equals(resProvider.getProviderId())) |
---|
113 | return false; |
---|
114 | |
---|
115 | return true; |
---|
116 | |
---|
117 | } |
---|
118 | |
---|
119 | public int hashCode() { |
---|
120 | // 4 is for 4 letters in word null. |
---|
121 | int cnt = (this.id == null ? 4 : this.id.length()); |
---|
122 | cnt += (this.administrationDomain == null ? 4 : this.administrationDomain.length()); |
---|
123 | cnt += (this.location == null ? 4 : this.location.length()); |
---|
124 | cnt += (this.type == null ? 4 : this.type.length()); |
---|
125 | cnt += (this.commonName == null ? 4 : this.commonName.length()); |
---|
126 | |
---|
127 | StringBuffer buffer = new StringBuffer(cnt); |
---|
128 | buffer.append(this.id); |
---|
129 | buffer.append(this.administrationDomain); |
---|
130 | buffer.append(this.location); |
---|
131 | buffer.append(this.type); |
---|
132 | buffer.append(this.commonName); |
---|
133 | String s = buffer.toString(); |
---|
134 | return s.hashCode(); |
---|
135 | } |
---|
136 | |
---|
137 | public String toString(){ |
---|
138 | return id + " " + administrationDomain + " " + location + " " + commonName; |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | } |
---|