Implement equals/hashCode/toString in CommitInfo and friends
Change-Id: I16f4f6858e47571b4911694d7d6695ced5c1a400
This commit is contained in:
@@ -14,7 +14,10 @@
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CommitInfo {
|
||||
public String commit;
|
||||
@@ -24,4 +27,40 @@ public class CommitInfo {
|
||||
public String subject;
|
||||
public String message;
|
||||
public List<WebLinkInfo> webLinks;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof CommitInfo)) {
|
||||
return false;
|
||||
}
|
||||
CommitInfo c = (CommitInfo) o;
|
||||
return Objects.equals(commit, c.commit)
|
||||
&& Objects.equals(parents, c.parents)
|
||||
&& Objects.equals(author, c.author)
|
||||
&& Objects.equals(committer, c.committer)
|
||||
&& Objects.equals(subject, c.subject)
|
||||
&& Objects.equals(message, c.message)
|
||||
&& Objects.equals(webLinks, c.webLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(commit, parents, author, committer, subject, message, webLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// Using something like the raw commit format might be nice, but we can't depend on JGit here.
|
||||
StringBuilder sb = new StringBuilder().append(getClass().getSimpleName()).append('{');
|
||||
sb.append(commit);
|
||||
sb.append(", parents=").append(parents.stream().map(p -> p.commit).collect(joining(", ")));
|
||||
sb.append(", author=").append(author);
|
||||
sb.append(", committer=").append(committer);
|
||||
sb.append(", subject=").append(subject);
|
||||
sb.append(", message=").append(message);
|
||||
if (webLinks != null) {
|
||||
sb.append(", webLinks=").append(webLinks);
|
||||
}
|
||||
return sb.append('}').toString();
|
||||
}
|
||||
}
|
||||
|
@@ -15,10 +15,42 @@
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Objects;
|
||||
|
||||
public class GitPerson {
|
||||
public String name;
|
||||
public String email;
|
||||
public Timestamp date;
|
||||
public int tz;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof GitPerson)) {
|
||||
return false;
|
||||
}
|
||||
GitPerson p = (GitPerson) o;
|
||||
return Objects.equals(name, p.name)
|
||||
&& Objects.equals(email, p.email)
|
||||
&& Objects.equals(date, p.date)
|
||||
&& tz == p.tz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, email, date, tz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()
|
||||
+ "{name="
|
||||
+ name
|
||||
+ ", email="
|
||||
+ email
|
||||
+ ", date="
|
||||
+ date
|
||||
+ ", tz="
|
||||
+ tz
|
||||
+ "}".toString();
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import com.google.gerrit.extensions.webui.WebLink.Target;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WebLinkInfo {
|
||||
public String name;
|
||||
@@ -32,4 +33,35 @@ public class WebLinkInfo {
|
||||
public WebLinkInfo(String name, String imageUrl, String url) {
|
||||
this(name, imageUrl, url, Target.SELF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof WebLinkInfo)) {
|
||||
return false;
|
||||
}
|
||||
WebLinkInfo i = (WebLinkInfo) o;
|
||||
return Objects.equals(name, i.name)
|
||||
&& Objects.equals(imageUrl, i.imageUrl)
|
||||
&& Objects.equals(url, i.url)
|
||||
&& Objects.equals(target, i.target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, imageUrl, url, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()
|
||||
+ "{name="
|
||||
+ name
|
||||
+ ", imageUrl="
|
||||
+ imageUrl
|
||||
+ ", url="
|
||||
+ url
|
||||
+ ", target"
|
||||
+ target
|
||||
+ "}".toString();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user