001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.api.ldap.aci.protectedItem;
021
022
023import org.apache.directory.api.ldap.model.schema.AttributeType;
024
025
026/**
027 * An element of  MaxValueCount.
028 * 
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 */
031public class MaxValueCountElem
032{
033    /** The targeted AttributeType */
034    private AttributeType attributeType;
035
036    /** The maximum number of accepted values for this attributeType */
037    private int maxCount;
038
039    /**
040     * Creates a new instance.
041     * 
042     * @param attributeType the attribute ID to limit the maximum count
043     * @param maxCount the maximum count of the attribute allowed
044     */
045
046    public MaxValueCountElem( AttributeType attributeType, int maxCount )
047    {
048        this.attributeType = attributeType;
049        this.maxCount = maxCount;
050    }
051
052
053    /**
054     * Gets the attribute to limit the maximum count.
055     *
056     * @return the attribute type
057     */
058    public AttributeType getAttributeType()
059    {
060        return attributeType;
061    }
062
063
064    /**
065     * Gets the maximum count of the attribute allowed.
066     *
067     * @return the maximum count of the attribute allowed
068     */
069    public int getMaxCount()
070    {
071        return maxCount;
072    }
073
074
075    /**
076     * {@inheritDoc}
077     */
078    @Override
079    public int hashCode()
080    {
081        int hash = 37;
082        hash = hash * 17 + maxCount;
083        
084        if ( attributeType != null )
085        {
086            hash = hash * 17 + attributeType.hashCode();
087        }
088        
089        return hash;
090    }
091
092
093    /**
094     * {@inheritDoc}
095     */
096    @Override
097    public boolean equals( Object o )
098    {
099        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}