Skip to content

Commit

Permalink
GH-4718 check returned value when adding/removing to deprecated/appro…
Browse files Browse the repository at this point in the history
…ved models so that we can update the approvedEmpty and deprecatedEmpty more efficiently
  • Loading branch information
hmottestad committed Aug 5, 2023
1 parent 5abd412 commit 36fb4be
Showing 1 changed file with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,17 @@ public void approve(Statement statement) {
try {

if (deprecated != null) {
deprecated.remove(statement);
deprecatedEmpty = deprecated == null || deprecated.isEmpty();
boolean removed = deprecated.remove(statement);
if (removed) {
deprecatedEmpty = deprecated == null || deprecated.isEmpty();
}
}
if (approved == null) {
approved = createEmptyModel();
}
approved.add(statement);
approvedEmpty = approved == null || approved.isEmpty();
approvedEmpty = false;

if (statement.getContext() != null) {
if (approvedContexts == null) {
approvedContexts = new HashSet<>();
Expand All @@ -440,14 +443,16 @@ public void deprecate(Statement statement) {
long writeLock = readWriteLock.writeLock();
try {
if (approved != null) {
approved.remove(statement);
approvedEmpty = approved == null || approved.isEmpty();
boolean removed = approved.remove(statement);
if (removed) {
approvedEmpty = approved == null || approved.isEmpty();
}
}
if (deprecated == null) {
deprecated = createEmptyModel();
}
deprecated.add(statement);
deprecatedEmpty = deprecated == null || deprecated.isEmpty();
deprecatedEmpty = false;
Resource ctx = statement.getContext();
if (approvedContexts != null && approvedContexts.contains(ctx)
&& !approved.contains(null, null, null, ctx)) {
Expand Down Expand Up @@ -879,13 +884,18 @@ public void approveAll(Set<Statement> approve, Set<Resource> approveContexts) {
try {

if (deprecated != null) {
deprecated.removeAll(approve);
boolean changed = deprecated.removeAll(approve);
if (changed) {
deprecatedEmpty = deprecated == null || deprecated.isEmpty();
}
}
if (approved == null) {
approved = createEmptyModel();
}
approved.addAll(approve);
approvedEmpty = approved == null || approved.isEmpty();
boolean changed = approved.addAll(approve);
if (changed) {
approvedEmpty = false;
}

if (approveContexts != null) {
if (approvedContexts == null) {
Expand All @@ -905,14 +915,18 @@ public void deprecateAll(Set<Statement> deprecate) {
try {

if (approved != null) {
approved.removeAll(deprecate);
approvedEmpty = approved == null || approved.isEmpty();
boolean changed = approved.removeAll(deprecate);
if (changed) {
approvedEmpty = approved == null || approved.isEmpty();
}
}
if (deprecated == null) {
deprecated = createEmptyModel();
}
deprecated.addAll(deprecate);
deprecatedEmpty = deprecated == null || deprecated.isEmpty();
boolean changed = deprecated.addAll(deprecate);
if (changed) {
deprecatedEmpty = false;
}

for (Statement statement : deprecate) {
Resource ctx = statement.getContext();
Expand Down

0 comments on commit 36fb4be

Please sign in to comment.