View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
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   * A specific value of specific attributes.
33   */
34  public class AttributeValueItem extends ProtectedItem
35  {
36      /** The protected Attributes */
37      private final Set<Attribute> attributes;
38  
39  
40      /**
41       * Creates a new instance.
42       * 
43       * @param attributes the collection of {@link Attribute}s.
44       */
45      public AttributeValueItem( Set<Attribute> attributes )
46      {
47          this.attributes = Collections.unmodifiableSet( attributes );
48      }
49  
50  
51      /**
52       * Returns an iterator of all {@link org.apache.directory.api.ldap.model.entry.Attribute}s.
53       *
54       * @return the iterator
55       */
56      public Iterator<Attribute> iterator()
57      {
58          return attributes.iterator();
59      }
60  
61  
62      /**
63       * {@inheritDoc}
64       */
65      @Override
66      public int hashCode()
67      {
68          int hash = 37;
69          hash = hash * 17 + attributes.hashCode();
70          return hash;
71      }
72  
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      public boolean equals( Object o )
79      {
80          if ( this == o )
81          {
82              return true;
83          }
84  
85          if ( o == null )
86          {
87              return false;
88          }
89  
90          if ( o instanceof AttributeValueItem )
91          {
92              AttributeValueItem that = ( AttributeValueItem ) o;
93  
94              return this.attributes.equals( that.attributes );
95          }
96  
97          return false;
98      }
99  
100 
101     /**
102      * {@inheritDoc}
103      */
104     public String toString()
105     {
106         StringBuilder buf = new StringBuilder();
107 
108         buf.append( "attributeValue {" );
109 
110         boolean isFirst = true;
111 
112         for ( Attribute attribute : attributes )
113         {
114             if ( isFirst )
115             {
116                 isFirst = false;
117             }
118             else
119             {
120                 buf.append( ", " );
121             }
122 
123             buf.append( attribute.getId() );
124             buf.append( '=' );
125             buf.append( attribute.get() );
126         }
127 
128         buf.append( " }" );
129 
130         return buf.toString();
131     }
132 }