PushCertificate: implement hashCode/equals/toString
Change-Id: Ib588a3f47492cee5e5e6274a3b088678919a0fa0
This commit is contained in:
parent
8293c770b5
commit
a643aaaa4a
|
@ -50,6 +50,7 @@
|
|||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jgit.internal.JGitText;
|
||||
|
||||
|
@ -216,4 +217,45 @@ public String toText() {
|
|||
}
|
||||
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…
Reference in New Issue