Skip to content

Commit

Permalink
Adding equals function and improve hash and equals function
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Nov 17, 2023
1 parent b09b182 commit 5b259d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.api.dataformat;

import java.util.Objects;

public class MediaPartialView extends View {

private String begin;
Expand Down Expand Up @@ -42,4 +44,18 @@ public void setExtent(String extent) {
this.extent = extent;
}

@Override
public boolean equals(Object o) {
if (!super.equals(o)) {
return false;
}
if (o == null || getClass().isInstance(o)) {
return false;
}
MediaPartialView mediaPartialView = (MediaPartialView) o;
return (Objects.isNull(begin) && Objects.isNull(mediaPartialView.begin)) || begin.equals(
mediaPartialView.getBegin());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((mediaFiles == null) ? 0 : mediaFiles.hashCode());
result = prime * result + ((mediaPartialView == null) ? 0 : mediaPartialView.hashCode());
result = prime * result + ((Objects.isNull(mediaPartialView) || Objects.isNull(mediaPartialView.getBegin()))
? 0
: mediaPartialView.getBegin().hashCode());
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || getClass().isInstance(o)) {
return false;
}
View view = (View) o;
Expand Down

0 comments on commit 5b259d5

Please sign in to comment.