-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
57 lines (48 loc) · 1.32 KB
/
Copy pathTest.java
File metadata and controls
57 lines (48 loc) · 1.32 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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test {
public static void main(String[] args) {
List<Schedule> schedules = new ArrayList<>();
schedules.add(new Schedule(1, 10, "Alice"));
schedules.add(new Schedule(5, 7, "Bob"));
schedules.add(new Schedule(6, 12, "Carla"));
schedules.add(new Schedule(15, 17, "David"));
// <1,5,alice> <5,7, Alice,bob> <7,10,alice>
// last.end = 6
//
Collections.sort(schedules,
Comparator.comparingInt((Schedule s) -> s.start).thenComparingInt(s -> s.end));
schedules.forEach(System.out::println);
}
}
class Schedule {
int start;
int end;
String name;
public Schedule(int start, int end, String name) {
this.start = start;
this.end = end;
this.name = name;
}
public int getStart() {
return start;
}
public int getEnd() {
return end;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Schedule{" +
"start=" + start +
", end=" + end +
", name='" + name + '\'' +
'}';
}
}