Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pmd :: CollapsibleIfStatement #1061

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/main/java/emissary/core/MobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,8 @@ protected DirectoryEntry getNextKey(@Nullable final IServiceProviderPlace place,
int startType = typeLookup(lastServiceType);

// If we came from transform we can start at the beginning again
if (lastEntry != null && startType != 0) {
if ("TRANSFORM".equals(lastEntry.getServiceType())) {
startType = 0;
}
if (lastEntry != null && startType != 0 && "TRANSFORM".equals(lastEntry.getServiceType())) {
startType = 0;
}

DirectoryEntry curEntry = null;
Expand All @@ -528,12 +526,10 @@ protected DirectoryEntry getNextKey(@Nullable final IServiceProviderPlace place,
for (String form : dataForms) {

// Test a full key form to see if it is the correct stage to be chosen
if (KeyManipulator.isKeyComplete(form)) {
if (KeyManipulator.getServiceType(form).equals(stageName)) {
logger.debug("Choosing cur form {} in stage {}", form, stageName);
payloadArg.pullFormToTop(form);
return new DirectoryEntry(form);
}
if (KeyManipulator.isKeyComplete(form) && KeyManipulator.getServiceType(form).equals(stageName)) {
logger.debug("Choosing cur form {} in stage {}", form, stageName);
payloadArg.pullFormToTop(form);
return new DirectoryEntry(form);
}

String formId = form + KeyManipulator.DATAIDSEPARATOR + stageName;
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/emissary/directory/DirectoryEntryList.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,10 @@ private boolean insert(final DirectoryEntry newEntry) {
if (newEntry.isBetterThan(currEntry)) {
super.add(i, newEntry);
return true;
} else if (newEntry.getExpense() == currEntry.getExpense()) {
} else if (newEntry.getExpense() == currEntry.getExpense() && newEntry.getServiceName().compareTo(currEntry.getServiceName()) < 0) {
// we could have an equal expense and if so, add lexicographically based on service name
if (newEntry.getServiceName().compareTo(currEntry.getServiceName()) < 0) {
super.add(i, newEntry);
return true;
}
super.add(i, newEntry);
return true;
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/emissary/directory/KeyManipulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ private static boolean gmatch2(final char[] s, final char[] p, final int spos, f
}
int spos2 = spos;
while (s.length > ++spos2) {
if (p[ppos2] == s[spos2]) {
if (gmatch2(s, p, spos2, ppos2)) {
return true;
}
if (p[ppos2] == s[spos2] && gmatch2(s, p, spos2, ppos2)) {
return true;
}
}
return false;
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/emissary/kff/KffMemcached.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,11 @@ public boolean check(String id, ChecksumResults sums) throws Exception {
Object result = future.get(opTimeoutMillis, TimeUnit.MILLISECONDS);

if (result != null) {
if (storeIdDupe) {
if (!((String) result).equals(id)) {
// As long as the id is not the same as what was already stored, then
// store it on its own
var unused = client.set(id, ageoff, key);
// logger.debug("Storing duplicate Id: {} with value (hash) {}", id, key);
}
if (storeIdDupe && !result.equals(id)) {
// As long as the id is not the same as what was already stored, then
// store it on its own
var unused = client.set(id, ageoff, key);
// logger.debug("Storing duplicate Id: {} with value (hash) {}", id, key);
}
// logger.debug("Found key: {} with value {}", key, (String) result);
// Found the key
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/emissary/kff/Ssdeep.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ private void applyBytes(final RollingState rollState, final byte[] buffer, final
// Therefore this secondary signature condition can
// only potentially be true if the main signature
// condition (which we've already checked) is true.
if ((rollingHash % (this.blockSize * 2)) == ((this.blockSize * 2) - 1)) {
if (this.fuzzLen2 < (SPAMSUM_LENGTH / 2 - 1)) {
this.fuzzHash2[this.fuzzLen2++] = b64EncodeLowBits(this.sumHash2);
this.sumHash2 = HASH_INIT;
}
if ((rollingHash % (this.blockSize * 2)) == ((this.blockSize * 2) - 1) && this.fuzzLen2 < (SPAMSUM_LENGTH / 2 - 1)) {
this.fuzzHash2[this.fuzzLen2++] = b64EncodeLowBits(this.sumHash2);
this.sumHash2 = HASH_INIT;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these I wonder if there is benefit to making them a method rather than jamming them in the above line. Here we have code that looks very similar to the above (line 185) where perhaps refactoring this would benefit more than just this line/warning.

}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/emissary/roll/Roller.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ private long getIntervalInMillis() {
private boolean shouldRoll(long start) {
// verify both time and progress are set
// if we're below max we'll check the interval
if (period > 0 && max > 0 && progress.get() < max) {
if (period > 0 && max > 0 && progress.get() < max && ((start - lastRun + 100) < getIntervalInMillis())) {
// we fired a progress run or delayed start due to starvation. add 100 for clock skew
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this read correctly with the comments, perhaps a method for the second if statement would be nicer?

if ((start - lastRun + 100) < getIntervalInMillis()) {
return false;
}
return false;
}
return true;
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/emissary/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public static String escapeInvalidXml(String in) {
// this is stolen from the implementation of Verifier.checkCharacterData(in);
for (int i = 0, len = in.length(); i < len; i++) {
char c = in.charAt(i);
if (!(c > 0x1F && c < 0xD800)) { // for performance
if (!Verifier.isXMLCharacter(c)) {
return in.substring(0, i) + "/0x" + Integer.toHexString(c) + escapeInvalidXml(in.substring(i + 1));
}
if (!(c > 0x1F && c < 0xD800) && !Verifier.isXMLCharacter(c)) {
return in.substring(0, i) + "/0x" + Integer.toHexString(c) + escapeInvalidXml(in.substring(i + 1));
}
}
return in;
Expand Down