Java Code Examples for org.apache.commons.collections4.Trie#get()
The following examples show how to use
org.apache.commons.collections4.Trie#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SuggestionServiceImpl.java From intellij-spring-assistant with MIT License | 6 votes |
private void removeReferences(Map<String, MetadataContainerInfo> containerPathToContainerInfo, Trie<String, MetadataSuggestionNode> rootSearchIndex, MetadataContainerInfo metadataContainerInfo) { debug(() -> log.debug("Removing references to " + metadataContainerInfo)); String containerPath = metadataContainerInfo.getContainerArchiveOrFileRef(); containerPathToContainerInfo.remove(containerPath); Iterator<String> searchIndexIterator = rootSearchIndex.keySet().iterator(); while (searchIndexIterator.hasNext()) { SuggestionNode root = rootSearchIndex.get(searchIndexIterator.next()); if (root != null) { boolean removeTree = MetadataSuggestionNode.class.cast(root) .removeRefCascadeDown(metadataContainerInfo.getContainerArchiveOrFileRef()); if (removeTree) { searchIndexIterator.remove(); } } } }
Example 2
Source File: MPQViewer.java From riiablo with Apache License 2.0 | 6 votes |
private void treeify(Trie<String, Node> nodes, Node root, String path) { Node parent = root; String[] parts = path.split("\\\\"); StringBuilder builder = new StringBuilder(path.length()); for (String part : parts) { if (part.isEmpty()) { break; } builder.append(part).append("\\"); String partPath = builder.toString(); Node node = nodes.get(partPath); if (node == null) { node = new BaseNode(new VisLabel(part)); nodes.put(partPath, node); parent.add(node); } parent = node; } }
Example 3
Source File: SuggestionServiceImpl.java From intellij-spring-assistant with MIT License | 4 votes |
private List<LookupElementBuilder> doFindSuggestionsForQueryPrefix(Module module, Trie<String, MetadataSuggestionNode> rootSearchIndex, FileType fileType, PsiElement element, @Nullable List<String> ancestralKeys, String queryWithDotDelimitedPrefixes, @Nullable Set<String> siblingsToExclude) { debug(() -> log.debug("Search requested for " + queryWithDotDelimitedPrefixes)); StopWatch timer = new StopWatch(); timer.start(); try { String[] querySegmentPrefixes = toSanitizedPathSegments(queryWithDotDelimitedPrefixes); Set<Suggestion> suggestions = null; if (ancestralKeys != null) { String[] ancestralKeySegments = ancestralKeys.stream().flatMap(key -> stream(toRawPathSegments(key))) .toArray(String[]::new); MetadataSuggestionNode rootNode = rootSearchIndex.get(sanitise(ancestralKeySegments[0])); if (rootNode != null) { List<SuggestionNode> matchesRootToDeepest; SuggestionNode startSearchFrom = null; if (ancestralKeySegments.length > 1) { String[] sanitisedAncestralPathSegments = stream(ancestralKeySegments).map(SuggestionNode::sanitise).toArray(String[]::new); matchesRootToDeepest = rootNode .findDeepestSuggestionNode(module, modifiableList(rootNode), sanitisedAncestralPathSegments, 1); if (matchesRootToDeepest != null && matchesRootToDeepest.size() != 0) { startSearchFrom = matchesRootToDeepest.get(matchesRootToDeepest.size() - 1); } } else { startSearchFrom = rootNode; matchesRootToDeepest = singletonList(rootNode); } if (startSearchFrom != null) { // if search start node is a leaf, this means, the user is looking for values for the given key, lets find the suggestions for values if (startSearchFrom.isLeaf(module)) { suggestions = startSearchFrom.findValueSuggestionsForPrefix(module, fileType, unmodifiableList(matchesRootToDeepest), sanitise(truncateIdeaDummyIdentifier(element.getText())), siblingsToExclude); } else { suggestions = startSearchFrom.findKeySuggestionsForQueryPrefix(module, fileType, unmodifiableList(matchesRootToDeepest), matchesRootToDeepest.size(), querySegmentPrefixes, 0, siblingsToExclude); } } } } else { String rootQuerySegmentPrefix = querySegmentPrefixes[0]; SortedMap<String, MetadataSuggestionNode> topLevelQueryResults = rootSearchIndex.prefixMap(rootQuerySegmentPrefix); Collection<MetadataSuggestionNode> childNodes; int querySegmentPrefixStartIndex; // If no results are found at the top level, let dive deeper and find matches if (topLevelQueryResults == null || topLevelQueryResults.size() == 0) { childNodes = rootSearchIndex.values(); querySegmentPrefixStartIndex = 0; } else { childNodes = topLevelQueryResults.values(); querySegmentPrefixStartIndex = 1; } Collection<MetadataSuggestionNode> nodesToSearchAgainst; if (siblingsToExclude != null) { Set<MetadataSuggestionNode> nodesToExclude = siblingsToExclude.stream() .flatMap(exclude -> rootSearchIndex.prefixMap(exclude).values().stream()) .collect(toSet()); nodesToSearchAgainst = childNodes.stream().filter(node -> !nodesToExclude.contains(node)).collect(toList()); } else { nodesToSearchAgainst = childNodes; } suggestions = doFindSuggestionsForQueryPrefix(module, fileType, nodesToSearchAgainst, querySegmentPrefixes, querySegmentPrefixStartIndex); } if (suggestions != null) { return toLookupElementBuilders(suggestions); } return null; } finally { timer.stop(); debug(() -> log.debug("Search took " + timer.toString())); } }