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