Seth 7 лет назад
Родитель
Сommit
18050b3a1b

+ 6
- 1
src/main/java/rocks/zipcode/AlphaCharDocument.java Просмотреть файл

@@ -1,6 +1,8 @@
1 1
 package rocks.zipcode;
2 2
 
3 3
 import java.io.IOException;
4
+import java.util.regex.Matcher;
5
+import java.util.regex.Pattern;
4 6
 
5 7
 /**
6 8
  * @author leon on 16/11/2018.
@@ -12,9 +14,12 @@ public class AlphaCharDocument extends Document {
12 14
 
13 15
     @Override
14 16
     public void write(String contentToBeWritten) {
17
+        if (isAlpha(contentToBeWritten)) {
18
+            super.write(contentToBeWritten);
19
+        } else throw new IllegalArgumentException();
15 20
     }
16 21
 
17 22
     private Boolean isAlpha(String s) {
18
-        return null;
23
+        return s.matches("[a-zA-Z\\s]*");
19 24
     }
20 25
 }

+ 5
- 1
src/main/java/rocks/zipcode/NumericCharDocument.java Просмотреть файл

@@ -12,9 +12,13 @@ public class NumericCharDocument extends Document {
12 12
 
13 13
     @Override
14 14
     public void write(String contentToBeWritten) {
15
+        if (isNumeric(contentToBeWritten)) {
16
+            super.write(contentToBeWritten);
17
+        } else throw new IllegalArgumentException();
15 18
     }
16 19
 
17 20
     private Boolean isNumeric(String s) {
18
-        return null;
21
+
22
+        return s.matches("[0-9]*");
19 23
     }
20 24
 }

+ 5
- 1
src/main/java/rocks/zipcode/SpecialCharDocument.java Просмотреть файл

@@ -12,9 +12,13 @@ public class SpecialCharDocument extends Document {
12 12
 
13 13
     @Override
14 14
     public void write(String contentToBeWritten) {
15
+        if (isSpecialCharacters(contentToBeWritten)) {
16
+            super.write(contentToBeWritten);
17
+        } else throw new IllegalArgumentException();
15 18
     }
16 19
 
17 20
     private Boolean isSpecialCharacters(String s) {
18
-        return null;
21
+
22
+        return s.matches("[^a-zA-Z0-9]*");
19 23
     }
20 24
 }