8c7ab330deba262277ad417b630f0fad3f016eb4
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / common / InjectionKey.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common;
10
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.base.Preconditions;
14
15
16 /**
17  * injection lookup key based on version and target object
18  */
19 public class InjectionKey {
20
21     private final int version;
22     private final Class<?> targetClazz;
23
24     /**
25      * @param version openflow version
26      * @param targetClazz target class
27      */
28     public InjectionKey(final int version, final Class<?> targetClazz) {
29         this.version = version;
30         this.targetClazz = Preconditions.checkNotNull(targetClazz);
31     }
32
33     @Override
34     public int hashCode() {
35         return 31 * version + targetClazz.hashCode();
36     }
37
38     @Override
39     public boolean equals(final Object obj) {
40         if (this == obj) {
41             return true;
42         }
43         if (obj == null) {
44             return false;
45         }
46         if (getClass() != obj.getClass()) {
47             return false;
48         }
49         final InjectionKey other = (InjectionKey) obj;
50         if (version != other.version) {
51             return false;
52         }
53         return targetClazz.equals(other.targetClazz);
54     }
55
56     @Override
57     public final String toString() {
58         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
59     }
60
61     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
62         return toStringHelper.add("version", version).add("targetClazz", targetClazz);
63     }
64 }