From 030b52261d03b8c753d413b21dab36e7f332a0ce Mon Sep 17 00:00:00 2001
From: akwizgran <michael@briarproject.org>
Date: Fri, 1 Dec 2017 13:47:54 +0000
Subject: [PATCH] Replace a few runnables with lambdas.

---
 .../bramble/plugin/tcp/LanTcpPluginTest.java  | 34 +++++++---------
 .../briar/android/BriarService.java           | 40 ++++++++-----------
 .../controller/BriarControllerImpl.java       | 33 +++++++--------
 3 files changed, 46 insertions(+), 61 deletions(-)

diff --git a/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java b/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java
index b4f360c7b5..d6ea0b6390 100644
--- a/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java
+++ b/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java
@@ -150,17 +150,14 @@ public class LanTcpPluginTest extends BrambleTestCase {
 		int port = ss.getLocalPort();
 		CountDownLatch latch = new CountDownLatch(1);
 		AtomicBoolean error = new AtomicBoolean(false);
-		new Thread() {
-			@Override
-			public void run() {
-				try {
-					ss.accept();
-					latch.countDown();
-				} catch (IOException e) {
-					error.set(true);
-				}
+		new Thread(() -> {
+			try {
+				ss.accept();
+				latch.countDown();
+			} catch (IOException e) {
+				error.set(true);
 			}
-		}.start();
+		}).start();
 		// Tell the plugin about the port
 		TransportProperties p = new TransportProperties();
 		p.put("ipPorts", addrString + ":" + port);
@@ -243,17 +240,14 @@ public class LanTcpPluginTest extends BrambleTestCase {
 		ss.bind(new InetSocketAddress(addrString, 0), 10);
 		CountDownLatch latch = new CountDownLatch(1);
 		AtomicBoolean error = new AtomicBoolean(false);
-		new Thread() {
-			@Override
-			public void run() {
-				try {
-					ss.accept();
-					latch.countDown();
-				} catch (IOException e) {
-					error.set(true);
-				}
+		new Thread(() -> {
+			try {
+				ss.accept();
+				latch.countDown();
+			} catch (IOException e) {
+				error.set(true);
 			}
-		}.start();
+		}).start();
 		// Tell the plugin about the port
 		BdfList descriptor = new BdfList();
 		descriptor.add(TRANSPORT_ID_LAN);
diff --git a/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java b/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java
index 0e6bb7c399..9149e10a06 100644
--- a/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java
+++ b/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java
@@ -91,24 +91,21 @@ public class BriarService extends Service {
 		b.setPriority(PRIORITY_MIN);
 		startForeground(ONGOING_NOTIFICATION_ID, b.build());
 		// Start the services in a background thread
-		new Thread() {
-			@Override
-			public void run() {
-				String nickname = databaseConfig.getLocalAuthorName();
-				StartResult result = lifecycleManager.startServices(nickname);
-				if (result == SUCCESS) {
-					started = true;
-				} else if (result == ALREADY_RUNNING) {
-					LOG.info("Already running");
-					stopSelf();
-				} else {
-					if (LOG.isLoggable(WARNING))
-						LOG.warning("Startup failed: " + result);
-					showStartupFailureNotification(result);
-					stopSelf();
-				}
+		new Thread(() -> {
+			String nickname = databaseConfig.getLocalAuthorName();
+			StartResult result = lifecycleManager.startServices(nickname);
+			if (result == SUCCESS) {
+				started = true;
+			} else if (result == ALREADY_RUNNING) {
+				LOG.info("Already running");
+				stopSelf();
+			} else {
+				if (LOG.isLoggable(WARNING))
+					LOG.warning("Startup failed: " + result);
+				showStartupFailureNotification(result);
+				stopSelf();
 			}
-		}.start();
+		}).start();
 	}
 
 	private void showStartupFailureNotification(StartResult result) {
@@ -155,12 +152,9 @@ public class BriarService extends Service {
 		LOG.info("Destroyed");
 		stopForeground(true);
 		// Stop the services in a background thread
-		new Thread() {
-			@Override
-			public void run() {
-				if (started) lifecycleManager.stopServices();
-			}
-		}.start();
+		new Thread(() -> {
+			if (started) lifecycleManager.stopServices();
+		}).start();
 	}
 
 	@Override
diff --git a/briar-android/src/main/java/org/briarproject/briar/android/controller/BriarControllerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/controller/BriarControllerImpl.java
index a8d90dd0cc..aa9861a7f6 100644
--- a/briar-android/src/main/java/org/briarproject/briar/android/controller/BriarControllerImpl.java
+++ b/briar-android/src/main/java/org/briarproject/briar/android/controller/BriarControllerImpl.java
@@ -123,25 +123,22 @@ public class BriarControllerImpl implements BriarController {
 
 	@Override
 	public void signOut(ResultHandler<Void> eventHandler) {
-		new Thread() {
-			@Override
-			public void run() {
-				try {
-					// Wait for the service to finish starting up
-					IBinder binder = serviceConnection.waitForBinder();
-					BriarService service =
-							((BriarService.BriarBinder) binder).getService();
-					service.waitForStartup();
-					// Shut down the service and wait for it to shut down
-					LOG.info("Shutting down service");
-					service.shutdown();
-					service.waitForShutdown();
-				} catch (InterruptedException e) {
-					LOG.warning("Interrupted while waiting for service");
-				}
-				eventHandler.onResult(null);
+		new Thread(() -> {
+			try {
+				// Wait for the service to finish starting up
+				IBinder binder = serviceConnection.waitForBinder();
+				BriarService service =
+						((BriarService.BriarBinder) binder).getService();
+				service.waitForStartup();
+				// Shut down the service and wait for it to shut down
+				LOG.info("Shutting down service");
+				service.shutdown();
+				service.waitForShutdown();
+			} catch (InterruptedException e) {
+				LOG.warning("Interrupted while waiting for service");
 			}
-		}.start();
+			eventHandler.onResult(null);
+		}).start();
 	}
 
 	private void unbindService() {
-- 
GitLab