/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package git4idea.util;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Couple;
import com.intellij.openapi.vcs.changes.Change;
import git4idea.GitCommit;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;

import java.util.*;

/**
 * @author Kirill Likhodedov
 */
public class GitCommitCompareInfo {
  
  private static final Logger LOG = Logger.getInstance(GitCommitCompareInfo.class);
  
  private final Map<GitRepository, Couple<List<GitCommit>>> myInfo = new HashMap<GitRepository, Couple<List<GitCommit>>>();
  private final Map<GitRepository, Collection<Change>> myTotalDiff = new HashMap<GitRepository, Collection<Change>>();
  private final InfoType myInfoType;

  public GitCommitCompareInfo() {
    this(InfoType.BOTH);
  }

  public GitCommitCompareInfo(@NotNull InfoType infoType) {
    myInfoType = infoType;
  }

  public void put(@NotNull GitRepository repository, @NotNull Couple<List<GitCommit>> commits) {
    myInfo.put(repository, commits);
  }

  public void put(@NotNull GitRepository repository, @NotNull Collection<Change> totalDiff) {
    myTotalDiff.put(repository, totalDiff);
  }

  @NotNull
  public List<GitCommit> getHeadToBranchCommits(@NotNull GitRepository repo) {
    return getCompareInfo(repo).getFirst();
  }
  
  @NotNull
  public List<GitCommit> getBranchToHeadCommits(@NotNull GitRepository repo) {
    return getCompareInfo(repo).getSecond();
  }

  @NotNull
  private Couple<List<GitCommit>> getCompareInfo(@NotNull GitRepository repo) {
    Couple<List<GitCommit>> pair = myInfo.get(repo);
    if (pair == null) {
      LOG.error("Compare info not found for repository " + repo);
      return Couple.of(Collections.<GitCommit>emptyList(), Collections.<GitCommit>emptyList());
    }
    return pair;
  }

  @NotNull
  public Collection<GitRepository> getRepositories() {
    return myInfo.keySet();
  }

  public boolean isEmpty() {
    return myInfo.isEmpty();
  }

  public InfoType getInfoType() {
    return myInfoType;
  }

  @NotNull
  public List<Change> getTotalDiff() {
    List<Change> changes = new ArrayList<Change>();
    for (Collection<Change> changeCollection : myTotalDiff.values()) {
      changes.addAll(changeCollection);
    }
    return changes;
  }

  public enum InfoType {
    BOTH, HEAD_TO_BRANCH, BRANCH_TO_HEAD
  }
}

@@ -698,22 +698,20 @@
 pi.util.
-Couple
+Pair
 ;%0Aimport
@@ -1069,39 +1069,54 @@
 %3CGitRepository, 
-Couple%3C
+Pair%3CList%3CGitCommit%3E, 
 List%3CGitCommit%3E%3E
@@ -1153,23 +1153,38 @@
 sitory, 
-Couple%3C
+Pair%3CList%3CGitCommit%3E, 
 List%3CGit
@@ -1571,23 +1571,38 @@
 NotNull 
-Couple%3C
+Pair%3CList%3CGitCommit%3E, 
 List%3CGit
@@ -2108,23 +2108,38 @@
 private 
-Couple%3C
+Pair%3CList%3CGitCommit%3E, 
 List%3CGit
@@ -2201,15 +2201,30 @@
     
-Couple%3C
+Pair%3CList%3CGitCommit%3E, 
 List
@@ -2368,17 +2368,19 @@
 urn 
-Couple.of
+Pair.create
 (Col

fix binary compatibility