Skip to content

Commit

Permalink
Use contains instead of indexOf to make intent of logic clearer.
Browse files Browse the repository at this point in the history
Correct a spelling error of local variable toke to token.
Patch by Graham Russell. Part of github pr apache#174.


git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1749194 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
FSchumacher committed Jun 19, 2016
1 parent aad0cde commit 3a31628
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 38 deletions.
13 changes: 6 additions & 7 deletions src/jorphan/org/apache/jorphan/reflect/ClassFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,21 @@ private static class ExtendsClassFilter implements ClassFilter {

@Override
public boolean accept(String className) {
if (contains!=null && className.indexOf(contains) == -1){

if (contains != null && !className.contains(contains)) {
return false; // It does not contain a required string
}
if (notContains!=null && className.indexOf(notContains) != -1){
if (notContains != null && className.contains(notContains)) {
return false; // It contains a banned string
}
if ((className.indexOf('$') == -1) || inner) { // $NON-NLS-1$
if (isChildOf(parents,className, contextClassLoader)) {
if (!className.contains("$") || inner) { // $NON-NLS-1$
if (isChildOf(parents, className, contextClassLoader)) {
return true;
}
}
return false;
}
}


private static class AnnoClassFilter implements ClassFilter {

Expand All @@ -113,7 +112,7 @@ private static class AnnoClassFilter implements ClassFilter {

@Override
public boolean accept(String className) {
if ((className.indexOf('$') == -1) || inner) { // $NON-NLS-1$
if (!className.contains("$") || inner) { // $NON-NLS-1$
if (hasAnnotationOnMethod(annotations,className, contextClassLoader)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public LogFilter() {
public void setReplaceExtension(String oldext, String newext) {
if (oldext != null && newext != null) {
this.CHANGEEXT = true;
if (oldext.indexOf('.') < 0 && newext.indexOf('.') < 0) {
if (!oldext.contains(".") && !newext.contains(".")) {
this.OLDEXT = "." + oldext;
this.NEWEXT = "." + newext;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,18 @@ private void createUrl(String line, TestElement el) {
*/
public String cleanURL(String entry) {
String url = entry;
// if the string contains atleast one double
// quote and checkMethod is true, go ahead
// and tokenize the string.
if (entry.indexOf('"') > -1 && checkMethod(entry)) {
StringTokenizer tokens = null;
if (entry.contains("\"") && checkMethod(entry)) {
// we tokenize using double quotes. this means
// for tomcat we should have 3 tokens if there
// isn't any additional information in the logs
tokens = this.tokenize(entry, "\"");
StringTokenizer tokens = this.tokenize(entry, "\"");
while (tokens.hasMoreTokens()) {
String toke = tokens.nextToken();
// if checkMethod on the token is true
// we tokenzie it using space and escape
// the while loop. Only the first matching
// token will be used
if (checkMethod(toke)) {
StringTokenizer token2 = this.tokenize(toke, " ");
String token = tokens.nextToken();
if (checkMethod(token)) {
// we tokenzie it using space and escape
// the while loop. Only the first matching
// token will be used
StringTokenizer token2 = this.tokenize(token, " ");
while (token2.hasMoreTokens()) {
String t = (String) token2.nextElement();
if (t.equalsIgnoreCase(GET)) {
Expand Down Expand Up @@ -432,7 +427,7 @@ public boolean checkMethod(String text) {
* @return String presenting the parameters, or <code>null</code> when none where found
*/
public String stripFile(String url, TestElement el) {
if (url.indexOf('?') > -1) {
if (url.contains("?")) {
StringTokenizer tokens = this.tokenize(url, "?");
this.URL_PATH = tokens.nextToken();
el.setProperty(HTTPSamplerBase.PATH, URL_PATH);
Expand All @@ -451,10 +446,7 @@ public String stripFile(String url, TestElement el) {
* <code>false</code> otherwise
*/
public boolean checkURL(String url) {
if (url.indexOf('?') > -1) {
return true;
}
return false;
return url.contains("?");
}

/**
Expand All @@ -466,10 +458,7 @@ public boolean checkURL(String url) {
* and <code>=</code>, <code>false</code> otherwise
*/
public boolean checkParamFormat(String text) {
if (text.indexOf('&') > -1 && text.indexOf('=') > -1) {
return true;
}
return false;
return text.contains("&") && text.contains("=");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ public void runFunction() throws Exception {
if (ct) {
funcTitles.put(title, Boolean.TRUE);// For detecting extra entries
}
if (// Is this a work in progress ?
title.indexOf("(ALPHA") == -1 && title.indexOf("(EXPERIMENTAL") == -1) {// No, not a
// work in progress
// ...
// Is this a work in progress ?
if (!title.contains("(ALPHA") && !title.contains("(EXPERIMENTAL")) {
// No, not a work in progress ...
String s = "function.xml needs '" + title + "' entry for " + funcItem.getClass().getName();
if (!ct) {
LOG.warn(s); // Record in log as well
Expand Down
6 changes: 3 additions & 3 deletions test/src/org/apache/jmeter/resources/PackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private int readRF(String res, List<String> l) throws Exception {
* JMeterUtils.getResString() converts space to _ and lowercases
* the key, so make sure all keys pass the test
*/
if ((key.indexOf(' ') >= 0) || !key.toLowerCase(java.util.Locale.ENGLISH).equals(key)) {
if (key.contains(" ") || !key.toLowerCase(java.util.Locale.ENGLISH).equals(key)) {
System.out.println("Invalid key for JMeterUtils " + key);
fails++;
}
Expand All @@ -136,9 +136,9 @@ private int readRF(String res, List<String> l) throws Exception {
* parameters and check if there is a { in the output. A bit
* crude, but should be enough for now.
*/
if (val.indexOf("{0}") > 0 && val.indexOf('\'') > 0) {
if (val.contains("{0}") && val.contains("'")) {
String m = java.text.MessageFormat.format(val, DUMMY_PARAMS);
if (m.indexOf('{') > 0) {
if (m.contains("{")) {
fails++;
System.out.println("Incorrect message format ? (input/output) for: "+key);
System.out.println(val);
Expand Down
2 changes: 1 addition & 1 deletion test/src/org/apache/jmeter/testbeans/gui/PackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void checkAllNecessaryKeysPresent() {
String dn = defaultBundle.getString("displayName").toUpperCase(Locale.ENGLISH);

// Skip the rest of this test for alpha/experimental beans:
if (dn.indexOf("(ALPHA") != -1 || dn.indexOf("(EXPERIMENTAL") != -1) {
if (dn.contains("(ALPHA") || dn.contains("(EXPERIMENTAL")) {
return;
}

Expand Down

0 comments on commit 3a31628

Please sign in to comment.