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 import org.apache.directory.api.ldap.model.schema.AttributeType;
29
30
31
32
33
34
35
36 public abstract class AbstractAttributeTypeProtectedItem extends ProtectedItem
37 {
38
39 protected final Set<AttributeType> attributeTypes;
40
41
42
43
44
45
46 protected AbstractAttributeTypeProtectedItem( Set<AttributeType> attributeTypes )
47 {
48 this.attributeTypes = Collections.unmodifiableSet( attributeTypes );
49 }
50
51
52
53
54
55
56
57 public Iterator<AttributeType> iterator()
58 {
59 return attributeTypes.iterator();
60 }
61
62
63
64
65
66 @Override
67 public int hashCode()
68 {
69 int hash = 37;
70
71 if ( attributeTypes != null )
72 {
73 for ( AttributeType attributeType : attributeTypes )
74 {
75 hash = hash * 17 + attributeType.hashCode();
76 }
77 }
78
79 hash = hash * 17 + getClass().getName().hashCode();
80
81 return hash;
82 }
83
84
85
86
87
88 @Override
89 public boolean equals( Object o )
90 {
91 if ( this == o )
92 {
93 return true;
94 }
95
96 if ( o == null )
97 {
98 return false;
99 }
100
101 if ( getClass().isAssignableFrom( o.getClass() ) )
102 {
103 AbstractAttributeTypeProtectedItem that = ( AbstractAttributeTypeProtectedItem ) o;
104
105 if ( attributeTypes != null )
106 {
107 if ( ( that.attributeTypes == null ) || ( that.attributeTypes.size() != attributeTypes.size() ) )
108 {
109 return false;
110 }
111
112 for ( AttributeType attributeType : attributeTypes )
113 {
114 if ( !that.attributeTypes.contains( attributeType ) )
115 {
116 return false;
117 }
118 }
119
120 return true;
121 }
122 else
123 {
124 return that.attributeTypes == null;
125 }
126 }
127
128 return false;
129 }
130
131
132
133
134
135 @Override
136 public String toString()
137 {
138 StringBuilder buf = new StringBuilder();
139
140 buf.append( "{ " );
141 boolean isFirst = true;
142
143 if ( attributeTypes != null )
144 {
145 for ( AttributeType attributeType : attributeTypes )
146 {
147 if ( isFirst )
148 {
149 isFirst = false;
150 }
151 else
152 {
153 buf.append( ", " );
154 }
155
156 buf.append( attributeType.getName() );
157 }
158 }
159
160 buf.append( " }" );
161
162 return buf.toString();
163 }
164 }