Sho SHIMIZU
Committed by Gerrit Code Review

Save memory consumption by avoding unnecessary instantiation

Change-Id: I7ce66c11136653fabc490aa7f33fdadf4454d2cc
Showing 18 changed files with 73 additions and 73 deletions
......@@ -18,7 +18,7 @@ package org.onosproject.segmentrouting.grouphandler;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
......@@ -95,8 +95,8 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
new GroupBucketIdentifier(label, sp);
PolicyGroupIdentifier key = new
PolicyGroupIdentifier(id,
Arrays.asList(param),
Arrays.asList(bucketId));
Collections.singletonList(param),
Collections.singletonList(bucketId));
TrafficTreatment.Builder tBuilder =
DefaultTrafficTreatment.builder();
tBuilder.setOutput(sp)
......@@ -122,8 +122,8 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
previousGroupkey);
PolicyGroupIdentifier key = new
PolicyGroupIdentifier(id,
Arrays.asList(param),
Arrays.asList(bucketId));
Collections.singletonList(param),
Collections.singletonList(bucketId));
// Add to group dependency list
dependentGroups.put(previousGroupkey, key);
previousGroupkey = key;
......@@ -283,8 +283,8 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
new GroupBucketIdentifier(label, sp);
PolicyGroupIdentifier key = new
PolicyGroupIdentifier(id,
Arrays.asList(param),
Arrays.asList(bucketId));
Collections.singletonList(param),
Collections.singletonList(bucketId));
previousGroupkey = key;
} else {
// Intermediate Groups
......@@ -293,8 +293,8 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
previousGroupkey);
PolicyGroupIdentifier key = new
PolicyGroupIdentifier(id,
Arrays.asList(param),
Arrays.asList(bucketId));
Collections.singletonList(param),
Collections.singletonList(bucketId));
previousGroupkey = key;
}
}
......@@ -348,4 +348,4 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
}
}
}
\ No newline at end of file
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.net.intent;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.onosproject.net.ConnectPoint;
......@@ -93,7 +94,7 @@ public class PathIntentTest extends ConnectivityIntentTest {
.appId(APPID)
.selector(MATCH)
.treatment(NOP)
.path(new DefaultPath(provider1, Arrays.asList(link1), cost))
.path(new DefaultPath(provider1, Collections.singletonList(link1), cost))
.build();
}
......
......@@ -17,8 +17,8 @@ package org.onosproject.net.group.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
......@@ -261,7 +261,7 @@ public class GroupManager
group.type(),
group.buckets());
groupOps = new GroupOperations(
Arrays.asList(groupAddOp));
Collections.singletonList(groupAddOp));
groupProvider.performGroupOperation(group.deviceId(), groupOps);
break;
......@@ -273,7 +273,7 @@ public class GroupManager
group.type(),
group.buckets());
groupOps = new GroupOperations(
Arrays.asList(groupModifyOp));
Collections.singletonList(groupModifyOp));
groupProvider.performGroupOperation(group.deviceId(), groupOps);
break;
......@@ -284,7 +284,7 @@ public class GroupManager
createDeleteGroupOperation(group.id(),
group.type());
groupOps = new GroupOperations(
Arrays.asList(groupDeleteOp));
Collections.singletonList(groupDeleteOp));
groupProvider.performGroupOperation(group.deviceId(), groupOps);
break;
......@@ -335,7 +335,7 @@ public class GroupManager
group.type(),
group.buckets());
GroupOperations groupOps = new GroupOperations(
Arrays.asList(groupAddOp));
Collections.singletonList(groupAddOp));
gp.performGroupOperation(group.deviceId(), groupOps);
break;
default:
......
......@@ -44,7 +44,7 @@ import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.resource.LinkResourceAllocations;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -104,7 +104,7 @@ public class LinkCollectionIntentCompiler implements IntentCompiler<LinkCollecti
for (DeviceId deviceId: outputPorts.keys()) {
rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId)));
}
return Arrays.asList(new FlowRuleIntent(appId, rules, intent.resources()));
return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
}
private List<FlowRule> createRules(LinkCollectionIntent intent, DeviceId deviceId,
......
......@@ -52,7 +52,7 @@ import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceType;
import org.slf4j.Logger;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
......@@ -86,7 +86,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
LinkResourceAllocations allocations = assignMplsLabel(intent);
List<FlowRule> rules = generateRules(intent, allocations);
return Arrays.asList(new FlowRuleIntent(appId, rules, intent.resources()));
return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
}
@Activate
......
......@@ -15,7 +15,7 @@
*/
package org.onosproject.net.intent.impl.compiler;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -110,7 +110,7 @@ public class MultiPointToSinglePointIntentCompiler
.constraints(intent.constraints())
.build();
return Arrays.asList(result);
return Collections.singletonList(result);
}
/**
......
......@@ -46,7 +46,7 @@ import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceType;
import org.onosproject.net.topology.TopologyService;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
......@@ -88,7 +88,8 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte
Set<LinkResourceAllocations> resources) {
LinkResourceAllocations allocations = assignWavelength(intent);
return Arrays.asList(new FlowRuleIntent(appId, createRules(intent, allocations), intent.resources()));
return Collections.singletonList(
new FlowRuleIntent(appId, createRules(intent, allocations), intent.resources()));
}
private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) {
......
......@@ -38,7 +38,7 @@ import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.resource.LinkResourceAllocations;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
......@@ -80,7 +80,7 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
rules.add(rule);
}
return Arrays.asList(new FlowRuleIntent(appId, null, rules, intent.resources()));
return Collections.singletonList(new FlowRuleIntent(appId, null, rules, intent.resources()));
}
private FlowRule createFlowRule(TrafficSelector originalSelector, TrafficTreatment originalTreatment,
......
......@@ -15,7 +15,7 @@
*/
package org.onosproject.net.intent.impl.compiler;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -77,6 +77,6 @@ public class SinglePointToMultiPointIntentCompiler
.constraints(intent.constraints())
.build();
return Arrays.asList(result);
return Collections.singletonList(result);
}
}
......
......@@ -63,7 +63,6 @@ import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.trivial.impl.SimpleFlowRuleStore;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
......@@ -412,7 +411,7 @@ public class FlowRuleManagerTest {
@Override
public Iterable<Device> getDevices() {
return Arrays.asList(DEV);
return Collections.singletonList(DEV);
}
@Override
......
......@@ -258,9 +258,9 @@ public class GroupManagerTest {
DID,
Group.Type.SELECT,
createdGroup.buckets());
List<Group> groupEntries = Arrays.asList(createdGroup);
List<Group> groupEntries = Collections.singletonList(createdGroup);
providerService.pushGroupMetrics(DID, groupEntries);
internalListener.validateEvent(Arrays.asList(GroupEvent.Type.GROUP_ADDED));
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_ADDED));
}
// Test group add bucket operations
......@@ -296,15 +296,15 @@ public class GroupManagerTest {
addKey,
appId);
GroupBuckets updatedBuckets = new GroupBuckets(buckets);
List<GroupOperation> expectedGroupOps = Arrays.asList(
GroupOperation.createModifyGroupOperation(createdGroup.id(),
Group.Type.SELECT,
updatedBuckets));
List<GroupOperation> expectedGroupOps = Collections.singletonList(
GroupOperation.createModifyGroupOperation(createdGroup.id(),
Group.Type.SELECT,
updatedBuckets));
internalProvider.validate(DID, expectedGroupOps);
Group existingGroup = groupService.getGroup(DID, addKey);
List<Group> groupEntries = Arrays.asList(existingGroup);
List<Group> groupEntries = Collections.singletonList(existingGroup);
providerService.pushGroupMetrics(DID, groupEntries);
internalListener.validateEvent(Arrays.asList(GroupEvent.Type.GROUP_UPDATED));
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED));
}
// Test group remove bucket operations
......@@ -340,15 +340,15 @@ public class GroupManagerTest {
removeKey,
appId);
GroupBuckets updatedBuckets = new GroupBuckets(buckets);
List<GroupOperation> expectedGroupOps = Arrays.asList(
GroupOperation.createModifyGroupOperation(createdGroup.id(),
Group.Type.SELECT,
updatedBuckets));
List<GroupOperation> expectedGroupOps = Collections.singletonList(
GroupOperation.createModifyGroupOperation(createdGroup.id(),
Group.Type.SELECT,
updatedBuckets));
internalProvider.validate(DID, expectedGroupOps);
Group existingGroup = groupService.getGroup(DID, removeKey);
List<Group> groupEntries = Arrays.asList(existingGroup);
List<Group> groupEntries = Collections.singletonList(existingGroup);
providerService.pushGroupMetrics(DID, groupEntries);
internalListener.validateEvent(Arrays.asList(GroupEvent.Type.GROUP_UPDATED));
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED));
}
// Test group remove operations
......@@ -356,13 +356,13 @@ public class GroupManagerTest {
GroupKey currKey = new DefaultGroupKey("group1RemoveBuckets".getBytes());
Group existingGroup = groupService.getGroup(DID, currKey);
groupService.removeGroup(DID, currKey, appId);
List<GroupOperation> expectedGroupOps = Arrays.asList(
GroupOperation.createDeleteGroupOperation(existingGroup.id(),
Group.Type.SELECT));
List<GroupOperation> expectedGroupOps = Collections.singletonList(
GroupOperation.createDeleteGroupOperation(existingGroup.id(),
Group.Type.SELECT));
internalProvider.validate(DID, expectedGroupOps);
List<Group> groupEntries = Collections.emptyList();
providerService.pushGroupMetrics(DID, groupEntries);
internalListener.validateEvent(Arrays.asList(GroupEvent.Type.GROUP_REMOVED));
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_REMOVED));
}
/**
......@@ -423,7 +423,7 @@ public class GroupManagerTest {
createdGroup.type(),
createdGroup.buckets());
providerService.groupOperationFailed(DID, groupAddOp);
internalListener.validateEvent(Arrays.asList(GroupEvent.Type.GROUP_ADD_FAILED));
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_ADD_FAILED));
// Group Mod failure test
groupService.addGroup(newGroupDesc);
......@@ -435,7 +435,7 @@ public class GroupManagerTest {
createdGroup.type(),
createdGroup.buckets());
providerService.groupOperationFailed(DID, groupModOp);
internalListener.validateEvent(Arrays.asList(GroupEvent.Type.GROUP_UPDATE_FAILED));
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATE_FAILED));
// Group Delete failure test
groupService.addGroup(newGroupDesc);
......@@ -446,7 +446,7 @@ public class GroupManagerTest {
createDeleteGroupOperation(createdGroup.id(),
createdGroup.type());
providerService.groupOperationFailed(DID, groupDelOp);
internalListener.validateEvent(Arrays.asList(GroupEvent.Type.GROUP_REMOVE_FAILED));
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_REMOVE_FAILED));
}
......
......@@ -46,7 +46,6 @@ import org.onosproject.net.intent.Key;
import org.onosproject.net.resource.LinkResourceAllocations;
import org.onosproject.store.trivial.impl.SimpleIntentStore;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
......@@ -151,7 +150,7 @@ public class IntentManagerTest {
private static class MockInstallableIntent extends FlowRuleIntent {
public MockInstallableIntent() {
super(APPID, Arrays.asList(new MockFlowRule(100)));
super(APPID, Collections.singletonList(new MockFlowRule(100)));
}
}
......
......@@ -38,7 +38,7 @@ import org.onosproject.net.resource.BandwidthResource;
import org.onosproject.net.resource.LambdaResource;
import org.onosproject.net.resource.LinkResourceService;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.CoreMatchers.instanceOf;
......@@ -228,8 +228,8 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
final LinkResourceService resourceService =
IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
final List<Constraint> constraints = Arrays.asList(
new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0))));
final List<Constraint> constraints =
Collections.singletonList(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0))));
final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
......@@ -250,8 +250,8 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
final LinkResourceService resourceService =
IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
final List<Constraint> constraints = Arrays.asList(
new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0))));
final List<Constraint> constraints =
Collections.singletonList(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0))));
try {
final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
......@@ -274,7 +274,8 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
@Test
public void testLambdaConstrainedIntentSuccess() {
final List<Constraint> constraints = Arrays.asList(new LambdaConstraint(LambdaResource.valueOf(1)));
final List<Constraint> constraints =
Collections.singletonList(new LambdaConstraint(LambdaResource.valueOf(1)));
final LinkResourceService resourceService =
IntentTestsMocks.MockResourceService.makeLambdaResourceService(1);
......@@ -297,7 +298,8 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
@Test
public void testLambdaConstrainedIntentFailure() {
final List<Constraint> constraints = Arrays.asList(new LambdaConstraint(LambdaResource.valueOf(1)));
final List<Constraint> constraints =
Collections.singletonList(new LambdaConstraint(LambdaResource.valueOf(1)));
final LinkResourceService resourceService =
IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
try {
......
......@@ -40,7 +40,7 @@ import org.onosproject.net.intent.impl.IntentProcessor;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.Timestamp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
......@@ -70,7 +70,7 @@ public class CompilingTest {
private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
private final List<Link> links = Arrays.asList(new DefaultLink(pid, cp2, cp4, DIRECT));
private final List<Link> links = Collections.singletonList(new DefaultLink(pid, cp2, cp4, DIRECT));
private final Path path = new DefaultPath(pid, links, 10);
private PointToPointIntent input;
......@@ -118,7 +118,7 @@ public class CompilingTest {
public void testMoveToNextPhaseWithoutError() {
IntentData pending = new IntentData(input, INSTALL_REQ, version);
expect(processor.compile(input, null)).andReturn(Arrays.asList(compiled));
expect(processor.compile(input, null)).andReturn(Collections.singletonList(compiled));
replay(processor);
Compiling sut = new Compiling(processor, pending, Optional.empty());
......
......@@ -78,7 +78,6 @@ import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashSet;
......@@ -388,7 +387,7 @@ public class DistributedFlowRuleStore
@Override
public void storeFlowRule(FlowRule rule) {
storeBatch(new FlowRuleBatchOperation(
Arrays.asList(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)),
Collections.singletonList(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)),
rule.deviceId(), idGenerator.getNewId()));
}
......@@ -516,7 +515,7 @@ public class DistributedFlowRuleStore
public void deleteFlowRule(FlowRule rule) {
storeBatch(
new FlowRuleBatchOperation(
Arrays.asList(
Collections.singletonList(
new FlowRuleBatchEntry(
FlowRuleOperation.REMOVE,
rule)), rule.deviceId(), idGenerator.getNewId()));
......
......@@ -71,7 +71,6 @@ import org.onosproject.store.serializers.impl.DistributedStoreSerializers;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import java.util.Arrays;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashSet;
......@@ -378,7 +377,7 @@ public class NewDistributedFlowRuleStore
@Override
public void storeFlowRule(FlowRule rule) {
storeBatch(new FlowRuleBatchOperation(
Arrays.asList(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)),
Collections.singletonList(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)),
rule.deviceId(), idGenerator.getNewId()));
}
......@@ -484,7 +483,7 @@ public class NewDistributedFlowRuleStore
public void deleteFlowRule(FlowRule rule) {
storeBatch(
new FlowRuleBatchOperation(
Arrays.asList(
Collections.singletonList(
new FlowRuleBatchEntry(
FlowRuleOperation.REMOVE,
rule)), rule.deviceId(), idGenerator.getNewId()));
......
......@@ -20,6 +20,7 @@ import static org.onosproject.net.DeviceId.deviceId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
......@@ -307,7 +308,7 @@ public class SimpleGroupStoreTest {
PortNumber[] newNeighborPorts = {PortNumber.portNumber(41),
PortNumber.portNumber(42)};
List<PortNumber> newOutPorts = new ArrayList<PortNumber>();
newOutPorts.addAll(Arrays.asList(newNeighborPorts[0]));
newOutPorts.addAll(Collections.singletonList(newNeighborPorts[0]));
List<GroupBucket> toAddBuckets = new ArrayList<GroupBucket>();
for (PortNumber portNumber: newOutPorts) {
......
......@@ -73,7 +73,6 @@ import org.onosproject.net.group.GroupService;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
......@@ -313,7 +312,7 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour
log.warn("Unsupported Group type {}", group.type());
return;
}
GroupBuckets bucketsToAdd = new GroupBuckets(Arrays.asList(bucket));
GroupBuckets bucketsToAdd = new GroupBuckets(Collections.singletonList(bucket));
groupService.addBucketsToGroup(deviceId, key, bucketsToAdd, key, appId);
}
......@@ -339,7 +338,7 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour
log.warn("Unsupported Group type {}", group.type());
return;
}
GroupBuckets removeBuckets = new GroupBuckets(Arrays.asList(bucket));
GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
groupService.removeBucketsFromGroup(deviceId, key, removeBuckets, key, appId);
}
}
......