Consolidated equals and hashcode for all BaseEntities.

This commit is contained in:
Kai Zimmermann
2016-03-31 09:31:47 +02:00
parent c1b3b40a9d
commit 52cc957cfb
21 changed files with 137 additions and 372 deletions

View File

@@ -52,7 +52,7 @@ import org.eclipse.persistence.annotations.CascadeOnDelete;
@NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"),
@NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) })
@Entity
public class Action extends TenantAwareBaseEntity implements Comparable<Action> {
public class Action extends TenantAwareBaseEntity {
private static final long serialVersionUID = 1L;
/**
@@ -198,14 +198,6 @@ public class Action extends TenantAwareBaseEntity implements Comparable<Action>
this.rollout = rollout;
}
@Override
public int compareTo(final Action o) {
if (super.getId() == null || o == null || o.getId() == null) {
return 0;
}
return super.getId().compareTo(o.getId());
}
/**
* checks if the {@link #forcedTime} is hit by the given
* {@code hitTimeMillis}, by means if the given milliseconds are greater
@@ -254,26 +246,6 @@ public class Action extends TenantAwareBaseEntity implements Comparable<Action>
return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof Action)) {
return false;
}
return true;
}
/**
* Action status as reported by the controller.
*

View File

@@ -140,24 +140,4 @@ public class ActionStatus extends TenantAwareBaseEntity {
this.status = status;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ActionStatus)) {
return false;
}
return true;
}
}

View File

@@ -53,24 +53,4 @@ public abstract class Artifact extends TenantAwareBaseEntity {
public void setSize(final Long size) {
this.size = size;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof Artifact)) {
return false;
}
return true;
}
}

View File

@@ -108,6 +108,11 @@ public abstract class BaseEntity implements Serializable, Identifiable<Long> {
return optLockRevision;
}
// for test purposes only
void setOptLockRevision(final long optLockRevision) {
this.optLockRevision = optLockRevision;
}
@Override
public Long getId() {
return id;
@@ -135,6 +140,7 @@ public abstract class BaseEntity implements Serializable, Identifiable<Long> {
int result = 1;
result = prime * result + (id == null ? 0 : id.hashCode());
result = prime * result + (int) (optLockRevision ^ optLockRevision >>> 32);
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@@ -154,7 +160,7 @@ public abstract class BaseEntity implements Serializable, Identifiable<Long> {
if (obj == null) {
return false;
}
if (!(obj instanceof BaseEntity)) {
if (!(this.getClass().isInstance(obj))) {
return false;
}
final BaseEntity other = (BaseEntity) obj;

View File

@@ -150,26 +150,6 @@ public class DistributionSet extends NamedVersionedEntity {
return actions;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof DistributionSet)) {
return false;
}
return true;
}
public boolean isRequiredMigrationStep() {
return requiredMigrationStep;
}

View File

@@ -285,24 +285,4 @@ public class DistributionSetType extends NamedEntity {
return "DistributionSetType [key=" + key + ", isDeleted()=" + isDeleted() + ", getId()=" + getId() + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof DistributionSetType)) {
return false;
}
return true;
}
}

View File

@@ -73,24 +73,4 @@ public class ExternalArtifactProvider extends NamedEntity {
this.defaultSuffix = defaultSuffix;
}
@Override
public int hashCode() { // NOSONAR - as this is generated
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) { // NOSONAR - as this is generated
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ExternalArtifactProvider)) {
return false;
}
return true;
}
}

View File

@@ -60,24 +60,4 @@ public abstract class NamedEntity extends TenantAwareBaseEntity {
public void setName(final String name) {
this.name = name;
}
@Override
public int hashCode() { // NOSONAR - as this is generated
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) { // NOSONAR - as this is generated
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof NamedEntity)) {
return false;
}
return true;
}
}

View File

@@ -47,25 +47,4 @@ public abstract class NamedVersionedEntity extends NamedEntity {
public void setVersion(final String version) {
this.version = version;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof NamedVersionedEntity)) {
return false;
}
return true;
}
}

View File

@@ -231,24 +231,4 @@ public class Rollout extends NamedEntity {
*/
ERROR_STARTING;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof Rollout)) {
return false;
}
return true;
}
}

View File

@@ -476,25 +476,4 @@ public class RolloutGroup extends NamedEntity {
return this;
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof RolloutGroup)) {
return false;
}
return true;
}
}

View File

@@ -233,26 +233,6 @@ public class SoftwareModule extends NamedVersionedEntity {
+ ", revision=" + getOptLockRevision() + ", Id=" + getId() + ", type=" + getType().getName() + "]";
}
@Override
public int hashCode() { // NOSONAR - as this is generated
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) { // NOSONAR - as this is generated
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof SoftwareModule)) {
return false;
}
return true;
}
/**
* @return the assignedTo
*/

View File

@@ -114,24 +114,4 @@ public class SoftwareModuleType extends NamedEntity {
public String toString() {
return "SoftwareModuleType [key=" + key + ", getName()=" + getName() + ", getId()=" + getId() + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof SoftwareModuleType)) {
return false;
}
return true;
}
}

View File

@@ -56,24 +56,4 @@ public abstract class Tag extends NamedEntity implements Identifiable<Long> {
public String toString() {
return "Tag [getOptLockRevision()=" + getOptLockRevision() + ", getId()=" + getId() + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof Tag)) {
return false;
}
return true;
}
}

View File

@@ -131,31 +131,6 @@ public class Target extends NamedEntity implements Persistable<Long> {
securityToken = null;
}
/**
* Note: For Target we extended the general strategy by adding controllerId
* as well.
*
* @see org.eclipse.hawkbit.repository.model.BaseEntity#equals(java.lang.Object)
*/
@Override
public boolean equals(final Object obj) {// NOSONAR - as this is generated
if (obj == null) {
return false;
}
if (!(obj instanceof Target)) {
return false;
}
final Target other = (Target) obj;
if (controllerId == null) {
if (other.controllerId != null) {
return false;
}
} else if (!controllerId.equals(other.controllerId)) {
return false;
}
return true;
}
public DistributionSet getAssignedDistributionSet() {
return assignedDistributionSet;
}
@@ -168,14 +143,6 @@ public class Target extends NamedEntity implements Persistable<Long> {
return tags;
}
@Override
public int hashCode() { // NOSONAR - as this is generated
final int prime = 31;
int result = 1;
result = prime * result + (controllerId == null ? 0 : controllerId.hashCode());
return result;
}
public void setAssignedDistributionSet(final DistributionSet assignedDistributionSet) {
this.assignedDistributionSet = assignedDistributionSet;
}

View File

@@ -55,24 +55,4 @@ public class TargetFilterQuery extends TenantAwareBaseEntity {
public void setQuery(final String query) {
this.query = query;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof TargetFilterQuery)) {
return false;
}
return true;
}
}

View File

@@ -99,9 +99,6 @@ public abstract class TenantAwareBaseEntity extends BaseEntity {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof TenantAwareBaseEntity)) {
return false;
}
final TenantAwareBaseEntity other = (TenantAwareBaseEntity) obj;
if (tenant == null) {
if (other.tenant != null) {

View File

@@ -52,54 +52,20 @@ public class TenantConfiguration extends TenantAwareBaseEntity implements Serial
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key
* the key to set
*/
public void setKey(final String key) {
this.key = key;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value
* the value to set
*/
public void setValue(final String value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof TenantConfiguration)) {
return false;
}
return true;
}
}