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   *    https://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      public MaxValueCountElem( AttributeType attributeType, int maxCount )
46      {
47          this.attributeType = attributeType;
48          this.maxCount = maxCount;
49      }
50  
51  
52      /**
53       * Gets the attribute to limit the maximum count.
54       *
55       * @return the attribute type
56       */
57      public AttributeType getAttributeType()
58      {
59          return attributeType;
60      }
61  
62  
63      /**
64       * Gets the maximum count of the attribute allowed.
65       *
66       * @return the maximum count of the attribute allowed
67       */
68      public int getMaxCount()
69      {
70          return maxCount;
71      }
72  
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      public int hashCode()
79      {
80          int hash = 37;
81          hash = hash * 17 + maxCount;
82  
83          if ( attributeType != null )
84          {
85              hash = hash * 17 + attributeType.hashCode();
86          }
87  
88          return hash;
89      }
90  
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public boolean equals( Object o )
97      {
98          if ( this == o )
99          {
100             return true;
101         }
102 
103         if ( o instanceof MaxValueCountElem )
104         {
105             MaxValueCountElem that = ( MaxValueCountElem ) o;
106 
107             if ( maxCount == that.maxCount )
108             {
109                 if ( attributeType == null )
110                 {
111                     return that.attributeType == null;
112                 }
113                 else
114                 {
115                     return attributeType.equals( that.attributeType );
116                 }
117             }
118         }
119 
120         return false;
121     }
122 
123 
124     /**
125      * {@inheritDoc}
126      */
127     @Override
128     public String toString()
129     {
130         StringBuilder sb = new StringBuilder();
131         
132         sb.append( "{ type " );
133         
134         if ( attributeType != null )
135         {
136             sb.append( attributeType.getName() );
137         }
138         else
139         {
140             sb.append( "null" );
141         }
142         
143         sb.append( ", maxCount " ).append( maxCount );
144         sb.append( "}" );
145         
146         return sb.toString();
147     }
148 }