1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.metricshub.wbem.sblim.slp.internal.msg;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 import java.util.Iterator;
47 import java.util.List;
48 import java.util.TreeSet;
49 import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute;
50
51
52
53
54
55
56
57
58
59 public class DADescriptor implements Comparable<DADescriptor> {
60 private String iURL;
61
62 private TreeSet<String> iScopeSet;
63
64 private List<ServiceLocationAttribute> iAttributes;
65
66
67
68
69
70
71
72
73
74
75 public DADescriptor(String pURL, TreeSet<String> pScopeSet, List<ServiceLocationAttribute> pAttributes) {
76 this.iURL = pURL;
77 this.iScopeSet = pScopeSet;
78 this.iAttributes = pAttributes;
79 }
80
81
82
83
84
85
86 public String getURL() {
87 return this.iURL;
88 }
89
90
91
92
93
94
95
96 public boolean hasScope(String pScope) {
97 if (this.iScopeSet == null) return false;
98 return this.iScopeSet.contains(pScope);
99 }
100
101 public int compareTo(DADescriptor o) {
102 DADescriptor that = o;
103 return this.iURL.compareTo(that.iURL);
104 }
105
106 @Override
107 public boolean equals(Object pObj) {
108 if (!(pObj instanceof DADescriptor)) return false;
109 DADescriptor that = (DADescriptor) pObj;
110 return this.iURL.equals(that.iURL);
111 }
112
113 private int iHashCode = 0;
114
115 private void incHashCode(int pHashCode) {
116 this.iHashCode *= 31;
117 this.iHashCode += pHashCode;
118 }
119
120
121
122
123
124
125
126 @Override
127 public int hashCode() {
128 if (this.iHashCode == 0) {
129 this.iHashCode = this.iURL.hashCode();
130 Iterator<?> itr;
131 if (this.iScopeSet != null) {
132 itr = this.iScopeSet.iterator();
133 while (itr.hasNext()) incHashCode(itr.next().hashCode());
134 }
135 if (this.iAttributes != null) {
136 itr = this.iAttributes.iterator();
137
138
139
140
141 while (itr.hasNext()) this.iHashCode += itr.next().hashCode();
142 }
143 }
144 return this.iHashCode;
145 }
146
147 @Override
148 public String toString() {
149 StringBuffer strBuf = new StringBuffer("URL : " + this.iURL + "\nScopes : ");
150 if (this.iScopeSet != null) {
151 Iterator<String> itr = this.iScopeSet.iterator();
152 boolean more = false;
153 while (itr.hasNext()) {
154 if (more) strBuf.append(", "); else more = true;
155 strBuf.append(itr.next());
156 }
157 }
158
159 return strBuf.toString();
160 }
161 }