Skip to content

Commit 5a4c8cf

Browse files
feat: markdown documentation
1 parent 6d7d7f6 commit 5a4c8cf

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)