Merge "Fix minor bug in FRM proactive flow code path"
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / ForwardingMode.java
1 package org.opendaylight.controller.sal.core;
2
3 import javax.xml.bind.annotation.XmlElement;
4 import javax.xml.bind.annotation.XmlRootElement;
5
6 /**
7  * The class represents the forwarding mode property of a node.
8  */
9 @XmlRootElement
10 @SuppressWarnings("serial")
11 public class ForwardingMode extends Property {
12     @XmlElement
13     private final int modeValue;
14     public static final int REACTIVE_FORWARDING = 0;
15     public static final int PROACTIVE_FORWARDING = 1;
16     public static final String name = "mode";
17
18     /*
19      * Private constructor used for JAXB mapping
20      */
21     private ForwardingMode() {
22         super(name);
23         this.modeValue = REACTIVE_FORWARDING;
24     }
25
26     public ForwardingMode(int mode) {
27         super(name);
28         this.modeValue = mode;
29     }
30
31     public int getValue() {
32         return this.modeValue;
33     }
34
35     public boolean isProactive() {
36         return (modeValue == ForwardingMode.PROACTIVE_FORWARDING);
37     }
38
39     public boolean isValid() {
40         return ((modeValue >= 0) && (modeValue <= 1));
41     }
42
43     @Override
44     public ForwardingMode clone() {
45         return new ForwardingMode(this.modeValue);
46     }
47
48     @Override
49     public int hashCode() {
50         final int prime = 31;
51         int result = super.hashCode();
52         result = prime * result + modeValue;
53         return result;
54     }
55
56     @Override
57     public boolean equals(Object obj) {
58         if (this == obj)
59             return true;
60         if (!super.equals(obj))
61             return false;
62         if (getClass() != obj.getClass())
63             return false;
64         ForwardingMode other = (ForwardingMode) obj;
65         if (modeValue != other.modeValue)
66             return false;
67         return true;
68     }
69
70     @Override
71     public String toString() {
72         return "Mode[" + modeValue + "]";
73     }
74 }