From 231e11633b5533ea9aa041fb429adf4437fd5af2 Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Sun, 30 Jul 2017 18:47:12 +0200 Subject: [PATCH] Convert some things to lambda or Method Reference --- .../plan/data/cache/DataCacheHandler.java | 18 ++++-------- .../plan/data/cache/DataCacheHandlerTest.java | 14 ++------- .../cache/queue/DataCacheGetQueueTest.java | 14 ++------- .../plan/database/DatabaseTest.java | 29 ++++++------------- 4 files changed, 18 insertions(+), 57 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java index ee6962fd0..703a2d329 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java @@ -296,12 +296,7 @@ public class DataCacheHandler extends SessionCache { for (HandlingInfo i : toProcess) { UserData uData = dataCache.get(i.getUuid()); if (uData == null) { - DBCallableProcessor p = new DBCallableProcessor() { - @Override - public void process(UserData data) { - i.process(data); - } - }; + DBCallableProcessor p = i::process; getUserDataForProcessing(p, i.getUuid()); } else { i.process(uData); @@ -316,13 +311,10 @@ public class DataCacheHandler extends SessionCache { */ public void saveCachedData(UUID uuid) { Log.debug(uuid + ": SaveCachedData"); - DBCallableProcessor saveProcessor = new DBCallableProcessor() { - @Override - public void process(UserData data) { - data.access(); - data.setClearAfterSave(true); - saveTask.scheduleForSave(data); - } + DBCallableProcessor saveProcessor = data -> { + data.access(); + data.setClearAfterSave(true); + saveTask.scheduleForSave(data); }; getUserDataForProcessing(saveProcessor, uuid); } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java index 9c5355247..76506bb3c 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java @@ -134,12 +134,7 @@ public class DataCacheHandlerTest { // db.init(); UserData data = MockUtils.mockUser(); db.saveUserData(data); - handler.getUserDataForProcessing(new DBCallableProcessor() { - @Override - public void process(UserData d) { - assertTrue(d.equals(data)); - } - }, data.getUuid()); + handler.getUserDataForProcessing(d -> assertTrue(d.equals(data)), data.getUuid()); Thread.sleep(1000); assertTrue(handler.getDataCache().containsKey(data.getUuid())); assertTrue(handler.getDataCache().get(data.getUuid()).equals(data)); @@ -154,12 +149,7 @@ public class DataCacheHandlerTest { public void testGetUserDataForProcessingDontCache() throws SQLException, InterruptedException { UserData data = MockUtils.mockUser(); db.saveUserData(data); - handler.getUserDataForProcessing(new DBCallableProcessor() { - @Override - public void process(UserData d) { - assertTrue(d.equals(data)); - } - }, data.getUuid(), false); + handler.getUserDataForProcessing(d -> assertTrue(d.equals(data)), data.getUuid(), false); Thread.sleep(1000); assertTrue(!handler.getDataCache().containsKey(data.getUuid())); assertTrue(handler.getDataCache().get(data.getUuid()) == null); diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueueTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueueTest.java index 9ae781ff5..0861f37dc 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueueTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueueTest.java @@ -112,12 +112,7 @@ public class DataCacheGetQueueTest { UserData exp = MockUtils.mockUser2(); DataCacheGetQueue instance = new DataCacheGetQueue(plan); - instance.scheduleForGet(exp.getUuid(), new DBCallableProcessor() { - @Override - public void process(UserData data) { - assertTrue(data.equals(exp)); - } - }); + instance.scheduleForGet(exp.getUuid(), (DBCallableProcessor) data -> assertTrue(data.equals(exp))); } /** @@ -128,11 +123,6 @@ public class DataCacheGetQueueTest { public void testStop() { DataCacheGetQueue instance = new DataCacheGetQueue(plan); instance.stop(); - instance.scheduleForGet(MockUtils.getPlayerUUID(), new DBCallableProcessor() { - @Override - public void process(UserData data) { - fail("Called get process after stop."); - } - }); + instance.scheduleForGet(MockUtils.getPlayerUUID(), (DBCallableProcessor) data -> fail("Called get process after stop.")); } } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java index 7bf29969a..675f27054 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java @@ -228,12 +228,7 @@ public class DatabaseTest { db.saveUserData(data); data.addNickname("TestUpdateForSave"); db.saveUserData(data); - DBCallableProcessor process = new DBCallableProcessor() { - @Override - public void process(UserData d) { - assertTrue("Not Equals", data.equals(d)); - } - }; + DBCallableProcessor process = d -> assertTrue("Not Equals", data.equals(d)); db.giveUserDataToProcessors(data.getUuid(), process); } @@ -279,22 +274,16 @@ public class DatabaseTest { list.add(data2); db.saveMultipleUserData(list); data.addPlayerKill(new KillData(MockUtils.getPlayer2UUID(), 2, "DiamondSword", 75843759L)); - DBCallableProcessor process = new DBCallableProcessor() { - @Override - public void process(UserData d) { - System.out.println("\n" + data.toString()); - System.out.println(d.toString()); - assertTrue("Not Equals", data.equals(d)); - } + DBCallableProcessor process = d -> { + System.out.println("\n" + data.toString()); + System.out.println(d.toString()); + assertTrue("Not Equals", data.equals(d)); }; db.giveUserDataToProcessors(data.getUuid(), process); - DBCallableProcessor process2 = new DBCallableProcessor() { - @Override - public void process(UserData d) { - System.out.println("\n" + data2.toString()); - System.out.println(d.toString()); - assertTrue("Not Equals", data2.equals(d)); - } + DBCallableProcessor process2 = d -> { + System.out.println("\n" + data2.toString()); + System.out.println(d.toString()); + assertTrue("Not Equals", data2.equals(d)); }; db.giveUserDataToProcessors(data2.getUuid(), process2); }