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 org.apache.directory.api.ldap.model.schema.AttributeType;
24  
25  
26  /**
27   * An element of  MaxValueCount.
28   * 
29   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30   */
31  public class MaxValueCountElem
32  {
33      /** The targeted AttributeType */
34      private AttributeType attributeType;
35  
36      /** The maximum number of accepted values for this attributeType */
37      private int maxCount;
38  
39      /**
40       * Creates a new instance.
41       * 
42       * @param attributeType the attribute ID to limit the maximum count
43       * @param maxCount the maximum count of the attribute allowed
44       */
45  
46      public MaxValueCountElem( AttributeType attributeType, int maxCount )
47      {
48          this.attributeType = attributeType;
49          this.maxCount = maxCount;
50      }
51  
52  
53      /**
54       * Gets the attribute to limit the maximum count.
55       *
56       * @return the attribute type
57       */
58      public AttributeType getAttributeType()
59      {
60          return attributeType;
61      }
62  
63  
64      /**
65       * Gets the maximum count of the attribute allowed.
66       *
67       * @return the maximum count of the attribute allowed
68       */
69      public int getMaxCount()
70      {
71          return maxCount;
72      }
73  
74  
75      /**
76       * {@inheritDoc}
77       */
78      @Override
79      public int hashCode()
80      {
81          int hash = 37;
82          hash = hash * 17 + maxCount;
83          
84          if ( attributeType != null )
85          {
86              hash = hash * 17 + attributeType.hashCode();
87          }
88          
89          return hash;
90      }
91  
92  
93      /**
94       * {@inheritDoc}
95       */
96      @Override
97      public boolean equals( Object o )
98      {
99          if ( this == o )
100         {
101             return true;
102         }
103 
104         if ( o instanceof MaxValueCountElem )
105         {
106             MaxValueCountElem that = ( MaxValueCountElem ) o;
107             
108             if ( maxCount == that.maxCount )
109             {
110                 if ( attributeType == null )
111                 {
112                     return that.attributeType == null;
113                 }
114                 else
115                 {
116                     return attributeType.equals( that.attributeType );
117                 }
118             }
119         }
120         
121         return false;
122     }
123 
124 
125     /**
126      * {@inheritDoc}
127      */
128     @Override
129     public String toString()
130     {
131         StringBuilder sb = new StringBuilder();
132         
133         sb.append( "{ type " );
134         
135         if ( attributeType != null )
136         {
137             sb.append( attributeType.getName() );
138         }
139         else
140         {
141             sb.append( "null" );
142         }
143         
144         sb.append( ", maxCount " ).append( maxCount );
145         sb.append( "}" );
146         
147         return sb.toString();
148     }
149 }