001    /*****************************************************************************
002     * Copyright (C) PicoContainer Committers. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *                                                                           *
008     * Original code by Joerg Schaibe                                            *
009     *****************************************************************************/
010    package org.picocontainer;
011    
012    import java.io.Serializable;
013    import java.lang.annotation.Annotation;
014    
015    /** @author Paul Hammant */
016    @SuppressWarnings("serial")
017    public class BindKey<T> implements Serializable {
018    
019            
020            private final Class<T> type;
021        private final Class<? extends Annotation> annotation;
022    
023        public BindKey(Class<T> type, Class<? extends Annotation> annotation) {
024            this.type = type;
025            this.annotation = annotation;
026        }
027    
028        public Class<T> getType() {
029            return type;
030        }
031    
032        public Class<? extends Annotation> getAnnotation() {
033            return annotation;
034        }
035    
036        public String toString() {
037            return type.getName() + ":" + annotation.getName();
038        }
039    
040        public boolean equals(Object o) {
041            if (this == o) return true;
042            if (o == null || getClass() != o.getClass()) return false;
043    
044            BindKey<?> bindKey = (BindKey<?>)o;
045    
046            if (!annotation.equals(bindKey.annotation)) return false;
047            if (!type.equals(bindKey.type)) return false;
048    
049            return true;
050        }
051    
052        public int hashCode() {
053            int result;
054            result = type.hashCode();
055            result = 31 * result + annotation.hashCode();
056            return result;
057        }
058    
059        public static <T> BindKey<T> bindKey(Class<T> type, Class<? extends Annotation> annotation) {
060            return new BindKey<T>(type, annotation);
061        }
062    
063    }