From 764617d74124fa87c0606e0e7e86c8af725afab8 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 11 Jul 2013 15:21:14 +0400 Subject: [PATCH] [git] Better fix of equals & hashcode for GitRepoInfo We consider GitRepoInfos as equal if, in particular, they have the same set of remotes, while the order of these remotes in collection is not interesting. (Remotes are (or may be) supplied as ArrayLists, while equals for the ArrayList considers the order of the elements). Use LinkedHashSet to preserve the original ordering, but use the needed equality definition. --- .../src/git4idea/repo/GitRepoInfo.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java b/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java index 5e71115b5aa3..cbeb0c4268b1 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepoInfo.java @@ -22,6 +22,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.Set; /** * @author Kirill Likhodedov @@ -31,10 +33,10 @@ public class GitRepoInfo { @Nullable private final GitLocalBranch myCurrentBranch; @Nullable private final String myCurrentRevision; @NotNull private final Repository.State myState; - @NotNull private final Collection myRemotes; - @NotNull private final Collection myLocalBranches; - @NotNull private final Collection myRemoteBranches; - @NotNull private final Collection myBranchTrackInfos; + @NotNull private final Set myRemotes; + @NotNull private final Set myLocalBranches; + @NotNull private final Set myRemoteBranches; + @NotNull private final Set myBranchTrackInfos; public GitRepoInfo(@Nullable GitLocalBranch currentBranch, @Nullable String currentRevision, @NotNull Repository.State state, @NotNull Collection remotes, @NotNull Collection localBranches, @@ -42,10 +44,10 @@ public class GitRepoInfo { myCurrentBranch = currentBranch; myCurrentRevision = currentRevision; myState = state; - myRemotes = remotes; - myLocalBranches = localBranches; - myRemoteBranches = remoteBranches; - myBranchTrackInfos = branchTrackInfos; + myRemotes = new LinkedHashSet(remotes); + myLocalBranches = new LinkedHashSet(localBranches); + myRemoteBranches = new LinkedHashSet(remoteBranches); + myBranchTrackInfos = new LinkedHashSet(branchTrackInfos); } @Nullable