Browse Source

replace "String.indexOf(String) >= 1" with "String.contains(String)"

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1795296 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_17_BETA1
Javen O'Neal 7 years ago
parent
commit
9b4e4769dd

+ 10
- 21
src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java View File

@@ -18,6 +18,9 @@

package org.apache.poi.ss.excelant;

import static org.apache.poi.POITestCase.assertContains;
import static org.apache.poi.POITestCase.assertNotContained;

import java.io.File;
import java.io.PrintStream;
import java.net.URL;
@@ -119,20 +122,14 @@ public abstract class BuildFileTest extends TestCase {
* Assert that the given substring is in the log messages.
*/
public void assertLogContaining(String substring) {
String realLog = getLog();
assertTrue("expecting log to contain \"" + substring + "\" log was \""
+ realLog + "\"",
realLog.indexOf(substring) >= 0);
assertContains(getLog(), substring);
}

/**
* Assert that the given substring is not in the log messages.
*/
public void assertLogNotContaining(String substring) {
String realLog = getLog();
assertFalse("didn't expect log to contain \"" + substring + "\" log was \""
+ realLog + "\"",
realLog.indexOf(substring) >= 0);
assertNotContained(getLog(), substring);
}

/**
@@ -152,11 +149,7 @@ public abstract class BuildFileTest extends TestCase {
* @since Ant1.7
*/
public void assertOutputContaining(String message, String substring) {
String realOutput = getOutput();
String realMessage = (message != null)
? message
: "expecting output to contain \"" + substring + "\" output was \"" + realOutput + "\"";
assertTrue(realMessage, realOutput.indexOf(substring) >= 0);
assertContains("output: " + message, getOutput(), substring);
}

/**
@@ -167,11 +160,7 @@ public abstract class BuildFileTest extends TestCase {
* @since Ant1.7
*/
public void assertOutputNotContaining(String message, String substring) {
String realOutput = getOutput();
String realMessage = (message != null)
? message
: "expecting output to not contain \"" + substring + "\" output was \"" + realOutput + "\"";
assertFalse(realMessage, realOutput.indexOf(substring) >= 0);
assertNotContained(getOutput(), substring);
}

/**
@@ -218,10 +207,10 @@ public abstract class BuildFileTest extends TestCase {
*/
public void assertDebuglogContaining(String substring) {
String realLog = getFullLog();
assertTrue("expecting debug log to contain \"" + substring
assertContains("expecting debug log to contain \"" + substring
+ "\" log was \""
+ realLog + "\"",
realLog.indexOf(substring) >= 0);
realLog, substring);
}

/**
@@ -397,7 +386,7 @@ public abstract class BuildFileTest extends TestCase {
executeTarget(target);
} catch (org.apache.tools.ant.BuildException ex) {
buildException = ex;
if ((null != contains) && (ex.getMessage().indexOf(contains) == -1)) {
if ((null != contains) && (!ex.getMessage().contains(contains))) {
fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)");
}
return;

+ 8
- 7
src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java View File

@@ -40,6 +40,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header
String _center = "";
String _right = "";

// FIXME: replace outer goto. just eww.
outer:
while (text.length() > 1) {
if (text.charAt(0) != '&') {
@@ -50,30 +51,30 @@ outer:
int pos = text.length();
switch (text.charAt(1)) {
case 'L':
if (text.indexOf("&C") >= 0) {
if (text.contains("&C")) {
pos = Math.min(pos, text.indexOf("&C"));
}
if (text.indexOf("&R") >= 0) {
if (text.contains("&R")) {
pos = Math.min(pos, text.indexOf("&R"));
}
_left = text.substring(2, pos);
text = text.substring(pos);
break;
case 'C':
if (text.indexOf("&L") >= 0) {
if (text.contains("&L")) {
pos = Math.min(pos, text.indexOf("&L"));
}
if (text.indexOf("&R") >= 0) {
if (text.contains("&R")) {
pos = Math.min(pos, text.indexOf("&R"));
}
_center = text.substring(2, pos);
text = text.substring(pos);
break;
case 'R':
if (text.indexOf("&C") >= 0) {
if (text.contains("&C")) {
pos = Math.min(pos, text.indexOf("&C"));
}
if (text.indexOf("&L") >= 0) {
if (text.contains("&L")) {
pos = Math.min(pos, text.indexOf("&L"));
}
_right = text.substring(2, pos);
@@ -288,7 +289,7 @@ outer:
// Firstly, do the easy ones which are static
for (MarkupTag mt : MarkupTag.values()) {
String seq = mt.getRepresentation();
while ((pos = text.indexOf(seq)) > -1) {
while ((pos = text.indexOf(seq)) >= 0) {
text = text.substring(0, pos) + text.substring(pos + seq.length());
}
}

+ 3
- 5
src/java/org/apache/poi/ss/util/AreaReference.java View File

@@ -176,10 +176,7 @@ public class AreaReference {
}

// Check for the , as a sign of non-coniguous
if(reference.indexOf(',') == -1) {
return true;
}
return false;
return !reference.contains(",");
}

public static AreaReference getWholeRow(SpreadsheetVersion version, String start, String end) {
@@ -387,7 +384,8 @@ public class AreaReference {

String partA = reference.substring(0, delimiterPos);
String partB = reference.substring(delimiterPos+1);
if(partB.indexOf(SHEET_NAME_DELIMITER) >=0) {
if(partB.indexOf(SHEET_NAME_DELIMITER) >= 0) {
// partB contains SHEET_NAME_DELIMITER
// TODO - are references like "Sheet1!A1:Sheet1:B2" ever valid?
// FormulaParser has code to handle that.

+ 1
- 1
src/java/org/apache/poi/ss/util/CellReference.java View File

@@ -408,7 +408,7 @@ public class CellReference {
boolean isQuoted = reference.charAt(0) == SPECIAL_NAME_DELIMITER;
if(!isQuoted) {
// sheet names with spaces must be quoted
if (reference.indexOf(' ') == -1) {
if (! reference.contains(" ")) {
return reference.substring(0, indexOfSheetNameDelimiter);
} else {
throw new IllegalArgumentException("Sheet names containing spaces must be quoted: (" + reference + ")");

+ 1
- 1
src/ooxml/java/org/apache/poi/POIXMLRelation.java View File

@@ -119,7 +119,7 @@ public abstract class POIXMLRelation {
* @return the filename including the suffix
*/
public String getFileName(int index) {
if(_defaultName.indexOf("#") == -1) {
if(! _defaultName.contains("#")) {
// Generic filename in all cases
return getDefaultFileName();
}

+ 4
- 2
src/ooxml/java/org/apache/poi/util/OOXMLLite.java View File

@@ -278,7 +278,9 @@ public final class OOXMLLite {
if (loc == null) continue;
String jar = loc.toString();
if(jar.indexOf(ptrn) != -1) map.put(cls.getName(), cls);
if (jar.contains(ptrn)) {
map.put(cls.getName(), cls);
}
}
return map;
} catch (IllegalAccessException e) {
@@ -299,4 +301,4 @@ public final class OOXMLLite {
}
}

}
}

