-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.java
More file actions
75 lines (65 loc) · 2.94 KB
/
Task.java
File metadata and controls
75 lines (65 loc) · 2.94 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
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
public class Task {
private final String description;
private final LocalDateTime startTime;
private final LocalDateTime endTime;
private final boolean important; // already there
private final boolean hasTime; // ✅ flag for whether user gave time
// Default: hasTime = true, important = false
public Task(String description, LocalDateTime startTime, LocalDateTime endTime) {
this(description, startTime, endTime, false, startTime != null && endTime != null);
}
// Constructor with important flag
public Task(String description, LocalDateTime startTime, LocalDateTime endTime, boolean important) {
this(description, startTime, endTime, important, startTime != null && endTime != null);
}
// Full constructor
public Task(String description, LocalDateTime startTime, LocalDateTime endTime, boolean important, boolean hasTime) {
this.description = description.trim();
this.startTime = startTime;
this.endTime = endTime;
this.important = important;
this.hasTime = hasTime;
}
public String getDescription() { return description; }
public LocalDateTime getStartTime() { return startTime; }
public LocalDateTime getEndTime() { return endTime; }
public boolean isImportant() { return important; }
public boolean hasTime() { return hasTime; }
public boolean overlapsWith(Task other) {
return this.startTime != null && this.endTime != null &&
other.startTime != null && other.endTime != null &&
this.startTime.isBefore(other.endTime) && this.endTime.isAfter(other.startTime);
}
public boolean sameActivity(Task other) {
return this.description.equalsIgnoreCase(other.description);
}
@Override
public String toString() {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("MMM dd, yyyy | hh:mm a");
String base;
if (hasTime && startTime != null && endTime != null) {
base = description + " (" + startTime.format(fmt) + " - " + endTime.format(fmt) + ")";
} else {
base = description; // ⬅ timeless task only shows text
}
return important ? "[IMPORTANT] " + base : base;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Task)) return false;
Task task = (Task) o;
return important == task.important &&
hasTime == task.hasTime &&
Objects.equals(description, task.description) &&
Objects.equals(startTime, task.startTime) &&
Objects.equals(endTime, task.endTime);
}
@Override
public int hashCode() {
return Objects.hash(description, startTime, endTime, important, hasTime);
}
}