ソースを参照

oops I added lambdas

Allison Ziegler 8 年 前
コミット
27597a253b

+ 8
- 2
src/main/java/com/zipcoder/payment/PaymentPresenter.java ファイルの表示

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
 import java.util.Arrays;
3
 import java.util.Arrays;
4
+import java.util.Comparator;
4
 
5
 
5
 public class PaymentPresenter {
6
 public class PaymentPresenter {
6
 
7
 
8
+    Comparator<Payment> paymentSortByID = (Payment p1, Payment p2)  -> {
9
+            Long p1ID = p1.getId();
10
+            Long p2ID = p2.getId();
11
+            return p1ID.compareTo(p2ID);
12
+    };
13
+
7
 
14
 
8
     public String toString(Payment[] p){
15
     public String toString(Payment[] p){
9
         Arrays.sort(p);
16
         Arrays.sort(p);
17
     }
24
     }
18
 
25
 
19
     public String toStringByID(Payment[] p){
26
     public String toStringByID(Payment[] p){
20
-        PaymentSortById psbi = new PaymentSortById();
21
-        Arrays.sort(p, psbi);
27
+        Arrays.sort(p, paymentSortByID);
22
         return generateOutputString(p);
28
         return generateOutputString(p);
23
     }
29
     }
24
 
30
 

+ 0
- 12
src/main/java/com/zipcoder/payment/PaymentSortById.java ファイルの表示

1
-package com.zipcoder.payment;
2
-
3
-import java.util.Comparator;
4
-
5
-public class PaymentSortById implements Comparator<Payment>{
6
-    public int compare(Payment p1, Payment p2) {
7
-        Long p1ID = p1.getId();
8
-        Long p2ID = p2.getId();
9
-        return p1ID.compareTo(p2ID);
10
-    }
11
-
12
-}

+ 0
- 31
src/test/java/com/zipcoder/payment/PaymentSortByIdTest.java ファイルの表示

1
-package com.zipcoder.payment;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-
6
-public class PaymentSortByIdTest {
7
-    Check ch = new Check(1, "Sansa Stark", "1234567", "987654321");
8
-    PayPal pp = new PayPal(1, "Catelyn Stark", "ladystark@winterfell.com");
9
-    CreditCard cc = new CreditCard(123, "Robb Stark", "4444444444", 12, 2020);
10
-    Check ch2 = new Check(900, "Arya Stark", "1234569", "987654444");
11
-
12
-    PaymentSortById psbi = new PaymentSortById();
13
-
14
-
15
-    @Test
16
-    public void paymentSortByIdTest1() {
17
-        int expected = 0;
18
-        int actual = psbi.compare(ch, pp);
19
-        Assert.assertEquals(expected, actual);
20
-    }
21
-    @Test
22
-    public void paymentSortByIdTest2() {
23
-        int actual = psbi.compare(ch, cc);
24
-        Assert.assertTrue(actual < 0);
25
-    }
26
-    @Test
27
-    public void paymentSortByIdTest3() {
28
-        int actual = psbi.compare(ch2, cc);
29
-        Assert.assertTrue(actual > 0);
30
-    }
31
-}