-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
89 lines (66 loc) · 2.85 KB
/
Main.java
File metadata and controls
89 lines (66 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.dj;
import com.dj.domain.Employee;
import com.dj.domain.StoreEmployee;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Employee> employees = new ArrayList<>(List.of(
new Employee(10001,"Ralph",2015),
new Employee(10005,"Carole",2021),
new Employee(10022,"Jane",2013),
new Employee(13151,"Laura",2020),
new Employee(10020,"Jim",2018)));
// var comparator = new EmployeeComparator<>();
// employees.sort(comparator);
employees.sort(new Employee.EmployeeComparator<>("yearStarted").reversed());
for (Employee e : employees){
System.out.println(e);
}
System.out.println("Store Members");
List<StoreEmployee> storeEmployees = new ArrayList<>(List.of(
new StoreEmployee(10015,"Meg",2019,"Target"),
new StoreEmployee(10515,"Joe",2021,"Walmart"),
new StoreEmployee(10105,"Tom",2020,"Macys"),
new StoreEmployee(10215,"Marty",2018,"Walmart"),
new StoreEmployee(10322,"Bud",2016,"Target")
));
// var genericEmployee = new StoreEmployee();
var comparator = new StoreEmployee().new StoreComparator<>();
storeEmployees.sort(comparator);
for (StoreEmployee e : storeEmployees){
System.out.println(e);
}
System.out.println("With Pig Latin Names");
addPigLatinName(storeEmployees);
}
public static void addPigLatinName(List<? extends StoreEmployee> list){
String lastName = "Piggy";
class DecoratedEmployee extends StoreEmployee implements Comparable<DecoratedEmployee> {
private String pigLatinName;
private Employee originalInstance;
public DecoratedEmployee(String pigLatinName, Employee originalInstance) {
this.pigLatinName = pigLatinName + " " + lastName;
this.originalInstance = originalInstance;
}
@Override
public String toString() {
return originalInstance.toString() + " " + pigLatinName;
}
@Override
public int compareTo(DecoratedEmployee o) {
return pigLatinName.compareTo(o.pigLatinName);
}
}
List<DecoratedEmployee> newList = new ArrayList<>(list.size());
for (var employee : list){
String name = employee.getName();
String pigLatin = name.substring(1) + name.charAt(0) + "ay";
newList.add(new DecoratedEmployee(pigLatin, employee));
}
newList.sort(null);
for (var dEmployee : newList){
System.out.println(dEmployee.originalInstance.getName() + " " + dEmployee.pigLatinName);
}
}
}