@@ -0,0 +1,1417 @@
+package rapanui.ui;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.function.Function;%0A%0Apublic class Cache%3CTKey, TValue%3E %7B%0A%09private int maxCapacity;%0A%0A%09private final Map%3CTKey, TValue%3E map = new HashMap%3CTKey, TValue%3E();%0A%09private final Map%3CTKey, Long%3E usageTime = new HashMap%3CTKey, Long%3E();%0A%0A%09public Cache(int maxCapacity) %7B%0A%09%09assert maxCapacity %3E 1;%0A%09%09this.maxCapacity = maxCapacity;%0A%09%7D%0A%0A%09public synchronized void put(TKey key, TValue value) %7B%0A%09%09if (map.size() %3E= maxCapacity) %7B%0A%09%09%09TKey leastRecentlyUsed = usageTime.entrySet().stream().min(%0A%09%09%09%09%09(e1, e2) -%3E e1.getValue() == e2.getValue() ? 0 : (e1.getValue() %3C e2.getValue() ? -1 : 1)%0A%09%09%09%09).get().getKey();%0A%09%09%09map.remove(leastRecentlyUsed);%0A%09%09%09usageTime.remove(leastRecentlyUsed);%0A%09%09%7D%0A%0A%09%09map.put(key, value);%0A%09%09usageTime.put(key,  System.currentTimeMillis());%0A%09%7D%0A%0A%09public synchronized TValue get(TKey key) %7B%0A%09%09if (!map.containsKey(key))%0A%09%09%09throw new IllegalArgumentException(%22Unknown key%22);%0A%0A%09%09usageTime.put(key, System.currentTimeMillis());%0A%09%09return map.get(key);%0A%09%7D%0A%0A%09public synchronized TValue get(TKey key, Function%3CTKey, TValue%3E supplier) %7B%0A%09%09if (map.containsKey(key))%0A%09%09%09return get(key);%0A%0A%09%09TValue value = supplier.apply(key);%0A%09%09put(key, value);%0A%09%09return value;%0A%09%7D%0A%0A%09public synchronized void delete(TKey key) %7B%0A%09%09map.remove(key);%0A%09%09usageTime.remove(key);%0A%09%7D%0A%0A%09public synchronized boolean hasKey(TKey key) %7B%0A%09%09return map.containsKey(key);%0A%09%7D%0A%7D%0A

implement simple Cache class