SAL Actions Property is OF1.0 specific
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / NodeConnector.java
index 85a6c22c568cd97894c420c2850eeb848a6a1b14..d58be6771bb034d5cf7738b1eaa5c47caa4ec4ce 100644 (file)
 package org.opendaylight.controller.sal.core;
 
 import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
-import org.opendaylight.controller.sal.utils.INodeFactory;
 import org.opendaylight.controller.sal.utils.ServiceHelper;
 
 /**
@@ -96,42 +97,42 @@ public class NodeConnector implements Serializable {
         // for Unit Testing coverage
         static {
             compatibleType.put(CONTROLLER,
-                               new ImmutablePair(Short.class, null));
+                               new ImmutablePair<Class<? extends Object>, String>(Short.class, null));
             compatibleType.put(ALL,
-                               new ImmutablePair(Short.class, null));
+                               new ImmutablePair<Class<? extends Object>, String>(Short.class, null));
             compatibleType.put(SWSTACK,
-                               new ImmutablePair(Short.class, null));
+                               new ImmutablePair<Class<? extends Object>, String>(Short.class, null));
             compatibleType.put(HWPATH,
-                               new ImmutablePair(Short.class, null));
+                               new ImmutablePair<Class<? extends Object>, String>(Short.class, null));
             compatibleType.put(OPENFLOW,
-                               new ImmutablePair(Short.class,
+                               new ImmutablePair<Class<? extends Object>, String>(Short.class,
                                                  Node.NodeIDType.OPENFLOW));
             compatibleType.put(PCEP,
-                               new ImmutablePair(Integer.class,
+                               new ImmutablePair<Class<? extends Object>, String>(Integer.class,
                                                  Node.NodeIDType.PCEP));
             compatibleType.put(ONEPK,
-                               new ImmutablePair(String.class,
+                               new ImmutablePair<Class<? extends Object>, String>(String.class,
                                                  Node.NodeIDType.ONEPK));
             compatibleType.put(OPENFLOW2PCEP,
-                               new ImmutablePair(Short.class,
+                               new ImmutablePair<Class<? extends Object>, String>(Short.class,
                                                  Node.NodeIDType.OPENFLOW));
             compatibleType.put(OPENFLOW2ONEPK,
-                               new ImmutablePair(Short.class,
+                               new ImmutablePair<Class<? extends Object>, String>(Short.class,
                                                  Node.NodeIDType.OPENFLOW));
             compatibleType.put(PCEP2OPENFLOW,
-                               new ImmutablePair(Integer.class,
+                               new ImmutablePair<Class<? extends Object>, String>(Integer.class,
                                                  Node.NodeIDType.PCEP));
             compatibleType.put(PCEP2ONEPK,
-                               new ImmutablePair(Integer.class,
+                               new ImmutablePair<Class<? extends Object>, String>(Integer.class,
                                                  Node.NodeIDType.PCEP));
             compatibleType.put(ONEPK2OPENFLOW,
-                               new ImmutablePair(String.class,
+                               new ImmutablePair<Class<? extends Object>, String>(String.class,
                                                  Node.NodeIDType.ONEPK));
             compatibleType.put(ONEPK2PCEP,
-                               new ImmutablePair(String.class,
+                               new ImmutablePair<Class<? extends Object>, String>(String.class,
                                                  Node.NodeIDType.ONEPK));
             compatibleType.put(PRODUCTION,
-                               new ImmutablePair(String.class,
+                               new ImmutablePair<Class<? extends Object>, String>(String.class,
                                                  Node.NodeIDType.PRODUCTION));
         }
 
@@ -185,7 +186,7 @@ public class NodeConnector implements Serializable {
             if (compatibleType.get(type) != null) {
                 return false;
             }  else {
-                compatibleType.put(type, new ImmutablePair(compatibleID,
+                compatibleType.put(type, new ImmutablePair<Class<? extends Object>, String>(compatibleID,
                                                            compatibleNode));
                 return true;
             }
@@ -339,6 +340,7 @@ public class NodeConnector implements Serializable {
      *
      * @param type of node to be set
      */
+    @SuppressWarnings("unused")
     private void setType(String type) {
         this.nodeConnectorType = type;
         if (this.nodeConnectorIDString != null) {
@@ -372,6 +374,7 @@ public class NodeConnector implements Serializable {
      *
      * @param nodeConnectorIDString String representation for NodeConnectorID
      */
+    @SuppressWarnings("unused")
     private void setNodeConnectorIDString(String IDStr) {
         this.nodeConnectorIDString = IDStr;
         if (this.nodeConnectorType != null) {
@@ -408,28 +411,37 @@ public class NodeConnector 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;
+        }
         NodeConnector other = (NodeConnector) obj;
         if (nodeConnectorID == null) {
-            if (other.nodeConnectorID != null)
+            if (other.nodeConnectorID != null) {
                 return false;
-        } else if (!nodeConnectorID.equals(other.nodeConnectorID))
+            }
+        } else if (!nodeConnectorID.equals(other.nodeConnectorID)) {
             return false;
+        }
         if (nodeConnectorNode == null) {
-            if (other.nodeConnectorNode != null)
+            if (other.nodeConnectorNode != null) {
                 return false;
-        } else if (!nodeConnectorNode.equals(other.nodeConnectorNode))
+            }
+        } else if (!nodeConnectorNode.equals(other.nodeConnectorNode)) {
             return false;
+        }
         if (nodeConnectorType == null) {
-            if (other.nodeConnectorType != null)
+            if (other.nodeConnectorType != null) {
                 return false;
-        } else if (!nodeConnectorType.equals(other.nodeConnectorType))
+            }
+        } else if (!nodeConnectorType.equals(other.nodeConnectorType)) {
             return false;
+        }
         return true;
     }
 
@@ -454,9 +466,9 @@ public class NodeConnector implements Serializable {
             .equals(NodeConnectorIDType.SWSTACK) ||
             this.nodeConnectorType
             .equals(NodeConnectorIDType.HWPATH)) {
-            return this.nodeConnectorType.toString();
+            return this.nodeConnectorType;
         } else {
-            return this.nodeConnectorType.toString() + "|"
+            return this.nodeConnectorType + "|"
                     + this.nodeConnectorID.toString();
         }
     }
@@ -484,6 +496,27 @@ public class NodeConnector implements Serializable {
         return fromStringNoNode(parts[0], n);
     }
 
+    /**
+     * return a set of NodeConnector from a collection of string
+     *
+     * @param stringCollection Collection of String object to be parsed as a NodeConnector
+     *
+     * @return the Set of unique NodeConnector objects if parse is successful, empty Set otherwise
+     */
+    public static Set<NodeConnector> fromString(Collection<String> stringCollection) {
+        Set<NodeConnector> set = new HashSet<NodeConnector>();
+        if (stringCollection != null) {
+
+            for (String str : stringCollection) {
+                NodeConnector nodeConnector = NodeConnector.fromString(str);
+                if (nodeConnector != null) {
+                    set.add(nodeConnector);
+                }
+            }
+        }
+        return set;
+    }
+
     /**
      * return a NodeConnector from a string not containing explicitly
      * the Node portion which has to be supplied as parameter
@@ -609,8 +642,9 @@ public class NodeConnector implements Serializable {
             //The protocol plugin being used depends on typeStr.
             INodeConnectorFactory f = (INodeConnectorFactory) ServiceHelper
                     .getGlobalInstance(INodeConnectorFactory.class, new NodeConnector(), "(protocolName="+typeStr+")");
-            if(f==null)
+            if(f==null) {
                 return null;
+            }
             return f.fromStringNoNode(typeStr, IDStr, n);
         }
     }