38b8cd498d075199a3b9f2d7ad294e757e317ed3
[openflowjava.git] / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / keys / ActionSerializerKey.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.api.keys;\r
10 \r
11 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase;\r
14 \r
15 /**\r
16  * @author michal.polkorab\r
17  * @param <TYPE> action type\r
18  */\r
19 public class ActionSerializerKey<TYPE extends ActionBase> extends MessageTypeKey<Action> {\r
20 \r
21     private Class<TYPE> actionType;\r
22     private Long experimenterId;\r
23 \r
24     /**\r
25      * @param msgVersion protocol wire version\r
26      * @param actionType type of action\r
27      * @param experimenterId experimenter / vendor ID\r
28      */\r
29     public ActionSerializerKey(short msgVersion, Class<TYPE> actionType,\r
30             Long experimenterId) {\r
31         super(msgVersion, Action.class);\r
32         this.actionType = actionType;\r
33         this.experimenterId = experimenterId;\r
34     }\r
35 \r
36     @Override\r
37     public int hashCode() {\r
38         final int prime = 31;\r
39         int result = super.hashCode();\r
40         result = prime * result + ((actionType == null) ? 0 : actionType.hashCode());\r
41         result = prime * result + ((experimenterId == null) ? 0 : experimenterId.hashCode());\r
42         return result;\r
43     }\r
44 \r
45     @Override\r
46     public boolean equals(Object obj) {\r
47         if (this == obj)\r
48             return true;\r
49         if (!super.equals(obj))\r
50             return false;\r
51         if (!(obj instanceof ActionSerializerKey))\r
52             return false;\r
53         ActionSerializerKey<?> other = (ActionSerializerKey<?>) obj;\r
54         if (actionType == null) {\r
55             if (other.actionType != null)\r
56                 return false;\r
57         } else if (!actionType.equals(other.actionType))\r
58             return false;\r
59         if (experimenterId == null) {\r
60             if (other.experimenterId != null)\r
61                 return false;\r
62         } else if (!experimenterId.equals(other.experimenterId))\r
63             return false;\r
64         return true;\r
65     }\r
66 \r
67     @Override\r
68     public String toString() {\r
69         return super.toString() + " action type: " + actionType.getName() + " experimenterID: " + experimenterId;\r
70     }\r
71 }