File tree Expand file tree Collapse file tree 3 files changed +61
-1
lines changed
main/java/de/claudioaltamura/java25/markdowndocumentation
test/java/de/claudioaltamura/java25/markdowndocumentation Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ Java 25 features examples
88- ScopedValue
99- instance main method
1010- module import declarations
11- - flexible constructor bodies
11+ - flexible constructor bodies
12+ - markdown documentation
Original file line number Diff line number Diff line change 1+ package de .claudioaltamura .java25 .markdowndocumentation ;
2+
3+ public class CharReplacer {
4+
5+ public String replace (String input ) {
6+ if (input == null ) {
7+ throw new IllegalArgumentException ("Input string cannot be null" );
8+ }
9+
10+ var ret = replace (input , "e" , "3" );
11+ ret = replace (ret , "o" , "0" );
12+
13+ return ret ;
14+ }
15+
16+ /// Replaces all occurrences of the target string with the replacement string in the input string.
17+ ///
18+ /// @param input the string to perform the replacement on
19+ /// @param target the string to be replaced
20+ /// @param replacement the string to replace the target with
21+ /// @return a new string with the replacements made
22+ /// @throws IllegalArgumentException if input is null, target is null or empty, or replacement is null
23+ String replace (String input , String target , String replacement ) {
24+ if (input == null ) {
25+ throw new IllegalArgumentException ("Input string cannot be null" );
26+ }
27+ if (target == null || target .isEmpty ()) {
28+ throw new IllegalArgumentException ("Target string cannot be null or empty" );
29+ }
30+ if (replacement == null ) {
31+ throw new IllegalArgumentException ("Replacement string cannot be null" );
32+ }
33+ return input .replace (target , replacement );
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ package de .claudioaltamura .java25 .markdowndocumentation ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import static org .junit .jupiter .api .Assertions .*;
6+
7+ class CharReplacerTest {
8+
9+ @ Test
10+ void replaceAll () {
11+ CharReplacer charReplacer = new CharReplacer ();
12+ String result = charReplacer .replace ("Hello World!" );
13+ assertEquals ("H3ll0 W0rld!" , result );
14+ }
15+
16+
17+ @ Test
18+ void replace () {
19+ CharReplacer charReplacer = new CharReplacer ();
20+ String result = charReplacer .replace ("Hello World!" , "o" , "0" );
21+ assertEquals ("Hellx Wxrld!" , result );
22+ }
23+
24+ }
You can’t perform that action at this time.
0 commit comments