Bladeren bron

All Passing

Nick Satinover 7 jaren geleden
bovenliggende
commit
949b59ff1e

+ 7
- 2
src/main/java/rocks/zipcode/AlphaCharDocument.java Bestand weergeven

@@ -11,10 +11,15 @@ public class AlphaCharDocument extends Document {
11 11
     }
12 12
 
13 13
     @Override
14
-    public void write(String contentToBeWritten) {
14
+    public void write(String contentToBeWritten) throws IOException{
15
+        if (!isAlpha(contentToBeWritten)){
16
+            throw new IllegalArgumentException("Not all letters");
17
+        } else {
18
+            super.write(contentToBeWritten);
19
+        }
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
 }

+ 12
- 4
src/main/java/rocks/zipcode/Document.java Bestand weergeven

@@ -86,11 +86,18 @@ public class Document implements DocumentInterface {
86 86
     }
87 87
 
88 88
     @Override
89
-    public void replaceAll(String stringToReplace, String replacementString) {
89
+    public void replaceAll(String stringToReplace, String replacementString) throws IOException {
90
+        write(
91
+            read()
92
+            .replaceAll(stringToReplace, replacementString)
93
+        );
90 94
     }
91 95
 
92 96
     @Override
93
-    public void overWrite(String content) {
97
+    public void overWrite(String content) throws IOException {
98
+        FileWriter overWriter = new FileWriter(file, false);
99
+        overWriter.write(content);
100
+        overWriter.flush();
94 101
     }
95 102
 
96 103
     public List<String> toList() {
@@ -99,11 +106,12 @@ public class Document implements DocumentInterface {
99 106
 
100 107
     @Override
101 108
     public File getFile() {
102
-        return null;
109
+        return file;
103 110
     }
104 111
 
105 112
     @Override
106 113
     public String toString() {
107
-        return null;
114
+        StringBuilder builder = new StringBuilder();
115
+        return builder.append(file.toString() + "{" +read()).toString() + "}";
108 116
     }
109 117
 }

+ 2
- 2
src/main/java/rocks/zipcode/DocumentInterface.java Bestand weergeven

@@ -16,9 +16,9 @@ public interface DocumentInterface {
16 16
 
17 17
     String read();
18 18
 
19
-    void replaceAll(String stringToReplace, String replacementString);
19
+    void replaceAll(String stringToReplace, String replacementString) throws IOException;
20 20
 
21
-    void overWrite(String content);
21
+    void overWrite(String content) throws IOException;
22 22
 
23 23
     List<String> toList();
24 24
 

+ 9
- 2
src/main/java/rocks/zipcode/NumericCharDocument.java Bestand weergeven

@@ -11,10 +11,17 @@ public class NumericCharDocument extends Document {
11 11
     }
12 12
 
13 13
     @Override
14
-    public void write(String contentToBeWritten) {
14
+    public void write(String contentToBeWritten) throws IOException {
15
+            if (!isNumeric(contentToBeWritten)){
16
+                throw new IllegalArgumentException("Not all numbers");
17
+            } else {
18
+                super.write(contentToBeWritten);
19
+            }
20
+
15 21
     }
16 22
 
17 23
     private Boolean isNumeric(String s) {
18
-        return null;
24
+        return (s.matches("\\d+"));
19 25
     }
20 26
 }
27
+

+ 7
- 2
src/main/java/rocks/zipcode/SpecialCharDocument.java Bestand weergeven

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