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 {@link MaxValueCount}.
28   */
29  public class MaxValueCountElem
30  {
31      /** The targeted AttributeType */
32      private AttributeType attributeType;
33  
34      /** The maximum number of accepted values for this attributeType */
35      private int maxCount;
36  
37  
38      /**
39       * Creates a new instance.
40       * 
41       * @param attributeType the attribute ID to limit the maximum count
42       * @param maxCount the maximum count of the attribute allowed
43       */
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          hash = hash * 17 + attributeType.hashCode();
83          return hash;
84      }
85  
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public boolean equals( Object o )
92      {
93          if ( o == null )
94          {
95              return false;
96          }
97  
98          if ( this == o )
99          {
100             return true;
101         }
102 
103         if ( o instanceof MaxValueCountElem )
104         {
105             MaxValueCountElem that = ( MaxValueCountElem ) o;
106             if ( this.maxCount == that.maxCount )
107             {
108                 if ( this.attributeType == null )
109                 {
110                     return that.attributeType == null;
111                 }
112                 else
113                 {
114                     return this.attributeType.equals( that.attributeType );
115                 }
116             }
117         }
118         return false;
119     }
120 
121 
122     /**
123      * {@inheritDoc}
124      */
125     @Override
126     public String toString()
127     {
128         return "{ type " + attributeType.getName() + ", maxCount " + maxCount + " }";
129     }
130 }