ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / committed / CommittedListsSequencesZipper.java
blob292b0bc6c274e3cb1e25e2d6ceb2342119619324
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs.changes.committed;
18 import com.intellij.openapi.util.Pair;
19 import com.intellij.openapi.vcs.RepositoryLocation;
20 import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
22 import java.util.*;
24 public class CommittedListsSequencesZipper {
25 private final VcsCommittedListsZipper myVcsPartner;
26 private final List<RepositoryLocation> myInLocations;
27 private final Map<String, List<CommittedChangeList>> myInLists;
29 public CommittedListsSequencesZipper(final VcsCommittedListsZipper vcsPartner) {
30 myVcsPartner = vcsPartner;
31 myInLocations = new ArrayList<RepositoryLocation>();
32 myInLists = new HashMap<String, List<CommittedChangeList>>();
35 public void add(final RepositoryLocation location, final List<CommittedChangeList> lists) {
36 myInLocations.add(location);
37 Collections.sort(lists, new Comparator<CommittedChangeList>() {
38 public int compare(final CommittedChangeList o1, final CommittedChangeList o2) {
39 final long num1 = myVcsPartner.getNumber(o1);
40 final long num2 = myVcsPartner.getNumber(o2);
41 return num1 == num2 ? 0 : (num1 < num2) ? -1 : 1;
43 });
44 myInLists.put(location.toPresentableString(), lists);
47 public List<CommittedChangeList> execute() {
48 final Pair<List<RepositoryLocationGroup>,List<RepositoryLocation>> groupingResult = myVcsPartner.groupLocations(myInLocations);
49 final List<CommittedChangeList> result = new ArrayList<CommittedChangeList>();
51 for (RepositoryLocation location : groupingResult.getSecond()) {
52 result.addAll(myInLists.get(location.toPresentableString()));
55 for (RepositoryLocationGroup group : groupingResult.getFirst()) {
56 final List<RepositoryLocation> locations = group.getLocations();
57 final List<List<CommittedChangeList>> lists = new ArrayList<List<CommittedChangeList>>(locations.size());
58 for (RepositoryLocation location : locations) {
59 lists.add(myInLists.get(location.toPresentableString()));
61 final SimiliarListsZipper zipper = new SimiliarListsZipper(lists, myVcsPartner, group);
62 zipper.zip();
63 result.addAll(zipper.getResult());
65 return result;