ソースを参照

minor refactor

mpierse 7 年 前
コミット
3cd53396f4
共有2 個のファイルを変更した3 個の追加20 個の削除を含む
  1. 2
    19
      src/main/java/rocks/zipcode/Document.java
  2. 1
    1
      src/main/java/rocks/zipcode/NumericCharDocument.java

+ 2
- 19
src/main/java/rocks/zipcode/Document.java ファイルの表示

@@ -30,8 +30,7 @@ public class Document implements DocumentInterface {
30 30
             e.printStackTrace();
31 31
         }
32 32
         try {
33
-            bw.append(contentToBeWritten);
34
-            bw.close();
33
+            bw.write(contentToBeWritten);
35 34
         } catch (IOException ex) {
36 35
             ex.printStackTrace();
37 36
         } finally {
@@ -57,23 +56,7 @@ public class Document implements DocumentInterface {
57 56
 
58 57
     @Override
59 58
     public String read(Integer lineNumber) {
60
-        String result ="";
61
-        try {
62
-            BufferedReader br = new BufferedReader(new FileReader(file));
63
-            String str =br.readLine();
64
-            int counter = 0;
65
-            while (str  != null){
66
-                if(counter==lineNumber){
67
-                result+= str;}
68
-                str = br.readLine();
69
-               counter++;
70
-            }
71
-        } catch (FileNotFoundException e) {
72
-            e.printStackTrace();
73
-        } catch (IOException e) {
74
-            e.printStackTrace();
75
-        }
76
-        return result;
59
+        return this.toList().get(lineNumber);
77 60
     }
78 61
 
79 62
     @Override

+ 1
- 1
src/main/java/rocks/zipcode/NumericCharDocument.java ファイルの表示

@@ -21,7 +21,7 @@ public class NumericCharDocument extends Document {
21 21
     }
22 22
 
23 23
     private void isNumeric(String s) throws IOException{
24
-        if(!s.matches("[0-9\\s]*"))
24
+        if(!s.matches("[\\d\\s]*"))
25 25
             throw new IllegalArgumentException();
26 26
     }
27 27
 }