private static void addCurrentlySelectedItemToTop(
     Lookup lookup, List<LookupElement> items, LinkedHashSet<LookupElement> model) {
   if (!lookup.isSelectionTouched()) {
     LookupElement lastSelection = lookup.getCurrentItem();
     if (ContainerUtil.indexOfIdentity(items, lastSelection) >= 0) {
       model.add(lastSelection);
     }
   }
 }
 private static void addSomeItems(
     LinkedHashSet<LookupElement> model,
     Iterator<LookupElement> iterator,
     Condition<LookupElement> stopWhen) {
   while (iterator.hasNext()) {
     LookupElement item = iterator.next();
     model.add(item);
     if (stopWhen.value(item)) {
       break;
     }
   }
 }
 private static void ensureItemAdded(
     List<LookupElement> items,
     LinkedHashSet<LookupElement> model,
     Iterator<LookupElement> byRelevance,
     @Nullable final LookupElement item) {
   if (item != null && ContainerUtil.indexOfIdentity(items, item) >= 0 && !model.contains(item)) {
     addSomeItems(
         model,
         byRelevance,
         new Condition<LookupElement>() {
           @Override
           public boolean value(LookupElement lastAdded) {
             return lastAdded == item;
           }
         });
   }
 }
 private static void ensureEverythingVisibleAdded(
     LookupImpl lookup,
     final LinkedHashSet<LookupElement> model,
     Iterator<LookupElement> byRelevance) {
   JList list = lookup.getList();
   final boolean testMode = ApplicationManager.getApplication().isUnitTestMode();
   final int limit =
       Math.max(list.getLastVisibleIndex(), model.size())
           + ourUISettings.MAX_LOOKUP_LIST_HEIGHT * 3;
   addSomeItems(
       model,
       byRelevance,
       new Condition<LookupElement>() {
         @Override
         public boolean value(LookupElement lastAdded) {
           return !testMode && model.size() >= limit;
         }
       });
 }
 private void addFrozenItems(List<LookupElement> items, LinkedHashSet<LookupElement> model) {
   myFrozenItems.retainAll(items);
   model.addAll(myFrozenItems);
 }