Bug 5540 - Multiple convert types for one convertor
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / common / ConvertorKey.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 ConvertorKey {
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 ConvertorKey(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 ConvertorKey other = (ConvertorKey) obj;
50         return version == other.version && targetClazz.equals(other.targetClazz);
51     }
52
53     @Override
54     public final String toString() {
55         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
56     }
57
58     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
59         return toStringHelper.add("version", version).add("targetClazz", targetClazz);
60     }
61 }