Sho SHIMIZU
Committed by Ray Milkey

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
...@@ -22,7 +22,6 @@ import java.util.HashSet; ...@@ -22,7 +22,6 @@ import java.util.HashSet;
22 import java.util.List; 22 import java.util.List;
23 import java.util.ArrayList; 23 import java.util.ArrayList;
24 import java.util.Arrays; 24 import java.util.Arrays;
25 -import java.util.Collection;
26 import java.util.Collections; 25 import java.util.Collections;
27 26
28 import org.apache.karaf.shell.commands.Argument; 27 import org.apache.karaf.shell.commands.Argument;
...@@ -102,7 +101,7 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -102,7 +101,7 @@ public class ResourcesCommand extends AbstractShellCommand {
102 101
103 private void printResource(Resource resource, int level) { 102 private void printResource(Resource resource, int level) {
104 // TODO add an option to show only available resource 103 // TODO add an option to show only available resource
105 - Collection<Resource> children = resourceService.getRegisteredResources(resource); 104 + Set<Resource> children = resourceService.getRegisteredResources(resource);
106 105
107 if (resource.equals(Resource.ROOT)) { 106 if (resource.equals(Resource.ROOT)) {
108 print("ROOT"); 107 print("ROOT");
......
...@@ -23,6 +23,7 @@ import java.util.Arrays; ...@@ -23,6 +23,7 @@ import java.util.Arrays;
23 import java.util.Collection; 23 import java.util.Collection;
24 import java.util.List; 24 import java.util.List;
25 import java.util.Optional; 25 import java.util.Optional;
26 +import java.util.Set;
26 27
27 import static com.google.common.base.Preconditions.checkNotNull; 28 import static com.google.common.base.Preconditions.checkNotNull;
28 29
...@@ -162,7 +163,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource ...@@ -162,7 +163,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
162 * @return available resources under the specified resource 163 * @return available resources under the specified resource
163 */ 164 */
164 // TODO: need to change the argument type to ResourceId or ResourceId.Discrete 165 // TODO: need to change the argument type to ResourceId or ResourceId.Discrete
165 - Collection<Resource> getAvailableResources(Resource parent); 166 + Set<Resource> getAvailableResources(Resource parent);
166 167
167 /** 168 /**
168 * Returns resources registered under the specified resource. 169 * Returns resources registered under the specified resource.
...@@ -171,7 +172,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource ...@@ -171,7 +172,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
171 * @return registered resources under the specified resource 172 * @return registered resources under the specified resource
172 */ 173 */
173 // TODO: need to change the argument type to ResourceId or ResourceId.Discrete 174 // TODO: need to change the argument type to ResourceId or ResourceId.Discrete
174 - Collection<Resource> getRegisteredResources(Resource parent); 175 + Set<Resource> getRegisteredResources(Resource parent);
175 176
176 177
177 /** 178 /**
......
...@@ -20,6 +20,7 @@ import org.onosproject.store.Store; ...@@ -20,6 +20,7 @@ import org.onosproject.store.Store;
20 20
21 import java.util.Collection; 21 import java.util.Collection;
22 import java.util.List; 22 import java.util.List;
23 +import java.util.Set;
23 24
24 /** 25 /**
25 * Service for storing resource and consumer information. 26 * Service for storing resource and consumer information.
...@@ -104,13 +105,13 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat ...@@ -104,13 +105,13 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
104 Collection<Resource> getResources(ResourceConsumer consumer); 105 Collection<Resource> getResources(ResourceConsumer consumer);
105 106
106 /** 107 /**
107 - * Returns a collection of the child resources of the specified parent. 108 + * Returns a set of the child resources of the specified parent.
108 * 109 *
109 * @param parent parent of the resource to be returned 110 * @param parent parent of the resource to be returned
110 - * @return a collection of the child resources of the specified resource 111 + * @return a set of the child resources of the specified resource
111 */ 112 */
112 // TODO: need to change the argument type to ResourceId or ResourceId.Discrete 113 // TODO: need to change the argument type to ResourceId or ResourceId.Discrete
113 - Collection<Resource> getChildResources(Resource parent); 114 + Set<Resource> getChildResources(Resource parent);
114 115
115 /** 116 /**
116 * Returns a collection of the resources which are children of the specified parent and 117 * Returns a collection of the resources which are children of the specified parent and
......
...@@ -38,6 +38,7 @@ import org.slf4j.Logger; ...@@ -38,6 +38,7 @@ import org.slf4j.Logger;
38 38
39 import java.util.Collection; 39 import java.util.Collection;
40 import java.util.List; 40 import java.util.List;
41 +import java.util.Set;
41 import java.util.stream.Collectors; 42 import java.util.stream.Collectors;
42 43
43 import static com.google.common.base.Preconditions.checkNotNull; 44 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -147,18 +148,18 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent ...@@ -147,18 +148,18 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
147 } 148 }
148 149
149 @Override 150 @Override
150 - public Collection<Resource> getAvailableResources(Resource parent) { 151 + public Set<Resource> getAvailableResources(Resource parent) {
151 checkNotNull(parent); 152 checkNotNull(parent);
152 153
153 - Collection<Resource> children = store.getChildResources(parent); 154 + Set<Resource> children = store.getChildResources(parent);
154 return children.stream() 155 return children.stream()
155 // We access store twice in this method, then the store may be updated by others 156 // We access store twice in this method, then the store may be updated by others
156 .filter(store::isAvailable) 157 .filter(store::isAvailable)
157 - .collect(Collectors.toList()); 158 + .collect(Collectors.toSet());
158 } 159 }
159 160
160 @Override 161 @Override
161 - public Collection<Resource> getRegisteredResources(Resource parent) { 162 + public Set<Resource> getRegisteredResources(Resource parent) {
162 checkNotNull(parent); 163 checkNotNull(parent);
163 164
164 return store.getChildResources(parent); 165 return store.getChildResources(parent);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.intent.impl.compiler; 16 package org.onosproject.net.intent.impl.compiler;
17 17
18 import com.google.common.collect.ImmutableList; 18 import com.google.common.collect.ImmutableList;
19 +import com.google.common.collect.ImmutableSet;
19 import org.onlab.packet.MplsLabel; 20 import org.onlab.packet.MplsLabel;
20 import org.onlab.packet.VlanId; 21 import org.onlab.packet.VlanId;
21 import org.onosproject.net.newresource.ResourceAllocation; 22 import org.onosproject.net.newresource.ResourceAllocation;
...@@ -30,6 +31,7 @@ import java.util.HashSet; ...@@ -30,6 +31,7 @@ import java.util.HashSet;
30 import java.util.List; 31 import java.util.List;
31 import java.util.Map; 32 import java.util.Map;
32 import java.util.Optional; 33 import java.util.Optional;
34 +import java.util.Set;
33 import java.util.stream.Collectors; 35 import java.util.stream.Collectors;
34 36
35 class MockResourceService implements ResourceService { 37 class MockResourceService implements ResourceService {
...@@ -92,16 +94,16 @@ class MockResourceService implements ResourceService { ...@@ -92,16 +94,16 @@ class MockResourceService implements ResourceService {
92 } 94 }
93 95
94 @Override 96 @Override
95 - public Collection<Resource> getAvailableResources(Resource parent) { 97 + public Set<Resource> getAvailableResources(Resource parent) {
96 98
97 Collection<Resource> resources = new HashSet<Resource>(); 99 Collection<Resource> resources = new HashSet<Resource>();
98 resources.add(parent.child(VlanId.vlanId((short) 10))); 100 resources.add(parent.child(VlanId.vlanId((short) 10)));
99 resources.add(parent.child(MplsLabel.mplsLabel(10))); 101 resources.add(parent.child(MplsLabel.mplsLabel(10)));
100 - return ImmutableList.copyOf(resources); 102 + return ImmutableSet.copyOf(resources);
101 } 103 }
102 104
103 @Override 105 @Override
104 - public Collection<Resource> getRegisteredResources(Resource parent) { 106 + public Set<Resource> getRegisteredResources(Resource parent) {
105 return getAvailableResources(parent); 107 return getAvailableResources(parent);
106 } 108 }
107 109
......
...@@ -17,6 +17,7 @@ package org.onosproject.store.newresource.impl; ...@@ -17,6 +17,7 @@ package org.onosproject.store.newresource.impl;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 import com.google.common.collect.ImmutableList; 19 import com.google.common.collect.ImmutableList;
20 +import com.google.common.collect.ImmutableSet;
20 import com.google.common.collect.Maps; 21 import com.google.common.collect.Maps;
21 import org.apache.felix.scr.annotations.Activate; 22 import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
...@@ -389,16 +390,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -389,16 +390,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
389 } 390 }
390 391
391 @Override 392 @Override
392 - public Collection<Resource> getChildResources(Resource parent) { 393 + public Set<Resource> getChildResources(Resource parent) {
393 checkNotNull(parent); 394 checkNotNull(parent);
394 if (!(parent instanceof DiscreteResource)) { 395 if (!(parent instanceof DiscreteResource)) {
395 // only Discrete resource can have child resource 396 // only Discrete resource can have child resource
396 - return ImmutableList.of(); 397 + return ImmutableSet.of();
397 } 398 }
398 399
399 Versioned<Set<Resource>> children = childMap.get((DiscreteResource) parent); 400 Versioned<Set<Resource>> children = childMap.get((DiscreteResource) parent);
400 if (children == null) { 401 if (children == null) {
401 - return ImmutableList.of(); 402 + return ImmutableSet.of();
402 } 403 }
403 404
404 return children.value(); 405 return children.value();
......