Skip to content

Commit c0a730a

Browse files
ochejapivovarit
authored andcommitted
Replace string concatenations with String.format (eugenp#3201)
* Define beans for handling different message types in a lean chat app * Add class based spring beans configuration * Define spring configuration in XML for constructor based bean injection * Refactor package structure to separate constructor based bean injection code set from setter based bean injection code set * Define configuration and classes specific to setter-based bean injection. * Implement tests for constructor-based and setter-based bean injections * develop codes for explaining type erasure * Write unit tests for type erasure examples * Remove evaluation article code * Modify type erasure examples and unit tests * Modify type erasure examples and unit tests * Add expected exception in TypeErasureUnitTest * Correct grammar in class name * Implement File Manager app to demonstrate Polymorphism. Develop unit tests for Polymorphism article code * Add examples for static polymorphism * Change sysout statments to slf4j log info statements * Add assertions and expected errors check on Test * Add assertions and expected errors check on Test * Correct compile time error of symbol not found * Removed commented out non-compiling test. * Replace string concatenations with String.format * Replace string concatenations with String.format
1 parent 909109e commit c0a730a

4 files changed

Lines changed: 3 additions & 5 deletions

File tree

core-java/src/main/java/com/baeldung/polymorphism/GenericFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void setContent(byte[] content) {
5454
}
5555

5656
public String getFileInfo() {
57-
return "File Name: " + this.getName() + "\n" + "Extension: " + this.getExtension() + "\n" + "Date Created: " + this.getDateCreated() + "\n" + "Version: " + this.getVersion() + "\n";
57+
return String.format("File Name: %s\n" + " Extension: %s\n" + " Date Created: %s\n" + " Version: %s\n", this.getName(), this.getExtension(), this.getDateCreated(), this.getVersion());
5858
}
5959

6060
public Object read() {

core-java/src/main/java/com/baeldung/polymorphism/ImageFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void setWidth(int width) {
3030
}
3131

3232
public String getFileInfo() {
33-
return super.getFileInfo() + "Height: " + this.getHeight() + "\n" + "Width: " + this.getWidth();
33+
return String.format(" %s Height: %d\n Width: %d", super.getFileInfo(), this.getHeight(), this.getWidth());
3434
}
3535

3636
public String read() {

core-java/src/main/java/com/baeldung/polymorphism/TextFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void setWordCount(int wordCount) {
2121
}
2222

2323
public String getFileInfo() {
24-
return super.getFileInfo() + "Word Count: " + wordCount;
24+
return String.format(" %s Word Count: %d", super.getFileInfo(), wordCount);
2525
}
2626

2727
public String read() {

core-java/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import static org.junit.Assert.*;
44

55
import java.awt.image.BufferedImage;
6-
7-
import org.junit.Ignore;
86
import org.junit.Test;
97

108
public class PolymorphismUnitTest {

0 commit comments

Comments
 (0)