1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.aci.protectedItem;
21
22
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.Set;
26
27 import org.apache.directory.api.ldap.aci.ProtectedItem;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class RestrictedByItem extends ProtectedItem
43 {
44
45 private final Set<RestrictedByElem> items;
46
47
48
49
50
51
52 public RestrictedByItem( Set<RestrictedByElem> items )
53 {
54 this.items = Collections.unmodifiableSet( items );
55 }
56
57
58
59
60
61
62
63 public Iterator<RestrictedByElem> iterator()
64 {
65 return items.iterator();
66 }
67
68
69
70
71
72 @Override
73 public int hashCode()
74 {
75 int hash = 37;
76
77 if ( items != null )
78 {
79 for ( RestrictedByElem item : items )
80 {
81 if ( item != null )
82 {
83 hash = hash * 17 + item.hashCode();
84 }
85 else
86 {
87 hash = hash * 17 + 37;
88 }
89 }
90 }
91
92 return hash;
93 }
94
95
96
97
98
99 @Override
100 public boolean equals( Object o )
101 {
102 if ( this == o )
103 {
104 return true;
105 }
106
107 if ( o instanceof RestrictedByItem )
108 {
109 RestrictedByItem that = ( RestrictedByItem ) o;
110
111 if ( items != null )
112 {
113 if ( that.items == null )
114 {
115 return false;
116 }
117
118 if ( items.size() != that.items.size() )
119 {
120 return false;
121 }
122
123 for ( RestrictedByElem item : items )
124 {
125 if ( !that.items.contains( item ) )
126 {
127 return false;
128 }
129 }
130
131 return true;
132 }
133 else
134 {
135 return that.items == null;
136 }
137 }
138
139 return false;
140 }
141
142
143
144
145
146 @Override
147 public String toString()
148 {
149 StringBuilder buf = new StringBuilder();
150
151 buf.append( "restrictedBy {" );
152
153 boolean isFirst = true;
154
155 if ( items != null )
156 {
157 for ( RestrictedByElem item : items )
158 {
159 if ( isFirst )
160 {
161 isFirst = false;
162 }
163 else
164 {
165 buf.append( ", " );
166 }
167
168 buf.append( item.toString() );
169 }
170 }
171
172 buf.append( '}' );
173
174 return buf.toString();
175 }
176 }