Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Add missing hashCode() methods to all classes overriding equals() #8031

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void setTempID(Long tempID) {
this.tempIDTransient = tempID;
}

@Override
public int hashCode() {
// Important: do not include the tempId in the hash code
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved
return super.hashCode();
}

/**
* checks the tempId first and then the database id
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import de.tum.in.www1.artemis.service.compass.umlmodel.deployment.UMLNode;

Expand Down Expand Up @@ -57,6 +58,11 @@ public void removeSubElement(UMLNode umlElement) {
umlElement.setParentElement(null);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), subElements);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import de.tum.in.www1.artemis.service.compass.strategy.NameSimilarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.Similarity;
Expand Down Expand Up @@ -60,6 +61,11 @@ public void addChildElement(UMLActivityElement childElement) {
childElements.add(childElement);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), childElements);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public void setParentActivity(@Nullable UMLActivity parentActivity) {
this.parentActivity = parentActivity;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public UMLActivityElement getTarget() {
return target;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, target);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public BPMNFlowType getFlowType() {
return flowType;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name, source, target, flowType);
}

@Override
public boolean equals(Object object) {
if (!super.equals(object)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public String getType() {
return UML_ATTRIBUTE_TYPE;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name, attributeType);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -236,6 +237,11 @@ public int getElementCount() {
return getAttributes().size() + getMethods().size() + 1;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name, classType, umlPackage, attributes, methods);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public String getType() {
return UML_METHOD_TYPE;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), completeName, name, returnType, parameters);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import de.tum.in.www1.artemis.service.compass.strategy.NameSimilarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.Similarity;
Expand Down Expand Up @@ -45,6 +46,11 @@ public String getType() {
return UML_PACKAGE_TYPE;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public UMLClass getTarget() {
return target;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, target, sourceRole, targetRole, sourceMultiplicity, targetMultiplicity, relationshipType);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public UMLObject getTarget() {
return target;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, target, messages);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.in.www1.artemis.service.compass.umlmodel.component;

import java.util.Objects;

import de.tum.in.www1.artemis.service.compass.strategy.NameSimilarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.Similarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.UMLContainerElement;
Expand Down Expand Up @@ -50,6 +52,11 @@ public String getType() {
return UML_COMPONENT_TYPE;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.in.www1.artemis.service.compass.umlmodel.component;

import java.util.Objects;

import de.tum.in.www1.artemis.service.compass.strategy.NameSimilarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.Similarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.UMLElement;
Expand Down Expand Up @@ -73,6 +75,11 @@ public String getType() {
return UML_COMPONENT_INTERFACE_TYPE;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public UMLElement getTarget() {
return target;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, target, type);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.in.www1.artemis.service.compass.umlmodel.deployment;

import java.util.Objects;

import de.tum.in.www1.artemis.service.compass.strategy.NameSimilarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.Similarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.UMLElement;
Expand Down Expand Up @@ -49,6 +51,11 @@ public String getType() {
return UML_ARTIFACT_TYPE;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.in.www1.artemis.service.compass.umlmodel.deployment;

import java.util.Objects;

import de.tum.in.www1.artemis.service.compass.strategy.NameSimilarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.Similarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.UMLContainerElement;
Expand Down Expand Up @@ -57,6 +59,11 @@ public String getType() {
return UML_NODE_TYPE;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name, stereotype);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public UMLElement getTarget() {
return target;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, target);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public UMLObject getTarget() {
return target;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, target);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public String getMultiplicity() {
return multiplicity;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, target, multiplicity);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public UMLElement getTarget() {
return target;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, target);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.in.www1.artemis.service.compass.umlmodel.usecase;

import java.util.Objects;

import de.tum.in.www1.artemis.service.compass.strategy.NameSimilarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.Similarity;
import de.tum.in.www1.artemis.service.compass.umlmodel.UMLContainerElement;
Expand Down Expand Up @@ -44,6 +46,11 @@ public String getType() {
return UML_SYSTEM_BOUNDARY_TYPE;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public UMLElement getTarget() {
return target;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name, source, target, type);
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public void setCommonChanges(Collection<ChangeBlock> commonChanges) {
this.commonChanges = new TreeSet<>(commonChanges);
}

@Override
public int hashCode() {
return Objects.hash(filePath, testCase, gitDiffEntries, coverageReportEntries, fileContent, changedLines, coveredLines, commonLines, commonChanges);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand Down
Loading