-
Notifications
You must be signed in to change notification settings - Fork 548
/
Copy pathInteraction.java
77 lines (65 loc) · 2.19 KB
/
Interaction.java
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
package seedu.address.model.interaction;
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
/**
* Represents an interaction in the address book. Guarantees: immutable; date is
* valid as declared in {@link #isValidDate(String)}
*/
public class Interaction {
public static final String MESSAGE_CONSTRAINTS = "Please input a valid date (yyyy-MM-dd).";
public final String description;
public final LocalDate date;
/**
* Constructs a {@code Interaction}.
* @param description A valid interaction description.
* @param date A valid date string
*/
public Interaction(String description, String date) {
requireNonNull(description);
requireNonNull(date);
checkArgument(isValidDate(date), MESSAGE_CONSTRAINTS);
this.date = LocalDate.parse(date);
this.description = description;
}
/**
* Constructs a {@code Interaction}.
* @param description A valid interaction description.
*/
public Interaction(String description) {
requireNonNull(description);
this.date = LocalDate.now();
this.description = description;
}
/**
* Returns true if a given string is a valid tag name.
*/
boolean isValidDate(String input) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
format.parse(input);
return true;
} catch (ParseException e) {
return false;
}
}
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Interaction // instanceof handles nulls
&& description.equals(((Interaction) other).description))
&& date.equals(((Interaction) other).date); // state check
}
@Override
public int hashCode() {
return description.hashCode();
}
/**
* Format state as text for viewing.
*/
public String toString() {
return '[' + description + "][" + date + ']';
}
}