+ 1
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java View File

@@ -111,7 +111,7 @@ public class XSSFComment implements Comment {
boolean visible = false;
if(_vmlShape != null){
String style = _vmlShape.getStyle();
visible = style != null && style.indexOf("visibility:visible") != -1;
visible = style != null && style.contains("visibility:visible");
}
return visible;
}

+ 5
- 4
src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java View File

@@ -124,7 +124,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
if (recipientEmailChunk != null) {
String email = recipientEmailChunk.getValue();
int cne = email.indexOf("/CN=");
if (cne == -1) {
if (cne < 0) {
// Normal smtp address
return email;
} else {
@@ -136,7 +136,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
// Might be in the name field, check there
if (recipientNameChunk != null) {
String name = recipientNameChunk.getValue();
if (name.indexOf('@') > -1) {
if (name.contains("@")) {
// Strip leading and trailing quotes if needed
if (name.startsWith("'") && name.endsWith("'")) {
return name.substring(1, name.length() - 1);
@@ -149,8 +149,9 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
// encoded as a SMTP destination in there.
if (recipientSearchChunk != null) {
String search = recipientSearchChunk.getAs7bitString();
if (search.indexOf("SMTP:") != -1) {
return search.substring(search.indexOf("SMTP:") + 5);
int idx = search.indexOf("SMTP:");
if (idx >= 0) {
return search.substring(idx + 5);
}
}


+ 1
- 1
src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java View File

@@ -140,7 +140,7 @@ public final class POIFSChunkParser {
// Name in the wrong format
return;
}
if(entryName.indexOf('_') == -1) {
if(! entryName.contains("_")) {
// Name in the wrong format
return;
}

+ 8
- 8
src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java View File

@@ -64,9 +64,9 @@ public final class TestOutlookTextExtractor {
assertContains(text, "From: Kevin Roast\n");
assertContains(text, "To: Kevin Roast <kevin.roast@alfresco.org>\n");
assertEquals(-1, text.indexOf("CC:"));
assertEquals(-1, text.indexOf("BCC:"));
assertEquals(-1, text.indexOf("Attachment:"));
assertNotContained(text, "CC:");
assertNotContained(text, "BCC:");
assertNotContained(text, "Attachment:");
assertContains(text, "Subject: Test the content transformer\n");
Calendar cal = LocaleUtil.getLocaleCalendar(2007, 5, 14, 9, 42, 55);
SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ROOT);
@@ -89,8 +89,8 @@ public final class TestOutlookTextExtractor {
assertContains(text, "From: Travis Ferguson\n");
assertContains(text, "To: travis@overwrittenstack.com\n");
assertEquals(-1, text.indexOf("CC:"));
assertEquals(-1, text.indexOf("BCC:"));
assertNotContained(text, "CC:");
assertNotContained(text, "BCC:");
assertContains(text, "Subject: test message\n");
assertContains(text, "Date: Fri, 6 Jul 2007 05:27:17 +0000\n");
assertContains(text, "This is a test message.");
@@ -193,7 +193,7 @@ public final class TestOutlookTextExtractor {
"'Paul Holmes-Higgin' <paul.hh@alfresco.com>; 'Mike Farman' <mikef@alfresco.com>\n");
assertContains(text, "CC: nickb@alfresco.com; " +
"nick.burch@alfresco.com; 'Roy Wetherall' <roy.wetherall@alfresco.com>\n");
assertEquals(-1, text.indexOf("BCC:"));
assertNotContained(text, "BCC:");
assertContains(text, "Subject: This is a test message please ignore\n");
assertContains(text, "Date: Mon, 11 Jan 2010 16:2"); // Exact times differ slightly
assertContains(text, "The quick brown fox jumps over the lazy dog");
@@ -216,8 +216,8 @@ public final class TestOutlookTextExtractor {
assertContains(text, "From: Nicolas1");
assertContains(text, "To: 'nicolas1.23456@free.fr'");
assertEquals(-1, text.indexOf("CC:"));
assertEquals(-1, text.indexOf("BCC:"));
assertNotContained(text, "CC:");
assertNotContained(text, "BCC:");
assertContains(text, "Subject: test");
assertContains(text, "Date: Wed, 22 Apr");
assertContains(text, "Attachment: test-unicode.doc\n");

+ 1
- 1
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java View File

@@ -162,7 +162,7 @@ public final class TestProblems extends HWPFTestCase {
String text = para.text();

totalLength += text.length();
if (text.indexOf("{delete me}") > -1) {
if (text.contains("{delete me}")) {
para.delete();
deletedLength = text.length();
}

+ 2
- 2
src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java View File

@@ -64,7 +64,7 @@ public final class TestEscherGraphics {
@Test
public void testGetFont() {
Font f = graphics.getFont();
if (f.toString().indexOf("dialog") == -1 && f.toString().indexOf("Dialog") == -1) {
if (! f.toString().contains("dialog") && ! f.toString().contains("Dialog")) {
assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString());
}
}
@@ -72,7 +72,7 @@ public final class TestEscherGraphics {
@Test
public void testGetFontMetrics() {
Font f = graphics.getFont();
if (f.toString().indexOf("dialog") != -1 || f.toString().indexOf("Dialog") != -1) {
if (f.toString().contains("dialog") || f.toString().contains("Dialog")) {
return;
}
FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont());

+ 6
- 4
src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java View File

@@ -17,6 +17,8 @@

package org.apache.poi.poifs.filesystem;

import static org.apache.poi.POITestCase.assertContains;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -45,8 +47,8 @@ public class TestOfficeXMLException extends TestCase {
fail("expected exception was not thrown");
} catch(OfficeXmlFileException e) {
// expected during successful test
assertTrue(e.getMessage().indexOf("The supplied data appears to be in the Office 2007+ XML") > -1);
assertTrue(e.getMessage().indexOf("You are calling the part of POI that deals with OLE2 Office Documents") > -1);
assertContains(e.getMessage(), "The supplied data appears to be in the Office 2007+ XML");
assertContains(e.getMessage(), "You are calling the part of POI that deals with OLE2 Office Documents");
}
}
public void test2003XMLException() throws IOException
@@ -58,8 +60,8 @@ public class TestOfficeXMLException extends TestCase {
fail("expected exception was not thrown");
} catch(NotOLE2FileException e) {
// expected during successful test
assertTrue(e.getMessage().indexOf("The supplied data appears to be a raw XML file") > -1);
assertTrue(e.getMessage().indexOf("Formats such as Office 2003 XML") > -1);
assertContains(e.getMessage(), "The supplied data appears to be a raw XML file");
assertContains(e.getMessage(), "Formats such as Office 2003 XML");
}
}

+ 2
- 1
src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java View File

@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.apache.poi.POITestCase.assertContains;

import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -118,7 +119,7 @@ public class TestOle10Native {
Ole10Native.createFromEmbeddedOleObject(fs);
fail("Should have thrown exception because OLENative lacks a length parameter");
} catch (Ole10NativeException e) {
assertTrue(e.getMessage().indexOf("declared data length") > -1);
assertContains(e.getMessage(), "declared data length");
}
}


Loading…
Cancel
Save