Update dependenty code

This commit is contained in:
Sollace 2019-01-07 14:48:26 +02:00
parent 5b9b5b557c
commit f798900020
3 changed files with 57 additions and 1 deletions

View file

@ -2,9 +2,30 @@ package com.minelittlepony.model.anim;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.minelittlepony.util.chron.ChronicCache;
import com.minelittlepony.util.chron.Touchable;
//#MineLittlePony#
public class BasicEasingInterpolator implements IInterpolator {
public class BasicEasingInterpolator extends Touchable<BasicEasingInterpolator> implements IInterpolator {
private static ChronicCache<UUID, BasicEasingInterpolator> instanceCache = new ChronicCache<>();
/**
* Gets or creates a new basic, linear interpolator for the provided id.
*/
public static IInterpolator getInstance(UUID id) {
return instanceCache.retrieve(id, BasicEasingInterpolator::new);
}
public BasicEasingInterpolator() {
}
private BasicEasingInterpolator(UUID id) {
}
private final Map<String, Float> properties = new HashMap<String, Float>();

View file

@ -0,0 +1,18 @@
package com.minelittlepony.util.chron;
import java.util.HashMap;
import java.util.function.Function;
//#MineLittlePony#
public class ChronicCache<K, V extends Touchable<V>> extends HashMap<K, V> {
private static final long serialVersionUID = 6454924015818181978L;
public V retrieve(K key, Function<? super K, ? extends V> mappingFunction) {
V result = computeIfAbsent(key, mappingFunction).touch();
entrySet().removeIf(entry -> entry.getValue().hasExpired());
return result;
}
}

View file

@ -0,0 +1,17 @@
package com.minelittlepony.util.chron;
//#MineLittlePony#
public abstract class Touchable<T extends Touchable<T>> {
private long expirationPeriod;
public boolean hasExpired() {
return expirationPeriod <= System.currentTimeMillis();
}
@SuppressWarnings("unchecked")
public T touch() {
expirationPeriod = System.currentTimeMillis() + 30000;
return (T)this;
}
}