mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Update dependenty code
This commit is contained in:
parent
5b9b5b557c
commit
f798900020
3 changed files with 57 additions and 1 deletions
|
@ -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>();
|
||||
|
||||
|
|
18
src/external/java/com/minelittlepony/util/chron/ChronicCache.java
vendored
Normal file
18
src/external/java/com/minelittlepony/util/chron/ChronicCache.java
vendored
Normal 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;
|
||||
}
|
||||
|
||||
}
|
17
src/external/java/com/minelittlepony/util/chron/Touchable.java
vendored
Normal file
17
src/external/java/com/minelittlepony/util/chron/Touchable.java
vendored
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue