Guest User

Untitled

a guest
Jun 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.HashSet;
  3. import java.util.Map;
  4. import java.util.Set;
  5.  
  6. public class TimeList {
  7.  
  8. private Map<String, Long> map = new HashMap<String, Long>();
  9.  
  10. public void update(String id, long timestamp) {
  11. map.put(id, timestamp);
  12. }
  13.  
  14. public void remove(String id) {
  15. map.remove(id);
  16. }
  17.  
  18. public Set<String> getOlderThan(long timestamp) {
  19. Set<String> result = new HashSet<String>();
  20.  
  21. for (String id : map.keySet()) {
  22. if (map.get(id) < timestamp) {
  23. result.add(id);
  24. }
  25. }
  26.  
  27. return result;
  28. }
  29.  
  30.  
  31. public static void main(String[] args) {
  32. TimeList list = new TimeList();
  33.  
  34. list.update("a", 1000);
  35. list.update("b", 2000);
  36. list.update("c", 3000);
  37. list.update("a", 4000);
  38. list.update("d", 5000);
  39. list.update("a", 6000);
  40. list.update("a", 7000);
  41. list.update("a", 8000);
  42.  
  43. System.out.println(list.map);
  44. System.out.println("===========");
  45. System.out.println(list.getOlderThan(4001));
  46.  
  47. }
  48.  
  49. }
Add Comment
Please, Sign In to add comment