001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.ecm.automation.core.impl; 020 021/** 022 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 023 */ 024public final class TypeAdapterKey { 025 026 public final Class<?> input; 027 028 public final Class<?> output; 029 030 private int hashCode; 031 032 public TypeAdapterKey(Class<?> input, Class<?> output) { 033 this.input = input; 034 this.output = output; 035 } 036 037 @Override 038 public boolean equals(Object obj) { 039 if (this == obj) { 040 return true; 041 } 042 // this class is final - do not need instanceof check. 043 if (obj == null) { 044 return false; 045 } 046 if (obj.getClass() == TypeAdapterKey.class) { 047 TypeAdapterKey key = (TypeAdapterKey) obj; 048 return key.input == input && key.output == output; 049 } 050 return false; 051 } 052 053 @Override 054 public String toString() { 055 return input + ":" + output; 056 } 057 058 @Override 059 public int hashCode() { 060 if (hashCode == 0) { 061 hashCode = createHashCode(); 062 } 063 return hashCode; 064 } 065 066 protected int createHashCode() { 067 int result = input.hashCode() | output.hashCode(); 068 return result == 0 ? 0xbabe : result; 069 } 070 071}