:Revise behaviour to return empty list
Change-Id: I5e1dfa80cab1b8a8c5a245421be38b44e629cab3
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriver.java b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriver.java
index 7ed674b..6ffdbee 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriver.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriver.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.driver;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -65,7 +66,7 @@
Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours,
Map<String, String> properties) {
this.name = checkNotNull(name, "Name cannot be null");
- this.parents = parents == null || parents.isEmpty() ? null : parents;
+ this.parents = parents == null ? ImmutableList.of() : ImmutableList.copyOf(parents);
this.manufacturer = checkNotNull(manufacturer, "Manufacturer cannot be null");
this.hwVersion = checkNotNull(hwVersion, "HW version cannot be null");
this.swVersion = checkNotNull(swVersion, "SW version cannot be null");
@@ -77,6 +78,7 @@
public Driver merge(Driver other) {
checkArgument(parents == null || Objects.equals(parent(), other.parent()),
"Parent drivers are not the same");
+
// Merge the behaviours.
Map<Class<? extends Behaviour>, Class<? extends Behaviour>>
behaviours = Maps.newHashMap();
@@ -126,7 +128,7 @@
@Override
public Driver parent() {
- return parents == null ? null : parents.get(0);
+ return parents.isEmpty() ? null : parents.get(0);
}
@Override
diff --git a/core/api/src/main/java/org/onosproject/net/driver/Driver.java b/core/api/src/main/java/org/onosproject/net/driver/Driver.java
index 7af83b4..d8f6f3c 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/Driver.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/Driver.java
@@ -45,12 +45,11 @@
@Deprecated
Driver parent();
- // TODO should revise behaviour to return empty List when driver has no parent
/**
* Returns all the parent drivers from which this driver inherits behaviours
* and properties.
*
- * @return list of parent drivers; null if driver has no parent
+ * @return list of parent drivers
*/
List<Driver> parents();
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
index 330ec8b..2062951 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
@@ -41,6 +41,7 @@
ImmutableMap.of("foo", "bar"));
assertEquals("incorrect name", "foo.bar", ddc.name());
assertEquals("incorrect parent", ddp, ddc.parent());
+ assertEquals("incorrect empty parent", ImmutableList.of(), ddp.parents());
assertEquals("incorrect mfr", "Circus", ddc.manufacturer());
assertEquals("incorrect hw", "lux", ddc.hwVersion());
assertEquals("incorrect sw", "1.2a", ddc.swVersion());