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    /**
041     * Creates a new instance.
042     * 
043     * @param attributeType the attribute ID to limit the maximum count
044     * @param maxCount the maximum count of the attribute allowed
045     */
046
047    public MaxValueCountElem( AttributeType attributeType, int maxCount )
048    {
049        this.attributeType = attributeType;
050        this.maxCount = maxCount;
051    }
052
053
054    /**
055     * Gets the attribute to limit the maximum count.
056     *
057     * @return the attribute type
058     */
059    public AttributeType getAttributeType()
060    {
061        return attributeType;
062    }
063
064
065    /**
066     * Gets the maximum count of the attribute allowed.
067     *
068     * @return the maximum count of the attribute allowed
069     */
070    public int getMaxCount()
071    {
072        return maxCount;
073    }
074
075
076    /**
077     * {@inheritDoc}
078     */
079    @Override
080    public int hashCode()
081    {
082        int hash = 37;
083        hash = hash * 17 + maxCount;
084        hash = hash * 17 + attributeType.hashCode();
085        return hash;
086    }
087
088
089    /**
090     * {@inheritDoc}
091     */
092    @Override
093    public boolean equals( Object o )
094    {
095        if ( o == null )
096        {
097            return false;
098        }
099
100        if ( this == o )
101        {
102            return true;
103        }
104
105        if ( o instanceof MaxValueCountElem )
106        {
107            MaxValueCountElem that = ( MaxValueCountElem ) o;
108            if ( this.maxCount == that.maxCount )
109            {
110                if ( this.attributeType == null )
111                {
112                    return that.attributeType == null;
113                }
114                else
115                {
116                    return this.attributeType.equals( that.attributeType );
117                }
118            }
119        }
120        return false;
121    }
122
123
124    /**
125     * {@inheritDoc}
126     */
127    @Override
128    public String toString()
129    {
130        return "{ type " + attributeType.getName() + ", maxCount " + maxCount + " }";
131    }
132}