Fix errors reported by latest version of ErrorProne

This commit is contained in:
Tim Donohue
2020-01-10 10:26:59 -06:00
parent f3e4bfa29a
commit 1982ceb076
6 changed files with 45 additions and 8 deletions

View File

@@ -15,7 +15,7 @@ package org.dspace.app.statistics;
* *
* @author Richard Jones * @author Richard Jones
*/ */
public class Stat implements Comparable { public class Stat implements Comparable<Stat> {
// FIXME: this class is functional but a bit messy, and should be neatened // FIXME: this class is functional but a bit messy, and should be neatened
// up and completed // up and completed
@@ -132,17 +132,17 @@ public class Stat implements Comparable {
/** /**
* compare the current object to the given object returning -1 if o is less * Compare the current Stat to the given Stat returning -1 if o is less
* than the current object, 0 if they are the same, and +1 if o is greater * than the current Stat, 0 if they are the same, and +1 if o is greater
* than the current object. * than the current Stat.
* *
* @param o the object to compare to the current one * @param stat the Stat object to compare to the current one
* @return +1, 0, -1 if o is less than, equal to, or greater than the * @return +1, 0, -1 if o is less than, equal to, or greater than the
* current object value. * current object value.
*/ */
@Override @Override
public int compareTo(Object o) { public int compareTo(Stat stat) {
int objectValue = ((Stat) o).getValue(); int objectValue = stat.getValue();
if (objectValue < this.getValue()) { if (objectValue < this.getValue()) {
return -1; return -1;

View File

@@ -7,6 +7,7 @@
*/ */
package org.dspace.discovery.configuration; package org.dspace.discovery.configuration;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.beans.factory.annotation.Required; import org.springframework.beans.factory.annotation.Required;
/** /**
@@ -46,4 +47,11 @@ public class DiscoverySortFieldConfiguration {
return false; return false;
} }
@Override
public int hashCode() {
return new HashCodeBuilder(3, 19)
.append(this.getMetadataField())
.append(this.getType())
.toHashCode();
}
} }

View File

@@ -11,6 +11,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/** /**
* This class serves as a representation of a command line parameter by holding a String name and a String value * This class serves as a representation of a command line parameter by holding a String name and a String value
@@ -95,6 +96,7 @@ public class DSpaceCommandLineParameter {
* @param other The other object * @param other The other object
* @return A boolean indicating equality * @return A boolean indicating equality
*/ */
@Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (other == null) { if (other == null) {
return false; return false;
@@ -105,4 +107,12 @@ public class DSpaceCommandLineParameter {
return StringUtils.equals(this.getName(), ((DSpaceCommandLineParameter) other).getName()) && StringUtils return StringUtils.equals(this.getName(), ((DSpaceCommandLineParameter) other).getName()) && StringUtils
.equals(this.getValue(), ((DSpaceCommandLineParameter) other).getValue()); .equals(this.getValue(), ((DSpaceCommandLineParameter) other).getValue());
} }
@Override
public int hashCode() {
return new HashCodeBuilder(5, 17)
.append(this.getName())
.append(this.getValue())
.toHashCode();
}
} }

View File

@@ -14,6 +14,7 @@ import java.util.TreeMap;
import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonAnySetter;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/** /**
* Rest representation of a map of metadata keys to ordered lists of values. * Rest representation of a map of metadata keys to ordered lists of values.
@@ -66,4 +67,11 @@ public class MetadataRest {
public boolean equals(Object object) { public boolean equals(Object object) {
return object instanceof MetadataRest && ((MetadataRest) object).getMap().equals(map); return object instanceof MetadataRest && ((MetadataRest) object).getMap().equals(map);
} }
}
@Override
public int hashCode() {
return new HashCodeBuilder(7, 37)
.append(this.getMap())
.toHashCode();
}
}

View File

@@ -10,6 +10,8 @@ package org.dspace.app.rest.model;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/** /**
* The SubmissionVisibility REST Resource. It is not addressable directly, only * The SubmissionVisibility REST Resource. It is not addressable directly, only
* used as inline object in the SubmissionPanel resource and SubmissionForm's fields * used as inline object in the SubmissionPanel resource and SubmissionForm's fields
@@ -49,4 +51,12 @@ public class SubmissionVisibilityRest {
} }
return super.equals(obj); return super.equals(obj);
} }
@Override
public int hashCode() {
return new HashCodeBuilder(5, 31)
.append(this.getMain())
.append(this.getOther())
.toHashCode();
}
} }

View File

@@ -1512,6 +1512,7 @@
<groupId>com.google.errorprone</groupId> <groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId> <artifactId>error_prone_core</artifactId>
<version>${errorprone.version}</version> <version>${errorprone.version}</version>
<scope>compile</scope>
</dependency> </dependency>
<!-- JMockit, JUnit and Hamcrest are used for Unit/Integration tests --> <!-- JMockit, JUnit and Hamcrest are used for Unit/Integration tests -->
<!-- Keep jmockit before junit --> <!-- Keep jmockit before junit -->