@Test public void whenNewThenNotInCooldown() { UUID uuid = UUID.randomUUID(); ChatCooldowns chatCooldowns = new ChatCooldowns(3); assertFalse(chatCooldowns.checkCooldown(uuid).isPresent()); }
public Optional<Integer> checkCooldown(UUID player) { return Optional.ofNullable(cooldowns.compute(player, (uuid, lastChatTime) -> { int now = currentTime(); if (lastChatTime == null || now - lastChatTime >= cooldown) { return null; } else { return cooldown - (now - lastChatTime); } })); }
ChatCooldowns { public Optional<Integer> checkCooldown(UUID player) { return Optional.ofNullable(cooldowns.compute(player, (uuid, lastChatTime) -> { int now = currentTime(); if (lastChatTime == null || now - lastChatTime >= cooldown) { return null; } else { return cooldown - (now - lastChatTime); } })); } }
ChatCooldowns { public Optional<Integer> checkCooldown(UUID player) { return Optional.ofNullable(cooldowns.compute(player, (uuid, lastChatTime) -> { int now = currentTime(); if (lastChatTime == null || now - lastChatTime >= cooldown) { return null; } else { return cooldown - (now - lastChatTime); } })); }  }
ChatCooldowns { public Optional<Integer> checkCooldown(UUID player) { return Optional.ofNullable(cooldowns.compute(player, (uuid, lastChatTime) -> { int now = currentTime(); if (lastChatTime == null || now - lastChatTime >= cooldown) { return null; } else { return cooldown - (now - lastChatTime); } })); }  Optional<Integer> checkCooldown(UUID player); void removePlayer(UUID player); void onChat(UUID uuid); }
ChatCooldowns { public Optional<Integer> checkCooldown(UUID player) { return Optional.ofNullable(cooldowns.compute(player, (uuid, lastChatTime) -> { int now = currentTime(); if (lastChatTime == null || now - lastChatTime >= cooldown) { return null; } else { return cooldown - (now - lastChatTime); } })); }  Optional<Integer> checkCooldown(UUID player); void removePlayer(UUID player); void onChat(UUID uuid);  }