-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathWordTransformer.java
More file actions
27 lines (23 loc) · 859 Bytes
/
WordTransformer.java
File metadata and controls
27 lines (23 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class WordTransformer {
//length == 3 -> to UpperCase
//transform("aaa bcDE eklm iii") -> "AAA bdDE eklm III"
//length == 5 -> toLowerCase
//transform("aaa bcDEf eklm iiiPM") -> "aaa bcdef eklm iiipm"
//length ==2 -> relace first char with *
//transform("aa bcDEf ek") -> "*a bcDEf *k"
public static String transform(String input, RuleInterface c) {
String[] words = input.split(" ");
for(int i = 0; i< words.length; i++ ) {
String word = words[i];
if (c.check(word)) {
words[i] = c.action(word);
}
}
return String.join(" ", words);
//nothing is executed after this line
}
public static String transform(String input) {
RuleInterface c = new TransformerRuleLentgh3();
return transform(input, c);
}
}