Clean up instance checks and casts
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / MatchEntrySerializerKeyImpl.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.impl.protocol.serialization.match;
10
11 import org.opendaylight.openflowplugin.api.openflow.protocol.serialization.MatchEntrySerializerKey;
12
13 public class MatchEntrySerializerKeyImpl implements MatchEntrySerializerKey {
14
15     private final short version;
16     private final int oxmClass;
17     private final int oxmField;
18
19     /**
20      * Create new instance of MatchEntrySerializerKeyImpl.
21      *
22      * @param version openflow version
23      * @param oxmClass match entry oxm class
24      * @param oxmField match entry field code
25      */
26     public MatchEntrySerializerKeyImpl(final short version, final int oxmClass, final int oxmField) {
27         this.version = version;
28         this.oxmClass = oxmClass;
29         this.oxmField = oxmField;
30     }
31
32     @Override
33     public int hashCode() {
34         final int prime = 31;
35         int result = 1;
36         result = prime * result + oxmClass;
37         result = prime * result + oxmField;
38         result = prime * result + version;
39         return result;
40     }
41
42     @Override
43     public boolean equals(Object obj) {
44         if (this == obj) {
45             return true;
46         }
47
48         if (obj == null) {
49             return false;
50         }
51
52         if (!(obj instanceof MatchEntrySerializerKeyImpl)) {
53             return false;
54         }
55
56         final MatchEntrySerializerKeyImpl other = (MatchEntrySerializerKeyImpl) obj;
57
58
59         return oxmClass == other.oxmClass
60                 && oxmField == other.oxmField
61                 && version == other.version;
62     }
63
64
65     @Override
66     public String toString() {
67         return "version: " + version
68                 + " oxmClass:" + oxmClass
69                 + " oxmField: " + oxmField;
70     }
71
72 }