98f31fc6cb53edd6231c40c19cf1d58d1156863a
[openflowplugin.git] / extension / openflowplugin-extension-api / src / main / java / org / opendaylight / openflowplugin / extension / api / TypeVersionKey.java
1 /**
2  * Copyright (c) 2014 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 package org.opendaylight.openflowplugin.extension.api;
9
10
11 /**
12  * lookup and register key for extension converters, basic case expects this to
13  * correlate with input model type
14  * 
15  * @param <TYPE> type of key
16  */
17 public class TypeVersionKey<TYPE> {
18
19     private Class<? extends TYPE> type;
20     private short ofVersion;
21
22     /**
23      * @param type
24      * @param ofVersion 
25      */
26     public TypeVersionKey(Class<? extends TYPE> type, short ofVersion) {
27         this.type = type;
28         this.ofVersion = ofVersion;
29     }
30
31     /**
32      * @return key type
33      */
34     public Class<? extends TYPE> getType() {
35         return type;
36     }
37
38     @Override
39     public int hashCode() {
40         final int prime = 31;
41         int result = 1;
42         result = prime * result + ofVersion;
43         result = prime * result + ((type == null) ? 0 : type.hashCode());
44         return result;
45     }
46
47     @Override
48     public boolean equals(Object obj) {
49         if (this == obj)
50             return true;
51         if (obj == null)
52             return false;
53         if (getClass() != obj.getClass())
54             return false;
55         TypeVersionKey<?> other = (TypeVersionKey<?>) obj;
56         if (ofVersion != other.ofVersion)
57             return false;
58         if (type == null) {
59             if (other.type != null)
60                 return false;
61         } else if (!type.equals(other.type))
62             return false;
63         return true;
64     }
65
66 }