BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / core / ForwardingMode.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.controller.sal.core;
9
10 import javax.xml.bind.annotation.XmlAccessType;
11 import javax.xml.bind.annotation.XmlAccessorType;
12 import javax.xml.bind.annotation.XmlElement;
13 import javax.xml.bind.annotation.XmlRootElement;
14
15 /**
16  * The class represents the forwarding mode property of a node.
17  */
18 @XmlRootElement
19 @XmlAccessorType(XmlAccessType.NONE)
20 @SuppressWarnings("serial")
21 public class ForwardingMode extends Property {
22     @XmlElement(name="value")
23     private final int modeValue;
24     public static final int REACTIVE_FORWARDING = 0;
25     public static final int PROACTIVE_FORWARDING = 1;
26     public static final String name = "forwarding";
27
28     /*
29      * Private constructor used for JAXB mapping
30      */
31     private ForwardingMode() {
32         super(name);
33         this.modeValue = REACTIVE_FORWARDING;
34     }
35
36     public ForwardingMode(int mode) {
37         super(name);
38         this.modeValue = mode;
39     }
40
41     public int getValue() {
42         return this.modeValue;
43     }
44
45     public boolean isProactive() {
46         return (modeValue == ForwardingMode.PROACTIVE_FORWARDING);
47     }
48
49     public boolean isValid() {
50         return ((modeValue >= 0) && (modeValue <= 1));
51     }
52
53     @Override
54     public ForwardingMode clone() {
55         return new ForwardingMode(this.modeValue);
56     }
57
58     @Override
59     public int hashCode() {
60         final int prime = 31;
61         int result = super.hashCode();
62         result = prime * result + modeValue;
63         return result;
64     }
65
66     @Override
67     public boolean equals(Object obj) {
68         if (this == obj)
69             return true;
70         if (!super.equals(obj))
71             return false;
72         if (getClass() != obj.getClass())
73             return false;
74         ForwardingMode other = (ForwardingMode) obj;
75         if (modeValue != other.modeValue)
76             return false;
77         return true;
78     }
79
80     @Override
81     public String toString() {
82         return "Mode[" + modeValue + "]";
83     }
84
85     @Override
86     public String getStringValue() {
87         return (modeValue == ForwardingMode.PROACTIVE_FORWARDING) ? "Proactive" : "Reactive";
88     }
89 }