Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Drafts/WordSplitDemo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/out

/target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
9 changes: 9 additions & 0 deletions Drafts/WordSplitDemo/src/RuleInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public interface RuleInterface {

boolean check(String word);
String action(String word);

default String newMethod() {
return "Test";
}
}
12 changes: 12 additions & 0 deletions Drafts/WordSplitDemo/src/TransformerRuleLength5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class TransformerRuleLength5 implements RuleInterface {

@Override
public boolean check(String word) {
return word.length() == 5;
}

@Override
public String action(String word) {
return word.toLowerCase();
}
}
14 changes: 14 additions & 0 deletions Drafts/WordSplitDemo/src/TransformerRuleLentgh3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class TransformerRuleLentgh3 implements RuleInterface {
//no fields -> no state
public boolean check(String input) {
return input.length() == 3;
}

public String action(String input) {
return input.toUpperCase();
}

public String newMethod() {
return "Hello from Rule 3";
}
}
27 changes: 27 additions & 0 deletions Drafts/WordSplitDemo/src/WordTransformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
39 changes: 39 additions & 0 deletions Drafts/WordSplitDemo/src/WordTransformerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class WordTransformerTest {

@Test
public void testTransform() {
//test data
String input = "aaa bcDE eklm iii";

//call method we test with test data
String actual = WordTransformer.transform(input);

//expected result
String expected = "AAA bcDE eklm III";

//compare actual and expected
assertEquals("string length", expected.length(), actual.length());
assertEquals(expected, actual);
}

@Test
public void testTransformRule5() {
//test data
String input = "aaa bcDEF eklm iiiOP";

//call method we test with test data
String actual = WordTransformer.transform(input, new TransformerRuleLength5());

//expected result
String expected = "aaa bcdef eklm iiiop";

//compare actual and expected
assertEquals("string length", expected.length(), actual.length());
assertEquals(expected, actual);
}

}