Skip to content

Commit 851b58e

Browse files
committed
Update equals and hashcode methods for container resources
Differential Revision: https://phabricator.intern.facebook.com/D22924754
1 parent 9fcace7 commit 851b58e

File tree

16 files changed

+211
-2
lines changed

16 files changed

+211
-2
lines changed

portability-types-common/src/main/java/org/datatransferproject/types/common/models/calendar/CalendarAttendeeModel.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.fasterxml.jackson.annotation.JsonCreator;
1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020

21+
import java.util.Objects;
22+
2123
public class CalendarAttendeeModel {
2224
private final String displayName;
2325
private final String email;
@@ -44,4 +46,19 @@ public String getEmail() {
4446
public String getDisplayName() {
4547
return displayName;
4648
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) return true;
53+
if (o == null || getClass() != o.getClass()) return false;
54+
CalendarAttendeeModel that = (CalendarAttendeeModel) o;
55+
return getOptional() == that.getOptional() &&
56+
Objects.equals(getDisplayName(), that.getDisplayName()) &&
57+
Objects.equals(getEmail(), that.getEmail());
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return Objects.hash(getDisplayName(), getEmail(), getOptional());
63+
}
4764
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/calendar/CalendarContainerResource.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.fasterxml.jackson.annotation.JsonTypeName;
2121
import com.google.common.collect.ImmutableList;
2222
import java.util.Collection;
23+
import java.util.Objects;
2324
import org.datatransferproject.types.common.models.ContainerResource;
2425

2526
/** A Wrapper for all the possible objects that can be returned by a calendar exporter. */
@@ -43,4 +44,18 @@ public Collection<CalendarModel> getCalendars() {
4344
public Collection<CalendarEventModel> getEvents() {
4445
return events;
4546
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (this == o) return true;
51+
if (o == null || getClass() != o.getClass()) return false;
52+
CalendarContainerResource that = (CalendarContainerResource) o;
53+
return Objects.equals(getCalendars(), that.getCalendars()) &&
54+
Objects.equals(getEvents(), that.getEvents());
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return Objects.hash(getCalendars(), getEvents());
60+
}
4661
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/calendar/CalendarEventModel.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import java.time.OffsetDateTime;
2121
import java.util.List;
22+
import java.util.Objects;
2223

2324
public class CalendarEventModel {
2425

@@ -83,6 +84,34 @@ public RecurrenceRule getRecurrenceRule() {
8384
return recurrenceRule;
8485
}
8586

87+
@Override
88+
public boolean equals(Object o) {
89+
if (this == o) return true;
90+
if (o == null || getClass() != o.getClass()) return false;
91+
CalendarEventModel that = (CalendarEventModel) o;
92+
return Objects.equals(getCalendarId(), that.getCalendarId())
93+
&& Objects.equals(getTitle(), that.getTitle())
94+
&& Objects.equals(getNotes(), that.getNotes())
95+
&& Objects.equals(getAttendees(), that.getAttendees())
96+
&& Objects.equals(getLocation(), that.getLocation())
97+
&& Objects.equals(getStartTime(), that.getStartTime())
98+
&& Objects.equals(getEndTime(), that.getEndTime())
99+
&& Objects.equals(getRecurrenceRule(), that.getRecurrenceRule());
100+
}
101+
102+
@Override
103+
public int hashCode() {
104+
return Objects.hash(
105+
getCalendarId(),
106+
getTitle(),
107+
getNotes(),
108+
getAttendees(),
109+
getLocation(),
110+
getStartTime(),
111+
getEndTime(),
112+
getRecurrenceRule());
113+
}
114+
86115
public static class CalendarEventTime {
87116
private final OffsetDateTime dateTime;
88117
private final boolean dateOnly;
@@ -102,5 +131,19 @@ public OffsetDateTime getDateTime() {
102131
public boolean isDateOnly() {
103132
return dateOnly;
104133
}
134+
135+
@Override
136+
public boolean equals(Object o) {
137+
if (this == o) return true;
138+
if (o == null || getClass() != o.getClass()) return false;
139+
CalendarEventTime that = (CalendarEventTime) o;
140+
return isDateOnly() == that.isDateOnly() &&
141+
Objects.equals(getDateTime(), that.getDateTime());
142+
}
143+
144+
@Override
145+
public int hashCode() {
146+
return Objects.hash(getDateTime(), isDateOnly());
147+
}
105148
}
106149
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/calendar/CalendarModel.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.fasterxml.jackson.annotation.JsonCreator;
1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020

21+
import java.util.Objects;
22+
2123
public class CalendarModel {
2224
private final String id;
2325
private final String name;
@@ -44,4 +46,20 @@ public String getDescription() {
4446
public String getId() {
4547
return id;
4648
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) return true;
53+
if (o == null || getClass() != o.getClass()) return false;
54+
CalendarModel that = (CalendarModel) o;
55+
return Objects.equals(getId(), that.getId()) &&
56+
Objects.equals(getName(), that.getName()) &&
57+
Objects.equals(getDescription(), that.getDescription());
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return Objects.hash(getId(), getName(), getDescription());
63+
}
64+
4765
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/mail/MailContainerModel.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import com.google.common.base.MoreObjects;
2121

22+
import java.util.Objects;
23+
2224
// Model for a mail folder or label, which may contain sub folders and messages
2325
public final class MailContainerModel {
2426
private final String id;
@@ -42,4 +44,18 @@ public String getName() {
4244
public String toString() {
4345
return MoreObjects.toStringHelper(this).add("id", id).add("name", name).toString();
4446
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (this == o) return true;
51+
if (o == null || getClass() != o.getClass()) return false;
52+
MailContainerModel that = (MailContainerModel) o;
53+
return Objects.equals(getId(), that.getId()) &&
54+
Objects.equals(getName(), that.getName());
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return Objects.hash(getId(), getName());
60+
}
4561
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/mail/MailContainerResource.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.base.MoreObjects;
2222
import com.google.common.collect.ImmutableList;
2323
import java.util.Collection;
24+
import java.util.Objects;
2425
import org.datatransferproject.types.common.models.ContainerResource;
2526

2627
/** A Wrapper for all the possible objects that can be returned by a mail exporter. */
@@ -52,4 +53,18 @@ public String toString() {
5253
.add("messages", messages.size())
5354
.toString();
5455
}
56+
57+
@Override
58+
public boolean equals(Object o) {
59+
if (this == o) return true;
60+
if (o == null || getClass() != o.getClass()) return false;
61+
MailContainerResource that = (MailContainerResource) o;
62+
return Objects.equals(getFolders(), that.getFolders()) &&
63+
Objects.equals(getMessages(), that.getMessages());
64+
}
65+
66+
@Override
67+
public int hashCode() {
68+
return Objects.hash(getFolders(), getMessages());
69+
}
5570
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/mail/MailMessageModel.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.base.MoreObjects;
2121
import com.google.common.collect.ImmutableList;
2222
import java.util.List;
23+
import java.util.Objects;
2324

2425
public final class MailMessageModel {
2526
private final String rawString;
@@ -49,4 +50,18 @@ public String toString() {
4950
.add("containerIds", containerIds.size())
5051
.toString();
5152
}
53+
54+
@Override
55+
public boolean equals(Object o) {
56+
if (this == o) return true;
57+
if (o == null || getClass() != o.getClass()) return false;
58+
MailMessageModel that = (MailMessageModel) o;
59+
return Objects.equals(getRawString(), that.getRawString()) &&
60+
Objects.equals(getContainerIds(), that.getContainerIds());
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
return Objects.hash(getRawString(), getContainerIds());
66+
}
5267
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/tasks/TaskContainerResource.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.fasterxml.jackson.annotation.JsonTypeName;
2121
import com.google.common.collect.ImmutableList;
2222
import java.util.Collection;
23+
import java.util.Objects;
2324
import org.datatransferproject.types.common.models.ContainerResource;
2425

2526
/** A Wrapper for all the possible objects that can be returned by a task exporter. */
@@ -43,4 +44,18 @@ public Collection<TaskListModel> getLists() {
4344
public Collection<TaskModel> getTasks() {
4445
return tasks;
4546
}
47+
48+
@Override
49+
public boolean equals(Object o) {
50+
if (this == o) return true;
51+
if (o == null || getClass() != o.getClass()) return false;
52+
TaskContainerResource that = (TaskContainerResource) o;
53+
return Objects.equals(getLists(), that.getLists())
54+
&& Objects.equals(getTasks(), that.getTasks());
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return Objects.hash(getLists(), getTasks());
60+
}
4661
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/tasks/TaskListModel.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import org.datatransferproject.types.common.models.DataModel;
2121

22+
import java.util.Objects;
23+
2224
public class TaskListModel extends DataModel {
2325
private final String id;
2426
private final String name;
@@ -36,4 +38,18 @@ public String getName() {
3638
public String getId() {
3739
return id;
3840
}
41+
42+
@Override
43+
public boolean equals(Object o) {
44+
if (this == o) return true;
45+
if (o == null || getClass() != o.getClass()) return false;
46+
TaskListModel that = (TaskListModel) o;
47+
return Objects.equals(getId(), that.getId()) &&
48+
Objects.equals(getName(), that.getName());
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hash(getId(), getName());
54+
}
3955
}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/tasks/TaskModel.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import java.time.Instant;
2121
import java.util.List;
22+
import java.util.Objects;
2223

2324
public class TaskModel {
2425
private final String taskListId;
@@ -56,4 +57,21 @@ public String getTaskListId() {
5657
public Instant getCompletedTime() { return completedTime; }
5758

5859
public Instant getDueTime() { return dueTime; }
60+
61+
@Override
62+
public boolean equals(Object o) {
63+
if (this == o) return true;
64+
if (o == null || getClass() != o.getClass()) return false;
65+
TaskModel taskModel = (TaskModel) o;
66+
return Objects.equals(getTaskListId(), taskModel.getTaskListId()) &&
67+
Objects.equals(getText(), taskModel.getText()) &&
68+
Objects.equals(getNotes(), taskModel.getNotes()) &&
69+
Objects.equals(getCompletedTime(), taskModel.getCompletedTime()) &&
70+
Objects.equals(getDueTime(), taskModel.getDueTime());
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return Objects.hash(getTaskListId(), getText(), getNotes(), getCompletedTime(), getDueTime());
76+
}
5977
}

0 commit comments

Comments
 (0)