]> source.dussan.org Git - jgit.git/commitdiff
PushCertificate: implement hashCode/equals/toString 04/51204/7
authorDave Borowitz <dborowitz@google.com>
Wed, 1 Jul 2015 16:42:35 +0000 (09:42 -0700)
committerDave Borowitz <dborowitz@google.com>
Thu, 9 Jul 2015 18:15:41 +0000 (11:15 -0700)
Change-Id: Ib588a3f47492cee5e5e6274a3b088678919a0fa0

org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java

index 165a93908d20c633bc9d5c48979ff1b7db728403..413b02b1c8d480f6099121443d00980d41f9dc07 100644 (file)
@@ -50,6 +50,7 @@ import static org.eclipse.jgit.transport.PushCertificateParser.VERSION;
 
 import java.text.MessageFormat;
 import java.util.List;
+import java.util.Objects;
 
 import org.eclipse.jgit.internal.JGitText;
 
@@ -216,4 +217,45 @@ public class PushCertificate {
                }
                return sb.toString();
        }
+
+       @Override
+       public int hashCode() {
+               return signature.hashCode();
+       }
+
+       @Override
+       public boolean equals(Object o) {
+               if (!(o instanceof PushCertificate)) {
+                       return false;
+               }
+               PushCertificate p = (PushCertificate) o;
+               return version.equals(p.version)
+                               && pusher.equals(p.pusher)
+                               && Objects.equals(pushee, p.pushee)
+                               && nonceStatus == p.nonceStatus
+                               && signature.equals(p.signature)
+                               && commandsEqual(this, p);
+       }
+
+       private static boolean commandsEqual(PushCertificate c1, PushCertificate c2) {
+               if (c1.commands.size() != c2.commands.size()) {
+                       return false;
+               }
+               for (int i = 0; i < c1.commands.size(); i++) {
+                       ReceiveCommand cmd1 = c1.commands.get(i);
+                       ReceiveCommand cmd2 = c2.commands.get(i);
+                       if (!cmd1.getOldId().equals(cmd2.getOldId())
+                                       || !cmd1.getNewId().equals(cmd2.getNewId())
+                                       || !cmd1.getRefName().equals(cmd2.getRefName())) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       @Override
+       public String toString() {
+               return getClass().getSimpleName() + '['
+                                + toText() + signature + ']';
+       }
 }