Skip to content

Commit

Permalink
GH-5015 improvements to AbstractIRI and models
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Jun 5, 2024
1 parent e71e876 commit 1dfd824
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,23 @@ public boolean equals(Object o) {
return false;
}

private int cachedHashCode = 0;

@Override
public int hashCode() {
return stringValue().hashCode();
int cached = cachedHashCode;
if (cached == 0) {
synchronized (this) {
cached = cachedHashCode;
if (cached == 0) {
cached = stringValue().hashCode();
cachedHashCode = cached;
}
}
cached = stringValue().hashCode();
cachedHashCode = cached;
}
return cached;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public abstract class AbstractModel extends AbstractSet<Statement> implements Model {

private static final long serialVersionUID = 4254119331281455614L;
public static final Resource[] NULL_CONTEXT = { null };

@Override
public Model unmodifiable() {
Expand Down Expand Up @@ -179,6 +180,9 @@ public boolean remove(Object o) {
public boolean contains(Object o) {
if (o instanceof Statement) {
Statement st = (Statement) o;
if (st.getContext() == null) {
return contains(st.getSubject(), st.getPredicate(), st.getObject(), NULL_CONTEXT);
}
return contains(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext());
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (other == statement) {
return true;
}

if (!super.equals(other)) {
return false;
}
Expand Down

0 comments on commit 1dfd824

Please sign in to comment.