List<String> (@NotNull Set<String> requiredTags) { var pq = new PriorityQueue<>(ContainerUtil.map(myRoots, root -> new EnvInfo(root))); var addedPythonVersions = new HashSet<String>(); var result = new ArrayList<String>(); while (!pq.isEmpty()) { var envInfo = pq.poll(); if (isSuitableForTags(envInfo.tags, requiredTags)) { if (envInfo.pythonVersion == null) { result.add(envInfo.root); } else { if (!addedPythonVersions.contains(envInfo.pythonVersion)) { addedPythonVersions.add(envInfo.pythonVersion); result.add(envInfo.root); } } } } return result; }