Allison Ziegler před 6 roky
rodič
revize
45bf1fdf6b

+ 2
- 0
src/main/java/io/zipcoder/MonkeyTypewriter.java Zobrazit soubor

@@ -49,7 +49,9 @@ public class MonkeyTypewriter {
49 49
         // Print out the copied versions here.
50 50
         System.out.println("Unsafe Copier: ");
51 51
         System.out.println(dangerWillRobinson.copied);
52
+        System.out.println("Correctly Copied: " + dangerWillRobinson.copied.equals(introduction));
52 53
         System.out.println("Safe Copier: ");
53 54
         System.out.println(safetyFirst.copied);
55
+        System.out.println("Correctly Copied: " + safetyFirst.copied.equals(introduction));
54 56
     }
55 57
 }

+ 2
- 1
src/main/java/io/zipcoder/SafeCopier.java Zobrazit soubor

@@ -13,16 +13,17 @@ public class SafeCopier extends Copier {
13 13
 
14 14
     public SafeCopier(String toCopy) {
15 15
         super(toCopy);
16
+        alohomora = new ReentrantReadWriteLock();
16 17
     }
17 18
 
18 19
     public void run() {
19
-        alohomora = new ReentrantReadWriteLock();
20 20
         alohomora.writeLock().lock();
21 21
         alohomora.readLock().lock();
22 22
         try {
23 23
             while (stringIterator.hasNext()) {
24 24
                 copied += stringIterator.next() + " ";
25 25
             }
26
+            copied = copied.trim();
26 27
         } finally {
27 28
             alohomora.writeLock().unlock();
28 29
             alohomora.readLock().unlock();

+ 1
- 0
src/main/java/io/zipcoder/UnsafeCopier.java Zobrazit soubor

@@ -13,5 +13,6 @@ public class UnsafeCopier extends Copier {
13 13
         while (stringIterator.hasNext()) {
14 14
             copied += stringIterator.next() + " ";
15 15
         }
16
+        copied = copied.trim();
16 17
     }
17 18
 }