Skip to content

Commit fffc2fd

Browse files
author
Gintas Grigelionis
committed
Redundant string length computations
1 parent df76732 commit fffc2fd

8 files changed

Lines changed: 28 additions & 41 deletions

File tree

src/main/org/apache/tools/ant/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ private int handleArgDefine(final String[] args, int argPos) {
549549
* to help or not, so we simply look for the equals sign.
550550
*/
551551
final String arg = args[argPos];
552-
String name = arg.substring(2, arg.length());
552+
String name = arg.substring(2);
553553
String value;
554554
final int posEq = name.indexOf('=');
555555
if (posEq > 0) {

src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private void processComment(final String line) {
171171
private void processFile(final String line) {
172172
if (!remote && line.startsWith("Working file:")) {
173173
// CheckStyle:MagicNumber OFF
174-
file = line.substring(14, line.length());
174+
file = line.substring(14);
175175
// CheckStyle:MagicNumber ON
176176
status = GET_REVISION;
177177
} else if (remote && line.startsWith("RCS file:")) {

src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,17 @@ public void setJava2iiopParams(String params) {
202202
* @return the descriptor.
203203
*/
204204
protected DescriptorHandler getBorlandDescriptorHandler(final File srcDir) {
205-
DescriptorHandler handler =
206-
new DescriptorHandler(getTask(), srcDir) {
207-
@Override
208-
protected void processElement() {
209-
if ("type-storage".equals(currentElement)) {
210-
// Get the filename of vendor specific descriptor
211-
String fileNameWithMETA = currentText;
212-
//trim the META_INF\ off of the file name
213-
String fileName
214-
= fileNameWithMETA.substring(META_DIR.length(),
215-
fileNameWithMETA.length());
216-
File descriptorFile = new File(srcDir, fileName);
217-
218-
ejbFiles.put(fileNameWithMETA, descriptorFile);
219-
}
220-
}
221-
};
205+
DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir) {
206+
@Override
207+
protected void processElement() {
208+
if ("type-storage".equals(currentElement)) {
209+
// Get the filename of vendor specific descriptor
210+
// trim the META_INF\ off of the file name
211+
ejbFiles.put(currentText, new File(srcDir,
212+
currentText.substring(META_DIR.length())));
213+
}
214+
}
215+
};
222216
handler.registerDTD(PUBLICID_BORLAND_EJB,
223217
borlandDTD == null ? DEFAULT_BAS_DTD_LOCATION : borlandDTD);
224218

src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,23 +401,17 @@ protected void registerKnownDTDs(DescriptorHandler handler) {
401401
* @return the descriptor.
402402
*/
403403
protected DescriptorHandler getWeblogicDescriptorHandler(final File srcDir) {
404-
DescriptorHandler handler =
405-
new DescriptorHandler(getTask(), srcDir) {
406-
@Override
407-
protected void processElement() {
408-
if ("type-storage".equals(currentElement)) {
409-
// Get the filename of vendor specific descriptor
410-
String fileNameWithMETA = currentText;
411-
//trim the META_INF\ off of the file name
412-
String fileName
413-
= fileNameWithMETA.substring(META_DIR.length(),
414-
fileNameWithMETA.length());
415-
File descriptorFile = new File(srcDir, fileName);
416-
417-
ejbFiles.put(fileNameWithMETA, descriptorFile);
418-
}
404+
DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir) {
405+
@Override
406+
protected void processElement() {
407+
if ("type-storage".equals(currentElement)) {
408+
// Get the filename of vendor specific descriptor
409+
// trim the META_INF\ off of the file name
410+
ejbFiles.put(currentText, new File(srcDir,
411+
currentText.substring(META_DIR.length())));
419412
}
420-
};
413+
}
414+
};
421415

422416
handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, DEFAULT_WL51_DTD_LOCATION);
423417
handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, DEFAULT_WL60_51_DTD_LOCATION);

src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected InputStream openInputStream(ClassLoader cl) throws IOException {
4747
throw new IOException("No class name in " + constant);
4848
}
4949
String classname = constant.substring(0, index);
50-
String fieldname = constant.substring(index + 1, constant.length());
50+
String fieldname = constant.substring(index + 1);
5151
try {
5252
Class<?> clazz =
5353
cl != null

src/main/org/apache/tools/ant/util/FileUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ public String toVMSPath(File f) {
858858
if (isDirectory) {
859859
directory = new StringBuilder(path.substring(index).replace(File.separatorChar, '.'));
860860
} else {
861-
int dirEnd = path.lastIndexOf(File.separatorChar, path.length());
861+
int dirEnd = path.lastIndexOf(File.separatorChar);
862862
if (dirEnd == -1 || dirEnd < index) {
863863
file = path.substring(index);
864864
} else {

src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ private void parsePair(final String text) {
724724
setValue(null);
725725
} else {
726726
name = text.substring(0, pos);
727-
setValue(text.substring(pos + 1, text.length()));
727+
setValue(text.substring(pos + 1));
728728
}
729729
// trim leading whitespace only
730730
name = stripStart(name, " \t\f");

src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private static void ensureProperties(String msg, File inputFile,
229229
assertNotEquals(assertMsg + " Object ID does not exist.", null, obj);
230230

231231
// What is the property supposed to be?
232-
propertyValue = propertyValue.substring(3, propertyValue.length());
232+
propertyValue = propertyValue.substring(3);
233233
if (propertyValue.equals("path")) {
234234
assertThat(assertMsg + " Path ID is a " + obj.getClass().getName(),
235235
obj, instanceOf(Path.class));
@@ -243,8 +243,7 @@ private static void ensureProperties(String msg, File inputFile,
243243
// The property is the name of a file. We are testing
244244
// a location attribute, so we need to resolve the given
245245
// file name in the provided folder.
246-
String fileName =
247-
propertyValue.substring(5, propertyValue.length());
246+
String fileName = propertyValue.substring(5);
248247
File f = new File(workingDir, fileName);
249248
propertyValue = f.getAbsolutePath();
250249
}

0 commit comments

Comments
 (0)