Merge "Remove powermock dependency from md-sal."
[controller.git] / opendaylight / forwarding / staticrouting / src / main / java / org / opendaylight / controller / forwarding / staticrouting / StaticRouteConfig.java
index 262c0170db9edc27d4885bb7fc1ca8a14e825d12..7726c0f4e78c3bc9684e0384e13da23fb1e9d9b2 100644 (file)
@@ -18,6 +18,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.opendaylight.controller.configuration.ConfigurationObject;
 import org.opendaylight.controller.sal.utils.GUIField;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
@@ -25,7 +26,7 @@ import org.opendaylight.controller.sal.utils.StatusCode;
 /**
  * This class defines all the necessary configuration information for a static route.
  */
-public class StaticRouteConfig implements Serializable {
+public class StaticRouteConfig extends ConfigurationObject implements Serializable {
     private static final long serialVersionUID = 1L;
     private static final String regexSubnet = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
             + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
@@ -103,8 +104,9 @@ public class StaticRouteConfig implements Serializable {
      * @return The string representation of the next hop address type
      */
     public String getNextHopType() {
-        if (nextHopType == null)
+        if (nextHopType == null) {
             return StaticRoute.NextHopType.IPADDRESS.toString();
+        }
         return nextHopType;
     }
 
@@ -149,20 +151,20 @@ public class StaticRouteConfig implements Serializable {
      * @return SUCCESS if the config is valid
      */
     public Status isValid() {
-        if ((name == null) || (name.trim().length() < 1)) {
+        if (!isValidResourceName(name)) {
             return new Status(StatusCode.BADREQUEST,
-                       "Invalid Static Route name");
+                        "Invalid Static Route name");
         }
         if (!isValidStaticRouteEntry()) {
             return new Status(StatusCode.BADREQUEST,
-                       "Invalid Static Route entry. Please use the " +
-                       "IPAddress/mask format. Default gateway " +
-                       "(0.0.0.0/0) is NOT supported.");
+                        "Invalid Static Route entry. Please use the " +
+                        "IPAddress/mask format. Default gateway " +
+                        "(0.0.0.0/0) is NOT supported.");
         }
         if (!isValidNextHop()) {
             return new Status(StatusCode.BADREQUEST,
-                       "Invalid NextHop IP Address configuration. " +
-                                       "Please use the X.X.X.X format.");
+                        "Invalid NextHop IP Address configuration. " +
+                                        "Please use the X.X.X.X format.");
         }
 
         return new Status(StatusCode.SUCCESS, null);
@@ -206,8 +208,9 @@ public class StaticRouteConfig implements Serializable {
         if (getNextHopType().equalsIgnoreCase(
                 StaticRoute.NextHopType.SWITCHPORT.toString())) {
             String pieces[] = nextHop.split("/");
-            if (pieces.length < 2)
+            if (pieces.length < 2) {
                 return false;
+            }
             return isValidSwitchId(pieces[0]);
         }
         return false;
@@ -218,8 +221,9 @@ public class StaticRouteConfig implements Serializable {
      * @return The IP address
      */
     public InetAddress getStaticRouteIP() {
-        if (!isValidStaticRouteEntry())
+        if (!isValidStaticRouteEntry()) {
             return null;
+        }
         InetAddress ip = null;
         try {
             ip = InetAddress.getByName(staticRoute.split("/")[0]);
@@ -337,28 +341,37 @@ public class StaticRouteConfig implements Serializable {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         StaticRouteConfig other = (StaticRouteConfig) obj;
         if (name == null) {
-            if (other.name != null)
+            if (other.name != null) {
                 return false;
-        } else if (!name.equals(other.name))
+            }
+        } else if (!name.equals(other.name)) {
             return false;
+        }
         if (nextHop == null) {
-            if (other.nextHop != null)
+            if (other.nextHop != null) {
                 return false;
-        } else if (!nextHop.equals(other.nextHop))
+            }
+        } else if (!nextHop.equals(other.nextHop)) {
             return false;
+        }
         if (staticRoute == null) {
-            if (other.staticRoute != null)
+            if (other.staticRoute != null) {
                 return false;
-        } else if (!staticRoute.equals(other.staticRoute))
+            }
+        } else if (!staticRoute.equals(other.staticRoute)) {
             return false;
+        }
         return true;
     }