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