1 |
package org.icesoft.notify.cloud.core; |
2 |
|
3 |
import java.io.Serializable; |
4 |
import java.util.Collections; |
5 |
import java.util.Map; |
6 |
import java.util.logging.Level; |
7 |
import java.util.logging.Logger; |
8 |
|
9 |
import static org.icesoft.util.ObjectUtilities.isEqual; |
10 |
import static org.icesoft.util.PreCondition.checkIfIsNotNull; |
11 |
import static org.icesoft.util.PreCondition.checkIfIsNotNullAndIsNotEmpty; |
12 |
|
13 |
public class NotificationData |
14 |
implements Serializable { |
15 |
private static final long serialVersionUID = 5330022915994081756L; |
16 |
|
17 |
private static final Logger LOGGER = Logger.getLogger(NotificationData.class.getName()); |
18 |
|
19 |
private final Map<NotificationProvider.Category, Map<String, Object>> categoryToPropertyMap; |
20 |
private final CloudNotificationEndpoint notificationEndpoint; |
21 |
|
22 |
public NotificationData( |
23 |
final CloudNotificationEndpoint notificationEndpoint, |
24 |
final Map<NotificationProvider.Category, Map<String, Object>> categoryToPropertyMap) |
25 |
throws IllegalArgumentException, NullPointerException { |
26 |
this.notificationEndpoint = |
27 |
|
28 |
checkIfIsNotNull( |
29 |
notificationEndpoint, |
30 |
"Illegal argument notificationEndpoint: '" + notificationEndpoint + "'. " + |
31 |
"Argument cannot be null." |
32 |
); |
33 |
this.categoryToPropertyMap = |
34 |
|
35 |
checkIfIsNotNullAndIsNotEmpty( |
36 |
categoryToPropertyMap, |
37 |
"Illegal argument categoryToPropertyMap: '" + categoryToPropertyMap + "'. " + |
38 |
"Argument cannot be null or empty." |
39 |
); |
40 |
} |
41 |
|
42 |
@Override |
43 |
public boolean equals(final Object object) { |
44 |
return |
45 |
object instanceof NotificationData && |
46 |
isEqual( |
47 |
((NotificationData)object).getModifiableCategoryToPropertyMap(), |
48 |
getModifiableCategoryToPropertyMap() |
49 |
) && |
50 |
isEqual( |
51 |
((NotificationData)object).getNotificationEndpoint(), |
52 |
getNotificationEndpoint() |
53 |
); |
54 |
} |
55 |
|
56 |
public Map<NotificationProvider.Category, Map<String, Object>> getCategoryToPropertyMap() { |
57 |
return Collections.unmodifiableMap(getModifiableCategoryToPropertyMap()); |
58 |
} |
59 |
|
60 |
public CloudNotificationEndpoint getNotificationEndpoint() { |
61 |
return notificationEndpoint; |
62 |
} |
63 |
|
64 |
@Override |
65 |
public int hashCode() { |
66 |
int _hashCode; |
67 |
_hashCode = getModifiableCategoryToPropertyMap().hashCode(); |
68 |
_hashCode = 31 * _hashCode + (getNotificationEndpoint().hashCode()); |
69 |
return _hashCode; |
70 |
} |
71 |
|
72 |
@Override |
73 |
public String toString() { |
74 |
return "NotificationData[" + classMembersToString() + "]"; |
75 |
} |
76 |
|
77 |
protected String classMembersToString() { |
78 |
return |
79 |
"categoryToPropertyMap: '" + categoryToPropertyMap + "', " + |
80 |
"notificationEndpoint: '" + notificationEndpoint + "'"; |
81 |
} |
82 |
|
83 |
protected Map<NotificationProvider.Category, Map<String, Object>> getModifiableCategoryToPropertyMap() { |
84 |
return categoryToPropertyMap; |
85 |
} |
86 |
} |