Skip to content

Commit

Permalink
Merge pull request #1874 from dk2k/TIKA-4290_equals
Browse files Browse the repository at this point in the history
TIKA-4290 equals() should check the type of argument. Some changes im…
  • Loading branch information
THausherr committed Aug 4, 2024
1 parent f255fee commit fd57894
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,11 @@ private int getMetadataEntryHashCode(Entry<String, String[]> e) {

public boolean equals(Object o) {

if (o == null) {
if (!(o instanceof Metadata)) {
return false;
}

Metadata other = null;
try {
other = (Metadata) o;
} catch (ClassCastException cce) {
return false;
}
Metadata other = (Metadata) o;

if (other.size() != size()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,11 @@ public int hashCode() {

// Inherited JavaDoc
public boolean equals(Object obj) {

NGramEntry ngram = null;
try {
ngram = (NGramEntry) obj;
return ngram.seq.equals(seq);
} catch (Exception e) {
if (!(obj instanceof NGramEntry)) {
return false;
}
NGramEntry ngram = (NGramEntry) obj;
return ngram.seq.equals(seq);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ public void setAddress(Address address) {
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Affiliation)) {
return false;
}
Affiliation otherA = (Affiliation) obj;
return this.getAddress().equals(otherA.getAddress()) &&
this.getOrgName().equals(otherA.getOrgName());
Expand Down Expand Up @@ -633,6 +636,10 @@ public int hashCode() {
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof OrgName)) {
return false;
}

OrgName otherA = (OrgName) obj;

if (otherA.getTypeNames() != null) {
Expand Down Expand Up @@ -697,6 +704,9 @@ public void setType(String type) {
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof OrgTypeName)) {
return false;
}
OrgTypeName otherOrgName = (OrgTypeName) obj;
return this.type.equals(otherOrgName.getType()) &&
this.name.equals(otherOrgName.getName());
Expand Down Expand Up @@ -785,6 +795,9 @@ public void setCountry(Country country) {
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Address)) {
return false;
}
Address otherA = (Address) obj;
if (this.settlment == null) {
return otherA.getSettlment() == null;
Expand Down Expand Up @@ -870,6 +883,9 @@ public void setContent(String content) {
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Country)) {
return false;
}
Country otherC = (Country) obj;

if (this.key == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ public List<Byte> serializeToByteList() throws IOException {
*/
@Override
public boolean equals(Object obj) {
CellID another = (CellID) obj;

if (another == null) {
if (!(obj instanceof CellID)) {
return false;
}
CellID another = (CellID) obj;

if (another.extendGUID1 != null && another.extendGUID2 != null &&
this.extendGUID1 != null && this.extendGUID2 != null) {
Expand Down

0 comments on commit fd57894

Please sign in to comment.