Use more concrete type for return value
Same resources are not allowed for a parent and Set is more suitable than
Collection
Change-Id: Ib45179819d81376678bf8949864b12b5bd721085
diff --git a/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java b/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java
index c64518c..37faa0b 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java
@@ -22,7 +22,6 @@
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import org.apache.karaf.shell.commands.Argument;
@@ -102,7 +101,7 @@
private void printResource(Resource resource, int level) {
// TODO add an option to show only available resource
- Collection<Resource> children = resourceService.getRegisteredResources(resource);
+ Set<Resource> children = resourceService.getRegisteredResources(resource);
if (resource.equals(Resource.ROOT)) {
print("ROOT");
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java
index e0c7fd7..6dcd7ef 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java
@@ -23,6 +23,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -162,7 +163,7 @@
* @return available resources under the specified resource
*/
// TODO: need to change the argument type to ResourceId or ResourceId.Discrete
- Collection<Resource> getAvailableResources(Resource parent);
+ Set<Resource> getAvailableResources(Resource parent);
/**
* Returns resources registered under the specified resource.
@@ -171,7 +172,7 @@
* @return registered resources under the specified resource
*/
// TODO: need to change the argument type to ResourceId or ResourceId.Discrete
- Collection<Resource> getRegisteredResources(Resource parent);
+ Set<Resource> getRegisteredResources(Resource parent);
/**
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
index 321c861..cca8ed0 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
@@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.List;
+import java.util.Set;
/**
* Service for storing resource and consumer information.
@@ -104,13 +105,13 @@
Collection<Resource> getResources(ResourceConsumer consumer);
/**
- * Returns a collection of the child resources of the specified parent.
+ * Returns a set of the child resources of the specified parent.
*
* @param parent parent of the resource to be returned
- * @return a collection of the child resources of the specified resource
+ * @return a set of the child resources of the specified resource
*/
// TODO: need to change the argument type to ResourceId or ResourceId.Discrete
- Collection<Resource> getChildResources(Resource parent);
+ Set<Resource> getChildResources(Resource parent);
/**
* Returns a collection of the resources which are children of the specified parent and
diff --git a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
index b4badb8..517ee10 100644
--- a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
@@ -38,6 +38,7 @@
import java.util.Collection;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -147,18 +148,18 @@
}
@Override
- public Collection<Resource> getAvailableResources(Resource parent) {
+ public Set<Resource> getAvailableResources(Resource parent) {
checkNotNull(parent);
- Collection<Resource> children = store.getChildResources(parent);
+ Set<Resource> children = store.getChildResources(parent);
return children.stream()
// We access store twice in this method, then the store may be updated by others
.filter(store::isAvailable)
- .collect(Collectors.toList());
+ .collect(Collectors.toSet());
}
@Override
- public Collection<Resource> getRegisteredResources(Resource parent) {
+ public Set<Resource> getRegisteredResources(Resource parent) {
checkNotNull(parent);
return store.getChildResources(parent);
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java
index 7e3beca..c985882 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java
@@ -16,6 +16,7 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onosproject.net.newresource.ResourceAllocation;
@@ -30,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
class MockResourceService implements ResourceService {
@@ -92,16 +94,16 @@
}
@Override
- public Collection<Resource> getAvailableResources(Resource parent) {
+ public Set<Resource> getAvailableResources(Resource parent) {
Collection<Resource> resources = new HashSet<Resource>();
resources.add(parent.child(VlanId.vlanId((short) 10)));
resources.add(parent.child(MplsLabel.mplsLabel(10)));
- return ImmutableList.copyOf(resources);
+ return ImmutableSet.copyOf(resources);
}
@Override
- public Collection<Resource> getRegisteredResources(Resource parent) {
+ public Set<Resource> getRegisteredResources(Resource parent) {
return getAvailableResources(parent);
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
index f13481c..defc955 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
@@ -17,6 +17,7 @@
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -389,16 +390,16 @@
}
@Override
- public Collection<Resource> getChildResources(Resource parent) {
+ public Set<Resource> getChildResources(Resource parent) {
checkNotNull(parent);
if (!(parent instanceof DiscreteResource)) {
// only Discrete resource can have child resource
- return ImmutableList.of();
+ return ImmutableSet.of();
}
Versioned<Set<Resource>> children = childMap.get((DiscreteResource) parent);
if (children == null) {
- return ImmutableList.of();
+ return ImmutableSet.of();
}
return children.value();