use indexOf(char) instead of indexOf(String) where possible; replace one more StringBuffer with StringBuilder - bug 63805

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1874262 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Axel Howind 2020-02-20 15:51:17 +00:00
parent 09d55c7832
commit 842e71a3d7
10 changed files with 10 additions and 10 deletions

View File

@ -346,7 +346,7 @@ public class ToCSV {
// Simply replace the .xls or .xlsx file extension with .csv // Simply replace the .xls or .xlsx file extension with .csv
destinationFilename = excelFile.getName(); destinationFilename = excelFile.getName();
destinationFilename = destinationFilename.substring( destinationFilename = destinationFilename.substring(
0, destinationFilename.lastIndexOf(".")) + 0, destinationFilename.lastIndexOf('.')) +
ToCSV.CSV_FILE_EXTENSION; ToCSV.CSV_FILE_EXTENSION;
// Save the CSV file away using the newly constricted file name // Save the CSV file away using the newly constricted file name

View File

@ -47,7 +47,7 @@ public class CellTextFormatter extends CellFormatter {
textPos = new int[numPlaces[0]]; textPos = new int[numPlaces[0]];
int pos = desc.length() - 1; int pos = desc.length() - 1;
for (int i = 0; i < textPos.length; i++) { for (int i = 0; i < textPos.length; i++) {
textPos[i] = desc.lastIndexOf("\u0000", pos); textPos[i] = desc.lastIndexOf('\u0000', pos);
pos = textPos[i] - 1; pos = textPos[i] - 1;
} }
} }

View File

@ -122,7 +122,7 @@ public class CellRangeAddress extends CellRangeAddressBase {
* column range (e.g. "C:F") * column range (e.g. "C:F")
*/ */
public static CellRangeAddress valueOf(String ref) { public static CellRangeAddress valueOf(String ref) {
int sep = ref.indexOf(":"); int sep = ref.indexOf(':');
CellReference a; CellReference a;
CellReference b; CellReference b;
if (sep == -1) { if (sep == -1) {

View File

@ -111,7 +111,7 @@ public final class ContentTypes {
public static final String EXTENSION_XML = "xml"; public static final String EXTENSION_XML = "xml";
public static String getContentTypeFromFileExtension(String filename) { public static String getContentTypeFromFileExtension(String filename) {
String extension = filename.substring(filename.lastIndexOf(".") + 1) String extension = filename.substring(filename.lastIndexOf('.') + 1)
.toLowerCase(Locale.ROOT); .toLowerCase(Locale.ROOT);
if (extension.equals(EXTENSION_JPG_1) if (extension.equals(EXTENSION_JPG_1)
|| extension.equals(EXTENSION_JPG_2)) || extension.equals(EXTENSION_JPG_2))

View File

@ -517,7 +517,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
+ filename); + filename);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
String partName = "/docProps/thumbnail" + String partName = "/docProps/thumbnail" +
filename.substring(filename.lastIndexOf(".") + 1); filename.substring(filename.lastIndexOf('.') + 1);
try { try {
thumbnailPartName = PackagingURIHelper.createPartName(partName); thumbnailPartName = PackagingURIHelper.createPartName(partName);
} catch (InvalidFormatException e2) { } catch (InvalidFormatException e2) {

View File

@ -422,7 +422,7 @@ public final class PackagePartName implements Comparable<PackagePartName> {
public String getExtension() { public String getExtension() {
String fragment = this.partNameURI.getPath(); String fragment = this.partNameURI.getPath();
if (fragment.length() > 0) { if (fragment.length() > 0) {
int i = fragment.lastIndexOf("."); int i = fragment.lastIndexOf('.');
if (i > -1) { if (i > -1) {
return fragment.substring(i + 1); return fragment.substring(i + 1);
} }

View File

@ -193,7 +193,7 @@ public final class PackagingURIHelper {
*/ */
public static String getFilenameWithoutExtension(URI uri) { public static String getFilenameWithoutExtension(URI uri) {
String filename = getFilename(uri); String filename = getFilename(uri);
int dotIndex = filename.lastIndexOf("."); int dotIndex = filename.lastIndexOf('.');
if (dotIndex == -1) if (dotIndex == -1)
return filename; return filename;
return filename.substring(0, dotIndex); return filename.substring(0, dotIndex);

View File

@ -22,7 +22,7 @@ public class Util {
public static int countLines(String str) { public static int countLines(String str) {
int lines = 1; int lines = 1;
int pos = 0; int pos = 0;
while ((pos = str.indexOf("\n", pos) + 1) != 0) { while ((pos = str.indexOf('\n', pos) + 1) != 0) {
lines++; lines++;
} }
return lines; return lines;

View File

@ -916,7 +916,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(text, cell.getStringCellValue()); assertEquals(text, cell.getStringCellValue());
// Now add a 2nd, and check again // Now add a 2nd, and check again
int fontAt = text.indexOf("\n", 6); int fontAt = text.indexOf('\n', 6);
cell.getRichStringCellValue().applyFont(10, fontAt + 1, font2); cell.getRichStringCellValue().applyFont(10, fontAt + 1, font2);
assertEquals(text, cell.getStringCellValue()); assertEquals(text, cell.getStringCellValue());

View File

@ -47,7 +47,7 @@ public final class TestBug46610 {
private static String runExtract(String sampleName) throws Exception { private static String runExtract(String sampleName) throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName); HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName);
StringBuffer out = new StringBuffer(); StringBuilder out = new StringBuilder();
Range globalRange = doc.getRange(); Range globalRange = doc.getRange();
for (int i = 0; i < globalRange.numParagraphs(); i++) { for (int i = 0; i < globalRange.numParagraphs(); i++) {