Java Code Examples for com.intellij.util.containers.ContainerUtil#sort()
The following examples show how to use
com.intellij.util.containers.ContainerUtil#sort() .
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: SortedMemberResolveScopeProcessor.java From consulo-csharp with Apache License 2.0 | 6 votes |
public void consumeAll() { ResolveResult[] resolveResults = ((CommonProcessors.CollectProcessor<ResolveResult>) myResultProcessor).toArray(ResolveResult.ARRAY_FACTORY); ContainerUtil.sort(resolveResults, myComparator); for(ResolveResult result : resolveResults) { ProgressManager.checkCanceled(); if(!myOriginalProcessor.process(result)) { return; } } }
Example 2
Source File: VcsRevisionNumberArrayRule.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public List<VcsRevisionNumber> getRevisionNumbers(@Nonnull DataProvider dataProvider) { VcsRevisionNumber revisionNumber = dataProvider.getDataUnchecked(VcsDataKeys.VCS_REVISION_NUMBER); if (revisionNumber != null) { return Collections.singletonList(revisionNumber); } ChangeList[] changeLists = dataProvider.getDataUnchecked(VcsDataKeys.CHANGE_LISTS); if (changeLists != null && changeLists.length > 0) { List<CommittedChangeList> committedChangeLists = ContainerUtil.findAll(changeLists, CommittedChangeList.class); if (!committedChangeLists.isEmpty()) { ContainerUtil.sort(committedChangeLists, CommittedChangeListByDateComparator.DESCENDING); return ContainerUtil.mapNotNull(committedChangeLists, CommittedChangeListToRevisionNumberFunction.INSTANCE); } } VcsFileRevision[] fileRevisions = dataProvider.getDataUnchecked(VcsDataKeys.VCS_FILE_REVISIONS); if (fileRevisions != null && fileRevisions.length > 0) { return ContainerUtil.mapNotNull(fileRevisions, FileRevisionToRevisionNumberFunction.INSTANCE); } return null; }
Example 3
Source File: AppliedTextPatch.java From consulo with Apache License 2.0 | 6 votes |
public static AppliedTextPatch create(@Nonnull List<AppliedSplitPatchHunk> splitPatchHunkList) { List<AppliedSplitPatchHunk> hunks = new ArrayList<>(splitPatchHunkList); // ensure, that `appliedTo` ranges do not overlap BitSet appliedLines = new BitSet(); for (int i = 0; i < hunks.size(); i++) { AppliedSplitPatchHunk hunk = hunks.get(i); LineRange appliedTo = hunk.getAppliedTo(); if (appliedTo == null) continue; int nextAppliedLine = appliedLines.nextSetBit(appliedTo.start); if (nextAppliedLine != -1 && nextAppliedLine < appliedTo.end) { hunks.set(i, new AppliedSplitPatchHunk(hunk, -1, -1, NOT_APPLIED)); } else { appliedLines.set(appliedTo.start, appliedTo.end, true); } } ContainerUtil.sort(hunks, (o1, o2) -> Integer.compare(o1.getLineRangeBefore().start, o2.getLineRangeBefore().start)); return new AppliedTextPatch(hunks); }
Example 4
Source File: PatchChangeBuilder.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static CharSequence getPatchedContent(@Nonnull AppliedTextPatch patch, @Nonnull String localContent) { PatchChangeBuilder builder = new PatchChangeBuilder(); builder.exec(patch.getHunks()); DocumentImpl document = new DocumentImpl(localContent, true); List<Hunk> appliedHunks = ContainerUtil.filter(builder.getHunks(), (h) -> h.getStatus() == HunkStatus.EXACTLY_APPLIED); ContainerUtil.sort(appliedHunks, Comparator.comparingInt(h -> h.getAppliedToLines().start)); for (int i = appliedHunks.size() - 1; i >= 0; i--) { Hunk hunk = appliedHunks.get(i); LineRange appliedTo = hunk.getAppliedToLines(); List<String> inserted = hunk.getInsertedLines(); DiffUtil.applyModification(document, appliedTo.start, appliedTo.end, inserted); } return document.getText(); }
Example 5
Source File: StubTreeBuilder.java From consulo with Apache License 2.0 | 6 votes |
/** * Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()} */ @Nonnull public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@Nonnull FileViewProvider viewProvider) { final List<Trinity<Language, IStubFileElementType, PsiFile>> roots = new SmartList<>(); final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot(); for (Language language : viewProvider.getLanguages()) { final PsiFile file = viewProvider.getPsi(language); if (file instanceof PsiFileImpl) { final IElementType type = ((PsiFileImpl)file).getElementTypeForStubBuilder(); if (type != null) { roots.add(Trinity.create(language, (IStubFileElementType)type, file)); } } } ContainerUtil.sort(roots, (o1, o2) -> { if (o1.third == stubBindingRoot) return o2.third == stubBindingRoot ? 0 : -1; else if (o2.third == stubBindingRoot) return 1; else return StringUtil.compare(o1.first.getID(), o2.first.getID(), false); }); return ContainerUtil.map(roots, trinity -> Pair.create(trinity.second, trinity.third)); }
Example 6
Source File: ModuleDependencyTabContext.java From consulo with Apache License 2.0 | 6 votes |
private List<Module> getNotAddedModules() { final ModifiableRootModel rootModel = myClasspathPanel.getRootModel(); Set<Module> addedModules = new HashSet<Module>(Arrays.asList(rootModel.getModuleDependencies(true))); addedModules.add(rootModel.getModule()); final Module[] modules = myClasspathPanel.getModuleConfigurationState().getModulesProvider().getModules(); final List<Module> elements = new ArrayList<Module>(); for (final Module module : modules) { if (!addedModules.contains(module)) { elements.add(module); } } ContainerUtil.sort(elements, new Comparator<Module>() { @Override public int compare(Module o1, Module o2) { return StringUtil.compare(o1.getName(), o2.getName(), false); } }); return elements; }
Example 7
Source File: CSharpLineMarkerUtil.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction public static void openTargets(@Nonnull Collection<? extends PsiElement> members, @Nonnull MouseEvent mouseEvent, @Nonnull String text, @Nonnull final Function<PsiElement, PsiElement> map) { NavigatablePsiElement[] navigatablePsiElements = members.toArray(new NavigatablePsiElement[members.size()]); ContainerUtil.sort(navigatablePsiElements, (o1, o2) -> { PsiElement map1 = map.fun(o1); PsiElement map2 = map.fun(o2); if(map1 instanceof PsiNamedElement && map2 instanceof PsiNamedElement) { return Comparing.compare(((PsiNamedElement) map1).getName(), ((PsiNamedElement) map2).getName()); } return 0; }); PsiElementListNavigator.openTargets(mouseEvent, navigatablePsiElements, text, text, new PsiMappedElementListCellRender(map)); }
Example 8
Source File: TemplateState.java From consulo with Apache License 2.0 | 6 votes |
private void executeChanges(@Nonnull List<TemplateDocumentChange> changes) { if (isDisposed() || changes.isEmpty()) { return; } if (changes.size() > 1) { ContainerUtil.sort(changes, (o1, o2) -> { int startDiff = o2.startOffset - o1.startOffset; return startDiff != 0 ? startDiff : o2.endOffset - o1.endOffset; }); } DocumentUtil.executeInBulk(myDocument, true, () -> { for (TemplateDocumentChange change : changes) { replaceString(change.newValue, change.startOffset, change.endOffset, change.segmentNumber); } }); }
Example 9
Source File: WeightUtil.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction public static void sortAndProcess(@Nonnull List<MethodResolveResult> list, @Nonnull Processor<ResolveResult> processor, @Nonnull PsiElement place) { if(list.isEmpty()) { return; } ContainerUtil.sort(list, ourComparator); for(MethodResolveResult methodResolveResult : list) { ProgressManager.checkCanceled(); methodResolveResult.setAssignable(place); if(!processor.process(methodResolveResult)) { return; } } }
Example 10
Source File: DiffUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static <T> int[] getSortedIndexes(@Nonnull List<T> values, @Nonnull Comparator<T> comparator) { final List<Integer> indexes = new ArrayList<>(values.size()); for (int i = 0; i < values.size(); i++) { indexes.add(i); } ContainerUtil.sort(indexes, (i1, i2) -> { T val1 = values.get(indexes.get(i1)); T val2 = values.get(indexes.get(i2)); return comparator.compare(val1, val2); }); return ArrayUtil.toIntArray(indexes); }
Example 11
Source File: SeverityRegistrar.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private List<String> createCurrentSeverityNames() { List<String> list = new ArrayList<String>(); list.addAll(STANDARD_SEVERITIES.keySet()); list.addAll(myMap.keySet()); ContainerUtil.sort(list); return list; }
Example 12
Source File: AbstractDataGetter.java From consulo with Apache License 2.0 | 5 votes |
private void sortCommitsByRow(@Nonnull List<T> result, @Nonnull final TIntIntHashMap rowsForCommits) { ContainerUtil.sort(result, (details1, details2) -> { int row1 = rowsForCommits.get(myHashMap.getCommitIndex(details1.getId(), details1.getRoot())); int row2 = rowsForCommits.get(myHashMap.getCommitIndex(details2.getId(), details2.getRoot())); return Comparing.compare(row1, row2); }); }
Example 13
Source File: PermanentLinearGraphBuilder.java From consulo with Apache License 2.0 | 5 votes |
private void fixUnderdoneEdges(@Nonnull NotNullFunction<CommitId, Integer> notLoadedCommitToId) { List<CommitId> commitIds = ContainerUtil.newArrayList(upAdjacentNodes.keySet()); ContainerUtil.sort(commitIds, new Comparator<CommitId>() { @Override public int compare(@Nonnull CommitId o1, @Nonnull CommitId o2) { return Collections.min(upAdjacentNodes.get(o1)) - Collections.min(upAdjacentNodes.get(o2)); } }); for (CommitId notLoadCommit : commitIds) { int notLoadId = notLoadedCommitToId.fun(notLoadCommit); for (int upNodeIndex : upAdjacentNodes.get(notLoadCommit)) { fixUnderdoneEdgeForNotLoadCommit(upNodeIndex, notLoadId); } } }
Example 14
Source File: StdArrangementSettings.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public List<? extends ArrangementMatchRule> getRulesSortedByPriority() { synchronized (myRulesByPriority) { if (myRulesByPriority.isEmpty()) { for (ArrangementSectionRule rule : mySectionRules) { myRulesByPriority.addAll(rule.getMatchRules()); } ContainerUtil.sort(myRulesByPriority); } } return myRulesByPriority; }
Example 15
Source File: StdArrangementExtendableSettings.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public List<? extends ArrangementMatchRule> getRulesSortedByPriority() { synchronized (myExtendedSectionRules) { if (myRulesByPriority.isEmpty()) { for (ArrangementSectionRule rule : getExtendedSectionRules()) { myRulesByPriority.addAll(rule.getMatchRules()); } ContainerUtil.sort(myRulesByPriority); } } return myRulesByPriority; }
Example 16
Source File: DefaultArrangementEntryMatcherSerializer.java From consulo with Apache License 2.0 | 5 votes |
@Override public void visit(@Nonnull ArrangementCompositeMatchCondition condition) { Element composite = new Element(COMPOSITE_CONDITION_NAME); register(composite); parent = composite; List<ArrangementMatchCondition> operands = ContainerUtilRt.newArrayList(condition.getOperands()); ContainerUtil.sort(operands, CONDITION_COMPARATOR); for (ArrangementMatchCondition c : operands) { c.invite(this); } }
Example 17
Source File: GetFromVcsAction.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void fillActions(DefaultActionGroup group) { final List<CheckoutProvider> providers = new ArrayList<>(CheckoutProvider.EXTENSION_POINT_NAME.getExtensionList()); ContainerUtil.sort(providers, new CheckoutProvider.CheckoutProviderComparator()); for (CheckoutProvider provider : providers) { group.add(new CheckoutAction(provider)); } }
Example 18
Source File: IndentUsageStatisticsImpl.java From consulo with Apache License 2.0 | 4 votes |
public IndentUsageStatisticsImpl(@Nonnull List<LineIndentInfo> lineInfos) { myLineInfos = lineInfos; buildIndentToUsagesMap(); myIndentUsages = toIndentUsageList(myIndentToUsagesMap); ContainerUtil.sort(myIndentUsages, DECREASING_ORDER); }
Example 19
Source File: AbstractExternalSystemConfigurable.java From consulo with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void prepareProjectSettings(@Nonnull SystemSettings s) { myProjectsModel = new DefaultListModel(); myProjectsList = new JBList(myProjectsModel); myProjectsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); addTitle(ExternalSystemBundle.message("settings.title.linked.projects", myExternalSystemId.getReadableName())); myComponent.add(new JBScrollPane(myProjectsList), ExternalSystemUiUtil.getFillLineConstraints(1)); addTitle(ExternalSystemBundle.message("settings.title.project.settings")); List<ProjectSettings> settings = ContainerUtilRt.newArrayList(s.getLinkedProjectsSettings()); myProjectsList.setVisibleRowCount(Math.max(3, Math.min(5, settings.size()))); ContainerUtil.sort(settings, new Comparator<ProjectSettings>() { @Override public int compare(ProjectSettings s1, ProjectSettings s2) { return getProjectName(s1.getExternalProjectPath()).compareTo(getProjectName(s2.getExternalProjectPath())); } }); myProjectSettingsControls.clear(); for (ProjectSettings setting : settings) { ExternalSystemSettingsControl<ProjectSettings> control = createProjectSettingsControl(setting); control.fillUi(myComponent, 1); myProjectsModel.addElement(getProjectName(setting.getExternalProjectPath())); myProjectSettingsControls.add(control); control.showUi(false); } myProjectsList.addListSelectionListener(new ListSelectionListener() { @SuppressWarnings("unchecked") @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } int i = myProjectsList.getSelectedIndex(); if (i < 0) { return; } if (myActiveProjectSettingsControl != null) { myActiveProjectSettingsControl.showUi(false); } myActiveProjectSettingsControl = myProjectSettingsControls.get(i); myActiveProjectSettingsControl.showUi(true); } }); if (!myProjectsModel.isEmpty()) { addTitle(ExternalSystemBundle.message("settings.title.system.settings", myExternalSystemId.getReadableName())); myProjectsList.setSelectedIndex(0); } }
Example 20
Source File: Unity3dAssetUtil.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@Nonnull public static VirtualFile[] sortAssetFiles(VirtualFile[] virtualFiles) { ContainerUtil.sort(virtualFiles, (o1, o2) -> weight(o1) - weight(o2)); return virtualFiles; }