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.extras.controls.ad;
021
022
023import org.apache.directory.api.ldap.model.message.controls.AbstractControl;
024
025
026/**
027 * Implementation of the AD PolicyHints control.
028 * 
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 */
031public class AdPolicyHintsImpl extends AbstractControl implements AdPolicyHints
032{
033    /** This control OID */
034    private int flags;
035
036    /**
037     * Creates an instance of AdPolicyHintsImpl
038     */
039    public AdPolicyHintsImpl()
040    {
041        super( OID );
042    }
043
044
045    /**
046     * {@inheritDoc}
047     */
048    @Override
049    public int getFlags()
050    {
051        return flags;
052    }
053
054
055    /**
056     * {@inheritDoc}
057     */
058    @Override
059    public void setFlags( int flags )
060    {
061        this.flags = flags;
062    }
063    
064    
065    /**
066     * @see Object#hashCode()
067     */
068    @Override
069    public int hashCode()
070    {
071        int h = 37;
072
073        h = h * 17 + super.hashCode();
074        h = h * 17 + flags;
075
076        return h;
077    }
078
079
080    /**
081     * @see Object#equals(Object)
082     */
083    @Override
084    public boolean equals( Object o )
085    {
086        if ( this == o )
087        {
088            return true;
089        }
090
091        if ( !( o instanceof AdPolicyHints ) )
092        {
093            return false;
094        }
095
096        AdPolicyHints otherControl = ( AdPolicyHints ) o;
097
098        return super.equals( o ) && flags == otherControl.getFlags();
099    }
100
101
102    /**
103     * @see Object#toString()
104     */
105    @Override
106    public String toString()
107    {
108        StringBuilder sb = new StringBuilder();
109
110        sb.append( "    AdPolicyHints control :\n" );
111        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
112        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
113        sb.append( "        flags : 0x" ).append( Integer.toHexString( flags ) ).append( "\n" );
114
115        return sb.toString();
116    }
117}