Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Map;
- import java.util.Set;
- public class TimeList {
- private Map<String, Long> map = new HashMap<String, Long>();
- public void update(String id, long timestamp) {
- map.put(id, timestamp);
- }
- public void remove(String id) {
- map.remove(id);
- }
- public Set<String> getOlderThan(long timestamp) {
- Set<String> result = new HashSet<String>();
- for (String id : map.keySet()) {
- if (map.get(id) < timestamp) {
- result.add(id);
- }
- }
- return result;
- }
- public static void main(String[] args) {
- TimeList list = new TimeList();
- list.update("a", 1000);
- list.update("b", 2000);
- list.update("c", 3000);
- list.update("a", 4000);
- list.update("d", 5000);
- list.update("a", 6000);
- list.update("a", 7000);
- list.update("a", 8000);
- System.out.println(list.map);
- System.out.println("===========");
- System.out.println(list.getOlderThan(4001));
- }
- }
Add Comment
Please, Sign In to add comment