Cleanup and fix hash code and equals

This commit is contained in:
René Pfeuffer
2020-05-07 11:03:57 +02:00
parent a9b9c77333
commit bdd4c244d5
14 changed files with 36 additions and 256 deletions

View File

@@ -48,8 +48,7 @@ public class BlameResult implements Serializable, Iterable<BlameLine> {
private int total; private int total;
public BlameResult(List<BlameLine> blameLines) { public BlameResult(List<BlameLine> blameLines) {
this.blameLines = blameLines; this(blameLines.size(), blameLines);
this.total = blameLines.size();
} }
public BlameResult(int total, List<BlameLine> blameLines) { public BlameResult(int total, List<BlameLine> blameLines) {

View File

@@ -48,8 +48,6 @@ public final class Branches implements Iterable<Branch> {
public Branches() { public Branches() {
} }
;
public Branches(Branch... branches) { public Branches(Branch... branches) {
this.branches = Lists.newArrayList(branches); this.branches = Lists.newArrayList(branches);
} }
@@ -63,7 +61,6 @@ public final class Branches implements Iterable<Branch> {
return getBranches().iterator(); return getBranches().iterator();
} }
public List<Branch> getBranches() { public List<Branch> getBranches() {
if (branches == null) { if (branches == null) {
branches = Lists.newArrayList(); branches = Lists.newArrayList();
@@ -71,4 +68,8 @@ public final class Branches implements Iterable<Branch> {
return branches; return branches;
} }
public void setBranches(List<Branch> branches) {
this.branches = branches;
}
} }

View File

@@ -40,8 +40,6 @@ public class BrowserResult implements Serializable {
public BrowserResult() { public BrowserResult() {
} }
;
public BrowserResult(String revision, FileObject file) { public BrowserResult(String revision, FileObject file) {
this(revision, revision, file); this(revision, revision, file);
} }

View File

@@ -148,7 +148,7 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
*/ */
public List<String> getBranches() { public List<String> getBranches() {
if (branches == null) { if (branches == null) {
branches = new ArrayList<String>(); branches = new ArrayList<>();
} }
return branches; return branches;
@@ -206,7 +206,7 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
*/ */
public List<String> getParents() { public List<String> getParents() {
if (parents == null) { if (parents == null) {
parents = new ArrayList<String>(); parents = new ArrayList<>();
} }
return parents; return parents;
@@ -219,7 +219,7 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
*/ */
public List<String> getTags() { public List<String> getTags() {
if (tags == null) { if (tags == null) {
tags = new ArrayList<String>(); tags = new ArrayList<>();
} }
return tags; return tags;

View File

@@ -24,7 +24,7 @@
package sonia.scm.repository; package sonia.scm.repository;
import com.google.common.base.Objects; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.io.Serializable; import java.io.Serializable;
@@ -37,6 +37,7 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@EqualsAndHashCode
@ToString @ToString
public class ChangesetPagingResult implements Iterable<Changeset>, Serializable { public class ChangesetPagingResult implements Iterable<Changeset>, Serializable {
@@ -71,27 +72,6 @@ public class ChangesetPagingResult implements Iterable<Changeset>, Serializable
this.branchName = branchName; this.branchName = branchName;
} }
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ChangesetPagingResult other = (ChangesetPagingResult) obj;
return Objects.equal(changesets, other.changesets)
&& Objects.equal(total, other.total);
}
@Override
public int hashCode() {
return Objects.hashCode(changesets, total);
}
/** /**
* Returns an iterator which can iterate over the current list of changesets. * Returns an iterator which can iterate over the current list of changesets.
* *

View File

@@ -50,8 +50,6 @@ public class Modifications implements Serializable {
public Modifications() { public Modifications() {
} }
;
public Modifications(List<String> added) { public Modifications(List<String> added) {
this(added, null, null); this(added, null, null);
} }

View File

@@ -46,8 +46,6 @@ public class SubRepository implements Serializable {
public SubRepository() { public SubRepository() {
} }
;
public SubRepository(String repositoryUrl) { public SubRepository(String repositoryUrl) {
this.repositoryUrl = repositoryUrl; this.repositoryUrl = repositoryUrl;
} }

View File

@@ -39,11 +39,8 @@ import lombok.ToString;
@Getter @Getter
public final class Tag { public final class Tag {
private String name; private final String name;
private String revision; private final String revision;
public Tag() {
}
/** /**
* Constructs a new tag. * Constructs a new tag.

View File

@@ -48,8 +48,6 @@ public final class Tags implements Iterable<Tag> {
public Tags() { public Tags() {
} }
;
public Tags(List<Tag> tags) { public Tags(List<Tag> tags) {
this.tags = tags; this.tags = tags;
} }

View File

@@ -24,11 +24,14 @@
package sonia.scm.repository.spi; package sonia.scm.repository.spi;
import lombok.EqualsAndHashCode;
/** /**
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.17 * @since 1.17
*/ */
@EqualsAndHashCode(callSuper = true)
public final class BlameCommandRequest extends FileBaseCommandRequest public final class BlameCommandRequest extends FileBaseCommandRequest
{ {

View File

@@ -24,10 +24,8 @@
package sonia.scm.repository.spi; package sonia.scm.repository.spi;
//~--- non-JDK imports -------------------------------------------------------- import lombok.EqualsAndHashCode;
import lombok.ToString;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import sonia.scm.repository.BrowserResult; import sonia.scm.repository.BrowserResult;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -37,6 +35,8 @@ import java.util.function.Consumer;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.17 * @since 1.17
*/ */
@EqualsAndHashCode(callSuper = true)
@ToString
public final class BrowseCommandRequest extends FileBaseCommandRequest public final class BrowseCommandRequest extends FileBaseCommandRequest
{ {
@@ -53,14 +53,6 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
this.updater = updater; this.updater = updater;
} }
//~--- methods --------------------------------------------------------------
/**
* {@inheritDoc}
*
*
* @return
*/
@Override @Override
public BrowseCommandRequest clone() public BrowseCommandRequest clone()
{ {
@@ -80,74 +72,6 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
return clone; return clone;
} }
/**
* {@inheritDoc}
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final BrowseCommandRequest other = (BrowseCommandRequest) obj;
return super.equals(obj)
&& Objects.equal(recursive, other.recursive)
&& Objects.equal(disableLastCommit, other.disableLastCommit)
&& Objects.equal(disableSubRepositoryDetection, other.disableSubRepositoryDetection)
&& Objects.equal(offset, other.offset)
&& Objects.equal(limit, other.limit);
}
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public int hashCode()
{
return Objects.hashCode(super.hashCode(), recursive, disableLastCommit,
disableSubRepositoryDetection, offset, limit);
}
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public String toString()
{
//J-
return MoreObjects.toStringHelper(this)
.add("path", getPath())
.add("revision", getRevision())
.add("recursive", recursive)
.add("disableLastCommit", disableLastCommit)
.add("disableSubRepositoryDetection", disableSubRepositoryDetection)
.add("limit", limit)
.add("offset", offset)
.toString();
//J+
}
//~--- set methods ----------------------------------------------------------
/** /**
* True to disable the last commit. * True to disable the last commit.
* *
@@ -292,5 +216,6 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
// WARNING / TODO: This field creates a reverse channel from the implementation to the API. This will break // WARNING / TODO: This field creates a reverse channel from the implementation to the API. This will break
// whenever the API runs in a different process than the SPI (for example to run explicit hosts for git repositories). // whenever the API runs in a different process than the SPI (for example to run explicit hosts for git repositories).
@EqualsAndHashCode.Exclude
private final transient Consumer<BrowserResult> updater; private final transient Consumer<BrowserResult> updater;
} }

View File

@@ -24,11 +24,14 @@
package sonia.scm.repository.spi; package sonia.scm.repository.spi;
import lombok.EqualsAndHashCode;
/** /**
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.17 * @since 1.17
*/ */
@EqualsAndHashCode(callSuper = true)
public final class CatCommandRequest extends FileBaseCommandRequest public final class CatCommandRequest extends FileBaseCommandRequest
{ {

View File

@@ -27,7 +27,7 @@ package sonia.scm.repository.spi;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Strings; import com.google.common.base.Strings;
import lombok.EqualsAndHashCode;
import sonia.scm.Validateable; import sonia.scm.Validateable;
import sonia.scm.repository.api.DiffFormat; import sonia.scm.repository.api.DiffFormat;
@@ -36,21 +36,12 @@ import sonia.scm.repository.api.DiffFormat;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.17 * @since 1.17
*/ */
@EqualsAndHashCode(callSuper = true)
public final class DiffCommandRequest extends FileBaseCommandRequest public final class DiffCommandRequest extends FileBaseCommandRequest
implements Validateable implements Validateable {
{
/** Field description */
private static final long serialVersionUID = 4026911212676859626L; private static final long serialVersionUID = 4026911212676859626L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override @Override
public DiffCommandRequest clone() public DiffCommandRequest clone()
{ {
@@ -70,14 +61,6 @@ public final class DiffCommandRequest extends FileBaseCommandRequest
return clone; return clone;
} }
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override @Override
public boolean isValid() public boolean isValid()
{ {
@@ -85,8 +68,6 @@ public final class DiffCommandRequest extends FileBaseCommandRequest
||!Strings.isNullOrEmpty(getRevision()); ||!Strings.isNullOrEmpty(getRevision());
} }
//~--- set methods ----------------------------------------------------------
/** /**
* Sets the diff format which should be used for the output. * Sets the diff format which should be used for the output.
* *
@@ -103,7 +84,6 @@ public final class DiffCommandRequest extends FileBaseCommandRequest
public void setAncestorChangeset(String ancestorChangeset) { public void setAncestorChangeset(String ancestorChangeset) {
this.ancestorChangeset = ancestorChangeset; this.ancestorChangeset = ancestorChangeset;
} }
//~--- get methods ----------------------------------------------------------
/** /**
* Return the output format of the diff command. * Return the output format of the diff command.
@@ -121,7 +101,6 @@ public final class DiffCommandRequest extends FileBaseCommandRequest
public String getAncestorChangeset() { public String getAncestorChangeset() {
return ancestorChangeset; return ancestorChangeset;
} }
//~--- fields ---------------------------------------------------------------
/** diff format */ /** diff format */
private DiffFormat format = DiffFormat.NATIVE; private DiffFormat format = DiffFormat.NATIVE;

View File

@@ -26,8 +26,8 @@ package sonia.scm.repository.spi;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.MoreObjects; import lombok.EqualsAndHashCode;
import com.google.common.base.Objects; import lombok.ToString;
import java.io.Serializable; import java.io.Serializable;
@@ -38,54 +38,14 @@ import java.io.Serializable;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.17 * @since 1.17
*/ */
@EqualsAndHashCode
@ToString
public abstract class FileBaseCommandRequest public abstract class FileBaseCommandRequest
implements Resetable, Serializable, Cloneable implements Resetable, Serializable, Cloneable {
{
/** Field description */ /** Field description */
private static final long serialVersionUID = -3442101119408346165L; private static final long serialVersionUID = -3442101119408346165L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final FileBaseCommandRequest other = (FileBaseCommandRequest) obj;
return Objects.equal(path, other.path)
&& Objects.equal(revision, other.revision);
}
/**
* Method description
*
*
* @return
*/
@Override
public int hashCode()
{
return Objects.hashCode(path, revision);
}
/** /**
* Method description * Method description
* *
@@ -97,81 +57,26 @@ public abstract class FileBaseCommandRequest
revision = null; revision = null;
} }
/**
* Method description
*
*
* @return
*/
@Override
public String toString()
{
//J-
return MoreObjects.toStringHelper(this)
.add("path", path)
.add("revision", revision)
.toString();
//J+
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param path
*/
public void setPath(String path) public void setPath(String path)
{ {
this.path = path; this.path = path;
} }
/**
* Method description
*
*
* @param revision
*/
public void setRevision(String revision) public void setRevision(String revision)
{ {
this.revision = revision; this.revision = revision;
} }
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getPath() public String getPath()
{ {
return path; return path;
} }
/**
* Method description
*
*
* @return
*/
public String getRevision() public String getRevision()
{ {
return revision; return revision;
} }
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*
* @throws CloneNotSupportedException
*/
@Override @Override
protected FileBaseCommandRequest clone() throws CloneNotSupportedException protected FileBaseCommandRequest clone() throws CloneNotSupportedException
{ {
@@ -192,11 +97,7 @@ public abstract class FileBaseCommandRequest
return clone; return clone;
} }
//~--- fields ---------------------------------------------------------------
/** Field description */
private String path; private String path;
/** Field description */
private String revision; private String revision;
} }