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 * https://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 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 * {@inheritDoc} 076 */ 077 @Override 078 public int hashCode() 079 { 080 int hash = 37; 081 hash = hash * 17 + maxCount; 082 083 if ( attributeType != null ) 084 { 085 hash = hash * 17 + attributeType.hashCode(); 086 } 087 088 return hash; 089 } 090 091 092 /** 093 * {@inheritDoc} 094 */ 095 @Override 096 public boolean equals( Object o ) 097 { 098 if ( this == o ) 099 { 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}