Skip to content

Commit 7299c5d

Browse files
committed
add Rule5&6
1 parent 6dfd3d7 commit 7299c5d

5 files changed

Lines changed: 150 additions & 60 deletions

File tree

.idea/workspace.xml

Lines changed: 111 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

effective_java/src/main/java/com/yiyun/AllTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22

33
import com.yiyun.Rule03.Elvis;
44
import com.yiyun.Rule04.UtilityClass;
5+
import com.yiyun.Rule05.Lexicon;
6+
import com.yiyun.Rule05.SpellChecker;
7+
import com.yiyun.Rule06.RomanNumerals;
58
import org.junit.Test;
69

710
public class AllTest {
811

912
@Test
1013
public void Test0x(){
11-
14+
}
15+
@Test
16+
public void Test06(){
17+
System.out.println(RomanNumerals.isRomanNumeral("IV"));
18+
}
19+
@Test
20+
public void Test05(){
21+
SpellChecker spellChecker = new SpellChecker(new Lexicon());
22+
System.out.println(spellChecker.isValid("test"));
1223
}
1324
@Test
1425
public void Test03(){
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.yiyun.Rule05;
2+
3+
public class Lexicon {
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.yiyun.Rule05;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
6+
public class SpellChecker {
7+
private final Lexicon dictionary;
8+
public SpellChecker(Lexicon dictionary) {
9+
this.dictionary = Objects.requireNonNull(dictionary);
10+
}
11+
public boolean isValid(String word) {return true;}
12+
public List<String> suggestions(String typo) {return null;}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.yiyun.Rule06;
2+
3+
import java.util.regex.Pattern;
4+
5+
public class RomanNumerals {
6+
private static final Pattern ROMAN = Pattern.compile("^(?=.)M*(C[MD]|D?C{0,3})" + "(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$");
7+
public static boolean isRomanNumeral(String s) {
8+
return ROMAN.matcher(s).matches();
9+
}
10+
}

0 commit comments

Comments
 (0)