Browse Source

PushCertificate: implement hashCode/equals/toString

Change-Id: Ib588a3f47492cee5e5e6274a3b088678919a0fa0
stable-4.1
Dave Borowitz 10 years ago
parent
commit
a643aaaa4a
  1. 42
      org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java

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

@ -50,6 +50,7 @@ import static org.eclipse.jgit.transport.PushCertificateParser.VERSION;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
@ -216,4 +217,45 @@ public class PushCertificate {
} }
return sb.toString(); 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 + ']';
}
} }

Loading…
Cancel
Save