Prefer checking isEmpty over size() > 0. Plus fix some typos

Former-commit-id: 754f300c0b120c0c9098c17c19dbd11aa7a39844
This commit is contained in:
Hans Joachim Desserud
2015-02-22 11:42:14 +01:00
parent 42939e4922
commit cf677bd70e
7 changed files with 18 additions and 18 deletions

View File

@@ -116,7 +116,7 @@ public class Engine {
* Loads the analyzers specified in the configuration file (or system properties). * Loads the analyzers specified in the configuration file (or system properties).
*/ */
private void loadAnalyzers() { private void loadAnalyzers() {
if (analyzers.size() > 0) { if (!analyzers.isEmpty()) {
return; return;
} }
for (AnalysisPhase phase : AnalysisPhase.values()) { for (AnalysisPhase phase : AnalysisPhase.values()) {

View File

@@ -72,7 +72,7 @@ public abstract class AbstractTokenizingFilter extends TokenFilter {
* @return whether or not a new term was added * @return whether or not a new term was added
*/ */
protected boolean addTerm() { protected boolean addTerm() {
final boolean termAdded = tokens.size() > 0; final boolean termAdded = !tokens.isEmpty();
if (termAdded) { if (termAdded) {
final String term = tokens.pop(); final String term = tokens.pop();
clearAttributes(); clearAttributes();

View File

@@ -92,7 +92,7 @@ public final class TokenPairConcatenatingFilter extends TokenFilter {
//if we have a previousTerm - write it out as its own token concatenated //if we have a previousTerm - write it out as its own token concatenated
// with the current word (if one is available). // with the current word (if one is available).
if (previousWord != null && words.size() > 0) { if (previousWord != null && !words.isEmpty()) {
final String word = words.getFirst(); final String word = words.getFirst();
clearAttributes(); clearAttributes();
termAtt.append(previousWord).append(word); termAtt.append(previousWord).append(word);
@@ -100,7 +100,7 @@ public final class TokenPairConcatenatingFilter extends TokenFilter {
return true; return true;
} }
//if we have words, write it out as a single token //if we have words, write it out as a single token
if (words.size() > 0) { if (!words.isEmpty()) {
final String word = words.removeFirst(); final String word = words.removeFirst();
clearAttributes(); clearAttributes();
termAtt.append(word); termAtt.append(word);

View File

@@ -60,7 +60,7 @@ public final class UrlTokenizingFilter extends AbstractTokenizingFilter {
public boolean incrementToken() throws IOException { public boolean incrementToken() throws IOException {
final LinkedList<String> tokens = getTokens(); final LinkedList<String> tokens = getTokens();
final CharTermAttribute termAtt = getTermAtt(); final CharTermAttribute termAtt = getTermAtt();
if (tokens.size() == 0 && input.incrementToken()) { if (tokens.isEmpty() && input.incrementToken()) {
final String text = new String(termAtt.buffer(), 0, termAtt.length()); final String text = new String(termAtt.buffer(), 0, termAtt.length());
if (UrlStringUtils.containsUrl(text)) { if (UrlStringUtils.containsUrl(text)) {
final String[] parts = text.split("\\s"); final String[] parts = text.split("\\s");

View File

@@ -875,9 +875,9 @@ public class CveDB {
*/ */
private DependencyVersion parseDependencyVersion(VulnerableSoftware cpe) { private DependencyVersion parseDependencyVersion(VulnerableSoftware cpe) {
DependencyVersion cpeVersion; DependencyVersion cpeVersion;
if (cpe.getVersion() != null && cpe.getVersion().length() > 0) { if (cpe.getVersion() != null && !cpe.getVersion().isEmpty()) {
String versionText; String versionText;
if (cpe.getRevision() != null && cpe.getRevision().length() > 0) { if (cpe.getRevision() != null && !cpe.getRevision().isEmpty()) {
versionText = String.format("%s.%s", cpe.getVersion(), cpe.getRevision()); versionText = String.format("%s.%s", cpe.getVersion(), cpe.getRevision());
} else { } else {
versionText = cpe.getVersion(); versionText = cpe.getVersion();

View File

@@ -112,7 +112,7 @@ public class SuppressionRule {
* @return whether or not this suppression rule as CPE entries * @return whether or not this suppression rule as CPE entries
*/ */
public boolean hasCpe() { public boolean hasCpe() {
return cpe.size() > 0; return !cpe.isEmpty();
} }
/** /**
* The list of cvssBelow scores. * The list of cvssBelow scores.
@@ -152,7 +152,7 @@ public class SuppressionRule {
* @return whether or not this suppression rule has cvss suppressions * @return whether or not this suppression rule has cvss suppressions
*/ */
public boolean hasCvssBelow() { public boolean hasCvssBelow() {
return cvssBelow.size() > 0; return !cvssBelow.isEmpty();
} }
/** /**
* The list of cwe entries to suppress. * The list of cwe entries to suppress.
@@ -192,7 +192,7 @@ public class SuppressionRule {
* @return whether this suppression rule has CWE entries * @return whether this suppression rule has CWE entries
*/ */
public boolean hasCwe() { public boolean hasCwe() {
return cwe.size() > 0; return !cwe.isEmpty();
} }
/** /**
* The list of cve entries to suppress. * The list of cve entries to suppress.
@@ -232,7 +232,7 @@ public class SuppressionRule {
* @return whether this suppression rule has CVE entries * @return whether this suppression rule has CVE entries
*/ */
public boolean hasCve() { public boolean hasCve() {
return cve.size() > 0; return !cve.isEmpty();
} }
/** /**
* A Maven GAV to suppression. * A Maven GAV to suppression.
@@ -450,28 +450,28 @@ public class SuppressionRule {
if (gav != null) { if (gav != null) {
sb.append("gav=").append(gav).append(","); sb.append("gav=").append(gav).append(",");
} }
if (cpe != null && cpe.size() > 0) { if (cpe != null && !cpe.isEmpty()) {
sb.append("cpe={"); sb.append("cpe={");
for (PropertyType pt : cpe) { for (PropertyType pt : cpe) {
sb.append(pt).append(","); sb.append(pt).append(",");
} }
sb.append("}"); sb.append("}");
} }
if (cwe != null && cwe.size() > 0) { if (cwe != null && !cwe.isEmpty()) {
sb.append("cwe={"); sb.append("cwe={");
for (String s : cwe) { for (String s : cwe) {
sb.append(s).append(","); sb.append(s).append(",");
} }
sb.append("}"); sb.append("}");
} }
if (cve != null && cve.size() > 0) { if (cve != null && !cve.isEmpty()) {
sb.append("cve={"); sb.append("cve={");
for (String s : cve) { for (String s : cve) {
sb.append(s).append(","); sb.append(s).append(",");
} }
sb.append("}"); sb.append("}");
} }
if (cvssBelow != null && cvssBelow.size() > 0) { if (cvssBelow != null && !cvssBelow.isEmpty()) {
sb.append("cvssBelow={"); sb.append("cvssBelow={");
for (Float s : cvssBelow) { for (Float s : cvssBelow) {
sb.append(s).append(","); sb.append(s).append(",");

View File

@@ -701,7 +701,7 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
private Proxy getMavenProxy() { private Proxy getMavenProxy() {
if (mavenSettings != null) { if (mavenSettings != null) {
final List<Proxy> proxies = mavenSettings.getProxies(); final List<Proxy> proxies = mavenSettings.getProxies();
if (proxies != null && proxies.size() > 0) { if (proxies != null && !proxies.isEmpty()) {
if (mavenSettingsProxyId != null) { if (mavenSettingsProxyId != null) {
for (Proxy proxy : proxies) { for (Proxy proxy : proxies) {
if (mavenSettingsProxyId.equalsIgnoreCase(proxy.getId())) { if (mavenSettingsProxyId.equalsIgnoreCase(proxy.getId())) {
@@ -711,8 +711,8 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
} else if (proxies.size() == 1) { } else if (proxies.size() == 1) {
return proxies.get(0); return proxies.get(0);
} else { } else {
LOGGER.warning("Multiple proxy defentiions exist in the Maven settings. In the dependency-check " LOGGER.warning("Multiple proxy definitions exist in the Maven settings. In the dependency-check "
+ "configuration set the maveSettingsProxyId so that the correct proxy will be used."); + "configuration set the mavenSettingsProxyId so that the correct proxy will be used.");
throw new IllegalStateException("Ambiguous proxy definition"); throw new IllegalStateException("Ambiguous proxy definition");
} }
} }