nafis nibir 8 лет назад
Родитель
Сommit
f212474b80

+ 12
- 1
pom.xml Просмотреть файл

3
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
     <modelVersion>4.0.0</modelVersion>
5
     <modelVersion>4.0.0</modelVersion>
6
-
6
+    <build>
7
+        <plugins>
8
+            <plugin>
9
+                <groupId>org.apache.maven.plugins</groupId>
10
+                <artifactId>maven-compiler-plugin</artifactId>
11
+                <configuration>
12
+                    <source>1.8</source>
13
+                    <target>1.8</target>
14
+                </configuration>
15
+            </plugin>
16
+        </plugins>
17
+    </build>
7
     <groupId>com.zipcoder</groupId>
18
     <groupId>com.zipcoder</groupId>
8
     <artifactId>payment</artifactId>
19
     <artifactId>payment</artifactId>
9
     <version>1.0-SNAPSHOT</version>
20
     <version>1.0-SNAPSHOT</version>

+ 6
- 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
 
7
     public String toString(Payment[] payments){
8
     public String toString(Payment[] payments){
8
-        Arrays.sort(payments, new PaymentSortDescription());
9
+        //Comparator<Payment> shortDescComp = (p1, p2) -> p1.getShortDescription().compareTo(p2.getShortDescription());
10
+        Comparator<Payment> shortDescComp = Comparator.comparing(Payment::getShortDescription);
11
+        Arrays.sort(payments, shortDescComp);
9
         return createArrayString(payments);
12
         return createArrayString(payments);
10
     }
13
     }
11
 
14
 
15
     }
18
     }
16
 
19
 
17
     public String toStringById(Payment[] payments){
20
     public String toStringById(Payment[] payments){
18
-        Arrays.sort(payments, new PaymentSortID());
21
+        Comparator<Payment> sortByID = Comparator.comparing(Payment::getId);
22
+        Arrays.sort(payments, sortByID);
19
         return createArrayString(payments);
23
         return createArrayString(payments);
20
     }
24
     }
21
 
25
 

+ 0
- 8
src/main/java/com/zipcoder/payment/PaymentSortDescription.java Просмотреть файл

1
-package com.zipcoder.payment;
2
-import java.util.Comparator;
3
-
4
-public class PaymentSortDescription implements Comparator<Payment>{
5
-    public int compare(Payment o1, Payment o2) {
6
-        return o1.getShortDescription().compareTo(o2.getShortDescription());
7
-    }
8
-}

+ 0
- 10
src/main/java/com/zipcoder/payment/PaymentSortID.java Просмотреть файл

1
-package com.zipcoder.payment;
2
-
3
-import java.util.Comparator;
4
-
5
-public class PaymentSortID implements Comparator<Payment> {
6
-
7
-    public int compare(Payment o1, Payment o2) {
8
-        return o1.getId().compareTo(o2.getId());
9
-    }
10
-}