mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Convert some things to lambda or Method Reference
This commit is contained in:
parent
bc22a9d021
commit
231e11633b
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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."));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user