X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fcache%2FJvCacheableInputBox.java;fp=src%2Fjalview%2Fio%2Fcache%2FJvCacheableInputBox.java;h=e02a396cf19ebdaa8914a09fd4131a23b7f3ee83;hb=a83adb45bdf9554e270921b4baad94defd314b36;hp=9ec3a9f6658beb7e3554495317ab64961c935788;hpb=d4ec118f86b5c9dee801e743c46aaacc7bb521d1;p=jalview.git diff --git a/src/jalview/io/cache/JvCacheableInputBox.java b/src/jalview/io/cache/JvCacheableInputBox.java index 9ec3a9f..e02a396 100644 --- a/src/jalview/io/cache/JvCacheableInputBox.java +++ b/src/jalview/io/cache/JvCacheableInputBox.java @@ -237,65 +237,76 @@ public class JvCacheableInputBox @Override public void run() { - int cacheLimit = Integer.parseInt(appCache.getCacheLimit(cacheKey)); - String userInput = getUserInput(); - if (userInput != null && !userInput.isEmpty()) - { - LinkedHashSet foundCache = appCache - .getAllCachedItemsFor(cacheKey); - // remove old cache item so as to place current input at the top of - // the result - foundCache.remove(userInput); - foundCache.add(userInput); - appCache.putCache(cacheKey, foundCache); - } + updateCacheNow(); + } + }); + } - String lastSearch = userInput; - if (comboBox.getItemCount() > 0) - { - comboBox.removeAllItems(); - } - Set cacheItems = appCache.getAllCachedItemsFor(cacheKey); - List reversedCacheItems = new ArrayList<>(); - reversedCacheItems.addAll(cacheItems); - cacheItems = null; - Collections.reverse(reversedCacheItems); - if (lastSearch.isEmpty()) - { - comboBox.addItem(""); - } + /** + * For TestNG + * + * @author Bob Hanson 2019.08.28 + */ + public void updateCacheNow() + { + int cacheLimit = Integer.parseInt(appCache.getCacheLimit(cacheKey)); + String userInput = getUserInput(); + if (userInput != null && !userInput.isEmpty()) + { + LinkedHashSet foundCache = appCache + .getAllCachedItemsFor(cacheKey); + // remove old cache item so as to place current input at the top of + // the result + foundCache.remove(userInput); + foundCache.add(userInput); + appCache.putCache(cacheKey, foundCache); + } - if (reversedCacheItems != null && !reversedCacheItems.isEmpty()) + String lastSearch = userInput; + if (comboBox.getItemCount() > 0) + { + comboBox.removeAllItems(); + } + Set cacheItems = appCache.getAllCachedItemsFor(cacheKey); + List reversedCacheItems = new ArrayList<>(); + reversedCacheItems.addAll(cacheItems); + cacheItems = null; + Collections.reverse(reversedCacheItems); + if (lastSearch.isEmpty()) + { + comboBox.addItem(""); + } + + if (reversedCacheItems != null && !reversedCacheItems.isEmpty()) + { + LinkedHashSet foundCache = appCache + .getAllCachedItemsFor(cacheKey); + boolean prune = reversedCacheItems.size() > cacheLimit; + int count = 1; + boolean limitExceeded = false; + for (String cacheItem : reversedCacheItems) + { + limitExceeded = (count++ > cacheLimit); + if (prune) { - LinkedHashSet foundCache = appCache - .getAllCachedItemsFor(cacheKey); - boolean prune = reversedCacheItems.size() > cacheLimit; - int count = 1; - boolean limitExceeded = false; - for (String cacheItem : reversedCacheItems) + if (limitExceeded) { - limitExceeded = (count++ > cacheLimit); - if (prune) - { - if (limitExceeded) - { - foundCache.remove(cacheItem); - } - else - { - comboBox.addItem(cacheItem); - } - } - else - { - comboBox.addItem(cacheItem); - } + foundCache.remove(cacheItem); } - appCache.putCache(cacheKey, foundCache); + else + { + comboBox.addItem(cacheItem); + } + } + else + { + comboBox.addItem(cacheItem); } - setSelectedItem(lastSearch.isEmpty() ? "" : lastSearch); } - }); + appCache.putCache(cacheKey, foundCache); + } + setSelectedItem(lastSearch.isEmpty() ? "" : lastSearch); + } /**