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.model.schema;
021
022
023/**
024 * A class containing a SchemaObject, used by the global registries. As the hash code
025 * method of the SchemaObject class is too complex, we had to define a simplest class
026 * for this purpose, where the hash code is computed using only the SchemaObject
027 * type and its OID.
028 *
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 */
031public class SchemaObjectWrapper
032{
033    /** The internal schemaObject */
034    private SchemaObject schemaObject;
035
036
037    /**
038     * Creates a new instance of SchemaObjectWrapper.
039     *
040     * @param schemaObject The contained SchemaObject
041     */
042    public SchemaObjectWrapper( SchemaObject schemaObject )
043    {
044        this.schemaObject = schemaObject;
045    }
046
047
048    /**
049     * Compute the hash code for this wrapper. We only use the object type
050     * and its oid.
051     */
052    public int hashCode()
053    {
054        int h = 37;
055        h += h * 17 + schemaObject.getObjectType().getValue();
056        h += h * 17 + schemaObject.getOid().hashCode();
057
058        return h;
059    }
060
061
062    /**
063     * @see Object#equals(Object)
064     */
065    public boolean equals( Object o )
066    {
067        if ( o == this )
068        {
069            return true;
070        }
071
072        if ( !( o instanceof SchemaObjectWrapper ) )
073        {
074            return false;
075        }
076
077        SchemaObject that = ( ( SchemaObjectWrapper ) o ).get();
078        SchemaObject current = get();
079
080        return ( that.getOid().equals( current.getOid() ) && ( that.getObjectType() == current.getObjectType() ) );
081    }
082
083
084    /**
085     *  @return The interned SchemaObject
086     */
087    public SchemaObject get()
088    {
089        return schemaObject;
090    }
091
092
093    /**
094     * @see Object#toString()
095     */
096    public String toString()
097    {
098        return "<" + schemaObject.getObjectType() + "," + schemaObject.getOid() + ">";
099    }
100}