Sho SHIMIZU
Committed by Brian O'Connor

Use lambda expression to simplify statements

Change-Id: Ib8ddac6e93327ade9d42984d8eba66be7047d051
Showing 23 changed files with 43 additions and 205 deletions
......@@ -300,9 +300,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService {
ChannelFactory channelFactory = new NioServerSocketChannelFactory(
newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d")),
newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d")));
ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipelineFactory pipelineFactory = () -> {
// Allocate a new session per connection
BgpSession bgpSessionHandler =
new BgpSession(BgpSessionManager.this);
......@@ -314,7 +312,6 @@ public class BgpSessionManager implements BgpInfoService, BgpService {
pipeline.addLast("BgpFrameDecoder", bgpFrameDecoder);
pipeline.addLast("BgpSession", bgpSessionHandler);
return pipeline;
}
};
InetSocketAddress listenAddress =
new InetSocketAddress(bgpPort);
......
......@@ -159,12 +159,7 @@ public class Router implements RoutingService {
bgpService.start(new InternalRouteListener());
bgpUpdatesExecutor.execute(new Runnable() {
@Override
public void run() {
doUpdatesThread();
}
});
bgpUpdatesExecutor.execute(this::doUpdatesThread);
}
@Override
......
......@@ -151,10 +151,7 @@ public class BgpSessionManagerTest {
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ChannelPipelineFactory pipelineFactory =
new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipelineFactory pipelineFactory = () -> {
// Setup the transmitting pipeline
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("TestBgpPeerFrameDecoder",
......@@ -162,7 +159,6 @@ public class BgpSessionManagerTest {
pipeline.addLast("TestBgpPeerChannelHandler",
peerChannelHandler);
return pipeline;
}
};
peerBootstrap = new ClientBootstrap(channelFactory);
......
......@@ -393,14 +393,9 @@ public class DemoInstaller implements DemoAPI {
}
private Predicate<? super Host> hasLocalMaster() {
return new Predicate<Host>() {
@Override
public boolean apply(Host host) {
return mastershipService.getLocalRole(
return host -> mastershipService.getLocalRole(
host.location().deviceId()).equals(MastershipRole.MASTER);
}
};
}
/**
......
......@@ -25,7 +25,6 @@ import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import static com.google.common.base.Preconditions.checkArgument;
......@@ -159,12 +158,8 @@ public class PathIntent extends ConnectivityIntent {
* @param links links to be validated
*/
public static void validate(List<Link> links) {
checkArgument(Iterables.all(links, new Predicate<Link>() {
@Override
public boolean apply(Link link) {
return !link.src().elementId().equals(link.dst().elementId());
}
}), "element of src and dst in a link must be different: {}", links);
checkArgument(Iterables.all(links, link -> !link.src().elementId().equals(link.dst().elementId())),
"element of src and dst in a link must be different: {}", links);
boolean adjacentSame = true;
for (int i = 0; i < links.size() - 1; i++) {
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.device;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import org.onosproject.net.Device;
......@@ -45,13 +44,7 @@ public class DeviceServiceAdapter implements DeviceService {
@Override
public Iterable<Device> getAvailableDevices() {
return FluentIterable.from(getDevices())
.filter(new Predicate<Device>() {
@Override
public boolean apply(Device input) {
return isAvailable(input.id());
}
});
.filter(input -> isAvailable(input.id()));
}
@Override
......
......@@ -49,31 +49,24 @@ public class FakeIntentManager implements TestableIntentService {
// Provides an out-of-thread simulation of intent submit life-cycle
private void executeSubmit(final Intent intent) {
registerSubclassCompilerIfNeeded(intent);
executor.execute(new Runnable() {
@Override
public void run() {
executor.execute(() -> {
try {
executeCompilingPhase(intent);
} catch (IntentException e) {
exceptions.add(e);
}
}
});
}
// Provides an out-of-thread simulation of intent withdraw life-cycle
private void executeWithdraw(final Intent intent) {
executor.execute(new Runnable() {
@Override
public void run() {
executor.execute(() -> {
try {
List<Intent> installable = getInstallable(intent.key());
executeWithdrawingPhase(intent, installable);
} catch (IntentException e) {
exceptions.add(e);
}
}
});
}
......
......@@ -79,13 +79,8 @@ public class IntentServiceTest {
service.submit(intent);
// Allow a small window of time until the intent is in the expected state
TestTools.assertAfter(GRACE_MS, new Runnable() {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.INSTALLED,
service.getIntentState(intent.key()));
}
});
TestTools.assertAfter(GRACE_MS, () ->
assertEquals("incorrect intent state", IntentState.INSTALLED, service.getIntentState(intent.key())));
// Make sure that all expected events have been emitted
validateEvents(intent, INSTALL_REQ, INSTALLED);
......@@ -100,13 +95,8 @@ public class IntentServiceTest {
service.withdraw(intent);
// Allow a small window of time until the event is in the expected state
TestTools.assertAfter(GRACE_MS, new Runnable() {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.WITHDRAWN,
service.getIntentState(intent.key()));
}
});
TestTools.assertAfter(GRACE_MS, () ->
assertEquals("incorrect intent state", IntentState.WITHDRAWN, service.getIntentState(intent.key())));
// Make sure that all expected events have been emitted
validateEvents(intent, WITHDRAWN);
......@@ -128,13 +118,8 @@ public class IntentServiceTest {
service.submit(intent);
// Allow a small window of time until the intent is in the expected state
TestTools.assertAfter(GRACE_MS, new Runnable() {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.FAILED,
service.getIntentState(intent.key()));
}
});
TestTools.assertAfter(GRACE_MS, () ->
assertEquals("incorrect intent state", IntentState.FAILED, service.getIntentState(intent.key())));
// Make sure that all expected events have been emitted
validateEvents(intent, INSTALL_REQ, FAILED);
......@@ -196,13 +181,8 @@ public class IntentServiceTest {
service.submit(intent);
// Allow some time for the intent to be compiled and installed
TestTools.assertAfter(GRACE_MS, new Runnable() {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.INSTALLED,
service.getIntentState(intent.key()));
}
});
TestTools.assertAfter(GRACE_MS, () ->
assertEquals("incorrect intent state", IntentState.INSTALLED, service.getIntentState(intent.key())));
// Make sure that now we have an implicit registration of the compiler
// under the intent subclass
......
......@@ -22,7 +22,6 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.Link.State;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
/**
......@@ -42,13 +41,7 @@ public class LinkServiceAdapter implements LinkService {
@Override
public Iterable<Link> getActiveLinks() {
return FluentIterable.from(getLinks())
.filter(new Predicate<Link>() {
@Override
public boolean apply(Link input) {
return input.state() == State.ACTIVE;
}
});
.filter(input -> input.state() == State.ACTIVE);
}
@Override
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.store.trivial;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
......@@ -134,13 +133,7 @@ public class SimpleDeviceStore
@Override
public Iterable<Device> getAvailableDevices() {
return FluentIterable.from(getDevices())
.filter(new Predicate<Device>() {
@Override
public boolean apply(Device input) {
return isAvailable(input.id());
}
});
.filter(input -> isAvailable(input.id()));
}
@Override
......
......@@ -479,31 +479,22 @@ public class SimpleDeviceStoreTest {
@Test
public final void testEvents() throws InterruptedException {
final CountDownLatch addLatch = new CountDownLatch(1);
DeviceStoreDelegate checkAdd = new DeviceStoreDelegate() {
@Override
public void notify(DeviceEvent event) {
DeviceStoreDelegate checkAdd = event -> {
assertEquals(DEVICE_ADDED, event.type());
assertDevice(DID1, SW1, event.subject());
addLatch.countDown();
}
};
final CountDownLatch updateLatch = new CountDownLatch(1);
DeviceStoreDelegate checkUpdate = new DeviceStoreDelegate() {
@Override
public void notify(DeviceEvent event) {
DeviceStoreDelegate checkUpdate = event -> {
assertEquals(DEVICE_UPDATED, event.type());
assertDevice(DID1, SW2, event.subject());
updateLatch.countDown();
}
};
final CountDownLatch removeLatch = new CountDownLatch(1);
DeviceStoreDelegate checkRemove = new DeviceStoreDelegate() {
@Override
public void notify(DeviceEvent event) {
DeviceStoreDelegate checkRemove = event -> {
assertEquals(DEVICE_REMOVED, event.type());
assertDevice(DID1, SW2, event.subject());
removeLatch.countDown();
}
};
DeviceDescription description =
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.store.trivial;
import com.google.common.base.Function;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalListener;
......@@ -162,15 +161,7 @@ public class SimpleFlowRuleStore
public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
// flatten and make iterator unmodifiable
return FluentIterable.from(getFlowTable(deviceId).values())
.transformAndConcat(
new Function<List<StoredFlowEntry>, Iterable<? extends FlowEntry>>() {
@Override
public Iterable<? extends FlowEntry> apply(
List<StoredFlowEntry> input) {
return Collections.unmodifiableList(input);
}
});
.transformAndConcat(Collections::unmodifiableList);
}
@Override
......
......@@ -55,7 +55,6 @@ import org.onosproject.net.group.StoredGroupEntry;
import org.onosproject.store.AbstractStore;
import org.slf4j.Logger;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Sets;
......@@ -188,15 +187,7 @@ public class SimpleGroupStore
public Iterable<Group> getGroups(DeviceId deviceId) {
// flatten and make iterator unmodifiable
return FluentIterable.from(getGroupKeyTable(deviceId).values())
.transform(
new Function<StoredGroupEntry, Group>() {
@Override
public Group apply(
StoredGroupEntry input) {
return input;
}
});
.transform(input -> input);
}
/**
......
......@@ -498,31 +498,22 @@ public class SimpleLinkStoreTest {
final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
final CountDownLatch addLatch = new CountDownLatch(1);
LinkStoreDelegate checkAdd = new LinkStoreDelegate() {
@Override
public void notify(LinkEvent event) {
LinkStoreDelegate checkAdd = event -> {
assertEquals(LINK_ADDED, event.type());
assertLink(linkId1, INDIRECT, event.subject());
addLatch.countDown();
}
};
final CountDownLatch updateLatch = new CountDownLatch(1);
LinkStoreDelegate checkUpdate = new LinkStoreDelegate() {
@Override
public void notify(LinkEvent event) {
LinkStoreDelegate checkUpdate = event -> {
assertEquals(LINK_UPDATED, event.type());
assertLink(linkId1, DIRECT, event.subject());
updateLatch.countDown();
}
};
final CountDownLatch removeLatch = new CountDownLatch(1);
LinkStoreDelegate checkRemove = new LinkStoreDelegate() {
@Override
public void notify(LinkEvent event) {
LinkStoreDelegate checkRemove = event -> {
assertEquals(LINK_REMOVED, event.type());
assertLink(linkId1, DIRECT, event.subject());
removeLatch.countDown();
}
};
linkStore.setDelegate(checkAdd);
......
......@@ -51,7 +51,6 @@ import org.onosproject.net.resource.link.LinkResourceRequest;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyEdge;
import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -265,9 +264,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
private Set<Path> getOpticalPaths(OpticalConnectivityIntent intent) {
// Route in WDM topology
Topology topology = topologyService.currentTopology();
LinkWeight weight = new LinkWeight() {
@Override
public double weight(TopologyEdge edge) {
LinkWeight weight = edge -> {
// Disregard inactive or non-optical links
if (edge.link().state() == Link.State.INACTIVE) {
return -1;
......@@ -292,7 +289,6 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
}
return 1;
}
};
ConnectPoint start = intent.getSrc();
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.link.impl;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Sets;
......@@ -126,13 +125,7 @@ public class LinkManager
public Iterable<Link> getActiveLinks() {
checkPermission(LINK_READ);
return FluentIterable.from(getLinks())
.filter(new Predicate<Link>() {
@Override
public boolean apply(Link input) {
return input.state() == State.ACTIVE;
}
});
.filter(input -> input.state() == State.ACTIVE);
}
@Override
......
......@@ -348,12 +348,7 @@ public class StatisticManager implements StatisticService {
* @return predicate
*/
private static Predicate<FlowEntry> hasApplicationId(ApplicationId appId) {
return new Predicate<FlowEntry>() {
@Override
public boolean apply(FlowEntry flowEntry) {
return flowEntry.appId() == appId.id();
}
};
return flowEntry -> flowEntry.appId() == appId.id();
}
/**
......@@ -364,16 +359,13 @@ public class StatisticManager implements StatisticService {
* @return predicate
*/
private static Predicate<FlowEntry> hasGroupId(Optional<GroupId> groupId) {
return new Predicate<FlowEntry>() {
@Override
public boolean apply(FlowEntry flowEntry) {
return flowEntry -> {
if (!groupId.isPresent()) {
return false;
}
// FIXME: The left hand type and right hand type don't match
// FlowEntry.groupId() still returns a short value, not int.
return flowEntry.groupId().equals(groupId.get());
}
};
}
}
......
......@@ -24,7 +24,6 @@ import java.net.URI;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.ChassisId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.net.config.basics.BasicDeviceConfig;
import org.onosproject.net.AnnotationKeys;
......@@ -55,11 +54,7 @@ public class BasicDeviceOperatorTest {
private static final DeviceDescription DEV1 = new DefaultDeviceDescription(
DURI, SWITCH, MFR, HW, SW, SN, CID, SA);
private final ConfigApplyDelegate delegate = new ConfigApplyDelegate() {
@Override
public void onApply(Config config) {
}
};
private final ConfigApplyDelegate delegate = config -> { };
private final ObjectMapper mapper = new ObjectMapper();
private static final BasicDeviceConfig SW_BDC = new BasicDeviceConfig();
......
......@@ -22,7 +22,6 @@ import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.net.config.basics.BasicHostConfig;
import org.onosproject.net.AnnotationKeys;
......@@ -49,11 +48,7 @@ public class BasicHostOperatorTest {
);
private static final HostDescription HOST = new DefaultHostDescription(MAC, VLAN, LOC, IP);
private final ConfigApplyDelegate delegate = new ConfigApplyDelegate() {
@Override
public void onApply(Config config) {
}
};
private final ConfigApplyDelegate delegate = config -> { };
private final ObjectMapper mapper = new ObjectMapper();
private static final BasicHostConfig BHC = new BasicHostConfig();
......
......@@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals;
import java.time.Duration;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.net.config.basics.BasicLinkConfig;
import org.onosproject.net.AnnotationKeys;
......@@ -53,11 +52,7 @@ public class BasicLinkOperatorTest {
private static final SparseAnnotations SA = DefaultAnnotations.builder()
.set(AnnotationKeys.DURABLE, "true").build();
private static final LinkDescription LD = new DefaultLinkDescription(SRC, DST, Link.Type.DIRECT, SA);
private final ConfigApplyDelegate delegate = new ConfigApplyDelegate() {
@Override
public void onApply(Config config) {
}
};
private final ConfigApplyDelegate delegate = config -> { };
private final ObjectMapper mapper = new ObjectMapper();
private static final BasicLinkConfig BLC = new BasicLinkConfig();
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.store.device.impl;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
......@@ -564,13 +563,10 @@ public class GossipDeviceStore
final DeviceDescriptions descs = device.get(providerId);
List<PortDescription> mergedList =
FluentIterable.from(portDescriptions)
.transform(new Function<PortDescription, PortDescription>() {
@Override
public PortDescription apply(PortDescription input) {
.transform(input ->
// lookup merged port description
return descs.getPortDesc(input.portNumber()).value();
}
}).toList();
descs.getPortDesc(input.portNumber()).value()
).toList();
merged = new Timestamped<>(mergedList, newTimestamp);
}
......
......@@ -802,31 +802,22 @@ public class GossipDeviceStoreTest {
@Test
public final void testEvents() throws InterruptedException {
final CountDownLatch addLatch = new CountDownLatch(1);
DeviceStoreDelegate checkAdd = new DeviceStoreDelegate() {
@Override
public void notify(DeviceEvent event) {
DeviceStoreDelegate checkAdd = event -> {
assertEquals(DEVICE_ADDED, event.type());
assertDevice(DID1, SW1, event.subject());
addLatch.countDown();
}
};
final CountDownLatch updateLatch = new CountDownLatch(1);
DeviceStoreDelegate checkUpdate = new DeviceStoreDelegate() {
@Override
public void notify(DeviceEvent event) {
DeviceStoreDelegate checkUpdate = event -> {
assertEquals(DEVICE_UPDATED, event.type());
assertDevice(DID1, SW2, event.subject());
updateLatch.countDown();
}
};
final CountDownLatch removeLatch = new CountDownLatch(1);
DeviceStoreDelegate checkRemove = new DeviceStoreDelegate() {
@Override
public void notify(DeviceEvent event) {
DeviceStoreDelegate checkRemove = event -> {
assertEquals(DEVICE_REMOVED, event.type());
assertDevice(DID1, SW2, event.subject());
removeLatch.countDown();
}
};
DeviceDescription description =
......
......@@ -548,31 +548,22 @@ public class GossipLinkStoreTest {
final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
final CountDownLatch addLatch = new CountDownLatch(1);
LinkStoreDelegate checkAdd = new LinkStoreDelegate() {
@Override
public void notify(LinkEvent event) {
LinkStoreDelegate checkAdd = event -> {
assertEquals(LINK_ADDED, event.type());
assertLink(linkId1, INDIRECT, event.subject());
addLatch.countDown();
}
};
final CountDownLatch updateLatch = new CountDownLatch(1);
LinkStoreDelegate checkUpdate = new LinkStoreDelegate() {
@Override
public void notify(LinkEvent event) {
LinkStoreDelegate checkUpdate = event -> {
assertEquals(LINK_UPDATED, event.type());
assertLink(linkId1, DIRECT, event.subject());
updateLatch.countDown();
}
};
final CountDownLatch removeLatch = new CountDownLatch(1);
LinkStoreDelegate checkRemove = new LinkStoreDelegate() {
@Override
public void notify(LinkEvent event) {
LinkStoreDelegate checkRemove = event -> {
assertEquals(LINK_REMOVED, event.type());
assertLink(linkId1, DIRECT, event.subject());
removeLatch.countDown();
}
};
linkStore.setDelegate(checkAdd);
......