Skip to content

Commit

Permalink
fix sonar issues (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
slashgk authored Oct 4, 2023
1 parent dc22d0a commit f26cf96
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public abstract class AbstractResourceSession<R extends NodeReadOnlyTrx & NodeCu
*/
private final PageTrxFactory pageTrxFactory;

/**
* ID Generation exception message for duplicate ID.
*/
private final String ID_GENERATION_EXCEPTION = "ID generation is bogus because of duplicate ID.";

/**
* Creates a new instance of this class.
*
Expand Down Expand Up @@ -347,7 +352,7 @@ public synchronized R beginNodeReadOnlyTrx(@NonNegative final int revision) {

// Remember reader for debugging and safe close.
if (nodeTrxMap.put(reader.getId(), reader) != null) {
throw new SirixUsageException("ID generation is bogus because of duplicate ID.");
throw new SirixUsageException(ID_GENERATION_EXCEPTION);
}

return reader;
Expand Down Expand Up @@ -450,7 +455,7 @@ public synchronized W beginNodeTrx(final @NonNegative int maxNodeCount, final @N

// Remember node transaction for debugging and safe close.
if (nodeTrxMap.put(nodeTrxId, (R) wtx) != null || nodePageTrxMap.put(nodeTrxId, pageWtx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
throw new SirixThreadedException(ID_GENERATION_EXCEPTION);
}

return wtx;
Expand Down Expand Up @@ -721,7 +726,7 @@ public PageReadOnlyTrx beginPageReadOnlyTrx(final @NonNegative int revision) {

// Remember page transaction for debugging and safe close.
if (pageTrxMap.put(currentPageTrxID, pageReadTrx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
throw new SirixThreadedException(ID_GENERATION_EXCEPTION);
}

return pageReadTrx;
Expand All @@ -748,7 +753,7 @@ public synchronized PageTrx beginPageTrx(final @NonNegative int revision) {

// Remember page transaction for debugging and safe close.
if (pageTrxMap.put(currentPageTrxID, pageTrx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
throw new SirixThreadedException(ID_GENERATION_EXCEPTION);
}

return pageTrx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public final class JsonNodeReadOnlyTrxImpl
super(trxId, pageReadTransaction, documentNode, resourceManager, new ItemListImpl());
}

private final String INSERT = "insert";
private final String UPDATE = "update";
private final String DELETE = "delete";
private final String REPLACE = "replace";

@Override
public boolean hasLastChild() {
assertNotClosed();
Expand Down Expand Up @@ -103,10 +108,10 @@ private Consumer<JsonElement> serializeJsonFragmentIfNeeded(final List<JsonObjec
final var diffObject = diff.getAsJsonObject();

final JsonObject diffTupleObject;
if (diffObject.has("insert")) {
diffTupleObject = diffObject.getAsJsonObject("insert");
} else if (diffObject.has("replace")) {
diffTupleObject = diffObject.getAsJsonObject("replace");
if (diffObject.has(INSERT)) {
diffTupleObject = diffObject.getAsJsonObject(INSERT);
} else if (diffObject.has(REPLACE)) {
diffTupleObject = diffObject.getAsJsonObject(REPLACE);
} else {
diffTupleObject = null;
}
Expand Down Expand Up @@ -146,29 +151,29 @@ public List<JsonObject> getUpdateOperationsInSubtreeOfNode(final SirixDeweyID ro

private Comparator<JsonObject> sortByDeweyID() {
return Comparator.comparing(updateOperation -> {
if (updateOperation.has("insert")) {
return getDeweyID(updateOperation, "insert");
} else if (updateOperation.has("delete")) {
return getDeweyID(updateOperation, "delete");
} else if (updateOperation.has("update")) {
return getDeweyID(updateOperation, "update");
} else if (updateOperation.has("replace")) {
return getDeweyID(updateOperation, "replace");
if (updateOperation.has(INSERT)) {
return getDeweyID(updateOperation, INSERT);
} else if (updateOperation.has(DELETE)) {
return getDeweyID(updateOperation, DELETE);
} else if (updateOperation.has(UPDATE)) {
return getDeweyID(updateOperation, UPDATE);
} else if (updateOperation.has(REPLACE)) {
return getDeweyID(updateOperation, REPLACE);
}
throw new IllegalStateException(updateOperation + " not known.");
});
}

private Predicate<JsonObject> filterAncestorOperations(SirixDeweyID rootDeweyId, long maxDepth) {
return updateOperation -> {
if (updateOperation.has("insert")) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, "insert", maxDepth);
} else if (updateOperation.has("delete")) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, "delete", maxDepth);
} else if (updateOperation.has("update")) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, "update", maxDepth);
} else if (updateOperation.has("replace")) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, "replace", maxDepth);
if (updateOperation.has(INSERT)) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, INSERT, maxDepth);
} else if (updateOperation.has(DELETE)) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, DELETE, maxDepth);
} else if (updateOperation.has(UPDATE)) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, UPDATE, maxDepth);
} else if (updateOperation.has(REPLACE)) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, REPLACE, maxDepth);
} else {
throw new IllegalStateException(updateOperation + " not known.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,6 @@ private JsonNodeTrx insertSubtree(final JsonReader reader, final InsertPosition
commit();
}

// for (final long unused : new DescendantAxis(nodeReadOnlyTrx)) {
// System.out.println(nodeReadOnlyTrx.getDeweyID());
// }
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -553,9 +550,6 @@ private JsonNodeTrx insertSubtree(final Item item, final InsertPosition insertio
commit();
}

// for (final long unused : new DescendantAxis(nodeReadOnlyTrx)) {
// System.out.println(nodeReadOnlyTrx.getDeweyID());
// }
});
return this;
}
Expand Down

0 comments on commit f26cf96

Please sign in to comment.