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.shared.ldap.aci.protectedItem;
021
022
023import org.apache.directory.shared.ldap.model.schema.AttributeType;
024
025
026/**
027 * An element of {@link MaxValueCount}.
028 */
029public class MaxValueCountElem
030{
031    /** The targeted AttributeType */
032    private AttributeType attributeType;
033
034    /** The maximum number of accepted values for this attributeType */
035    private int maxCount;
036
037
038    /**
039     * Creates a new instance.
040     * 
041     * @param attributeType the attribute ID to limit the maximum count
042     * @param maxCount the maximum count of the attribute allowed
043     */
044
045    public MaxValueCountElem( AttributeType attributeType, int maxCount )
046    {
047        this.attributeType = attributeType;
048        this.maxCount = maxCount;
049    }
050
051
052    /**
053     * Gets the attribute to limit the maximum count.
054     *
055     * @return the attribute type
056     */
057    public AttributeType getAttributeType()
058    {
059        return attributeType;
060    }
061
062
063    /**
064     * Gets the maximum count of the attribute allowed.
065     *
066     * @return the maximum count of the attribute allowed
067     */
068    public int getMaxCount()
069    {
070        return maxCount;
071    }
072
073    
074
075    /**
076     * {@inheritDoc}
077     */
078    @Override
079    public int hashCode()
080    {
081        int hash = 37;
082        hash = hash * 17 + maxCount;
083        hash = hash * 17 + attributeType.hashCode();
084        return hash;
085    }
086
087
088    /**
089     * {@inheritDoc}
090     */
091    @Override
092    public boolean equals( Object o )
093    {
094        if (o == null)
095        {
096            return false;
097        }
098        
099        if ( this == o )
100        {
101            return true;
102        }
103        
104        if ( o instanceof MaxValueCountElem )
105        {
106            MaxValueCountElem that = ( MaxValueCountElem ) o;
107            if ( this.maxCount == that.maxCount )
108            {
109                if ( this.attributeType == null )
110                {
111                    return that.attributeType == null;
112                }
113                else
114                {
115                    return this.attributeType.equals( that.attributeType );
116                }
117            }
118        }
119        return false;
120    }
121
122
123    /**
124     * {@inheritDoc}
125     */
126    @Override
127    public String toString()
128    {
129        return "{ type " + attributeType.getName() + ", maxCount " + maxCount + " }";
130    }
131}