Optional<SearchEverywhereCommandInfo> (String typedCommand) { int index = myResultsList.getSelectedIndex(); if (index < 0) return Optional.empty(); SearchEverywhereContributor contributor = myListModel.getContributorForIndex(index); if (contributor != myStubCommandContributor) return Optional.empty(); SearchEverywhereCommandInfo selectedCommand = (SearchEverywhereCommandInfo)myListModel.getElementAt(index); return selectedCommand.getCommand().contains(typedCommand) ? Optional.of(selectedCommand) : Optional.empty(); }