Add TabCompletionCache #9

Zusammengeführt
YoyoNow hat 5 Commits von Caching nach master 2022-06-21 22:06:40 +02:00 zusammengeführt
2 geänderte Dateien mit 10 neuen und 10 gelöschten Zeilen
Nur Änderungen aus Commit 96953bdec4 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -111,7 +111,7 @@ public abstract class AbstractSWCommand<T> {
for (Method method : methods) {
Cached cached = method.getAnnotation(Cached.class);
addMapper(Mapper.class, method, i -> i == 0, false, AbstractTypeMapper.class, (anno, typeMapper) -> {
addToCache(cached, typeMapper);
TabCompletionCache.add(typeMapper, cached);
if (anno.local()) {
localTypeMapper.putIfAbsent(anno.value(), (AbstractTypeMapper<T, ?>) typeMapper);
} else {
@ -119,7 +119,7 @@ public abstract class AbstractSWCommand<T> {
}
});
addMapper(ClassMapper.class, method, i -> i == 0, false, AbstractTypeMapper.class, (anno, typeMapper) -> {
addToCache(cached, typeMapper);
TabCompletionCache.add(typeMapper, cached);
if (anno.local()) {
localTypeMapper.putIfAbsent(anno.value().getTypeName(), (AbstractTypeMapper<T, ?>) typeMapper);
} else {
@ -213,14 +213,6 @@ public abstract class AbstractSWCommand<T> {
initialized = true;
}
private void addToCache(Cached cached, AbstractTypeMapper<?, ?> typeMapper) {
if (cached != null) {
TabCompletionCache.cached.add(typeMapper);
if (cached.global()) TabCompletionCache.global.add(typeMapper);
TabCompletionCache.cacheDuration.put(typeMapper, cached.timeUnit().toMillis(cached.cacheDuration()));
}
}
private <T extends Annotation> void add(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, Parameter[]> consumer) {
T[] anno = SWCommandUtils.getAnnotation(method, annotation);
if (anno == null || anno.length == 0) return;

Datei anzeigen

@ -15,6 +15,14 @@ public class TabCompletionCache {
Set<AbstractTypeMapper<?, ?>> global = new HashSet<>();
Map<AbstractTypeMapper<?, ?>, Long> cacheDuration = new HashMap<>();
void add(AbstractTypeMapper<?, ?> typeMapper, AbstractSWCommand.Cached cached) {
if (cached != null) {
TabCompletionCache.cached.add(typeMapper);
if (cached.global()) TabCompletionCache.global.add(typeMapper);
TabCompletionCache.cacheDuration.put(typeMapper, cached.timeUnit().toMillis(cached.cacheDuration()));
}
}
@EqualsAndHashCode
@AllArgsConstructor
private static class Key {