11
11
12
12
import cn .jiguang .common .utils .Preconditions ;
13
13
14
- public class Message implements PushModel {
14
+ public class Message implements PushModel {
15
15
private static final String TITLE = "title" ;
16
16
private static final String MSG_CONTENT = "msg_content" ;
17
17
private static final String CONTENT_TYPE = "content_type" ;
18
18
private static final String EXTRAS = "extras" ;
19
-
19
+
20
20
private final String title ;
21
21
private final String msgContent ;
22
22
private final String contentType ;
@@ -26,12 +26,12 @@ public class Message implements PushModel {
26
26
private final Map <String , JsonObject > jsonExtras ;
27
27
private final Map <String , JsonPrimitive > customData ;
28
28
29
- private Message (String title , String msgContent , String contentType ,
30
- Map <String , String > extras ,
31
- Map <String , Number > numberExtras ,
32
- Map <String , Boolean > booleanExtras ,
33
- Map <String , JsonObject > jsonExtras ,
34
- Map <String , JsonPrimitive > customData ) {
29
+ private Message (String title , String msgContent , String contentType ,
30
+ Map <String , String > extras ,
31
+ Map <String , Number > numberExtras ,
32
+ Map <String , Boolean > booleanExtras ,
33
+ Map <String , JsonObject > jsonExtras ,
34
+ Map <String , JsonPrimitive > customData ) {
35
35
this .title = title ;
36
36
this .msgContent = msgContent ;
37
37
this .contentType = contentType ;
@@ -41,15 +41,15 @@ private Message(String title, String msgContent, String contentType,
41
41
this .jsonExtras = jsonExtras ;
42
42
this .customData = customData ;
43
43
}
44
-
44
+
45
45
public static Builder newBuilder () {
46
46
return new Builder ();
47
47
}
48
-
48
+
49
49
public static Message content (String msgContent ) {
50
50
return new Builder ().setMsgContent (msgContent ).build ();
51
51
}
52
-
52
+
53
53
@ Override
54
54
public JsonElement toJSON () {
55
55
JsonObject json = new JsonObject ();
@@ -62,12 +62,12 @@ public JsonElement toJSON() {
62
62
if (null != contentType ) {
63
63
json .add (CONTENT_TYPE , new JsonPrimitive (contentType ));
64
64
}
65
-
65
+
66
66
JsonObject extrasObject = null ;
67
- if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras ){
67
+ if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras ) {
68
68
extrasObject = new JsonObject ();
69
69
}
70
-
70
+
71
71
if (null != extras ) {
72
72
for (String key : extras .keySet ()) {
73
73
if (extras .get (key ) != null ) {
@@ -93,7 +93,7 @@ public JsonElement toJSON() {
93
93
}
94
94
}
95
95
96
- if (null != extras || null != numberExtras || null != booleanExtras ) {
96
+ if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras ) {
97
97
json .add (EXTRAS , extrasObject );
98
98
}
99
99
@@ -102,7 +102,7 @@ public JsonElement toJSON() {
102
102
json .add (entry .getKey (), entry .getValue ());
103
103
}
104
104
}
105
-
105
+
106
106
return json ;
107
107
}
108
108
@@ -115,33 +115,33 @@ public static class Builder {
115
115
private Map <String , Boolean > booleanExtrasBuilder ;
116
116
protected Map <String , JsonObject > jsonExtrasBuilder ;
117
117
private Map <String , JsonPrimitive > customData ;
118
-
118
+
119
119
public Builder setTitle (String title ) {
120
120
this .title = title ;
121
121
return this ;
122
122
}
123
-
123
+
124
124
public Builder setMsgContent (String msgContent ) {
125
125
this .msgContent = msgContent ;
126
126
return this ;
127
127
}
128
-
128
+
129
129
public Builder setContentType (String contentType ) {
130
130
this .contentType = contentType ;
131
131
return this ;
132
132
}
133
-
133
+
134
134
public Builder addExtra (String key , String value ) {
135
- Preconditions .checkArgument (! (null == key || null == value ), "Key/Value should not be null." );
135
+ Preconditions .checkArgument (!(null == key || null == value ), "Key/Value should not be null." );
136
136
if (null == extrasBuilder ) {
137
137
extrasBuilder = new HashMap <String , String >();
138
138
}
139
139
extrasBuilder .put (key , value );
140
140
return this ;
141
141
}
142
-
142
+
143
143
public Builder addExtras (Map <String , String > extras ) {
144
- Preconditions .checkArgument (! (null == extras ), "extras should not be null." );
144
+ Preconditions .checkArgument (!(null == extras ), "extras should not be null." );
145
145
if (null == extrasBuilder ) {
146
146
extrasBuilder = new HashMap <String , String >();
147
147
}
@@ -150,29 +150,29 @@ public Builder addExtras(Map<String, String> extras) {
150
150
}
151
151
return this ;
152
152
}
153
-
153
+
154
154
public Builder addExtra (String key , Number value ) {
155
- Preconditions .checkArgument (! (null == key || null == value ), "Key/Value should not be null." );
155
+ Preconditions .checkArgument (!(null == key || null == value ), "Key/Value should not be null." );
156
156
if (null == numberExtrasBuilder ) {
157
157
numberExtrasBuilder = new HashMap <String , Number >();
158
158
}
159
159
numberExtrasBuilder .put (key , value );
160
160
return this ;
161
161
}
162
-
162
+
163
163
public Builder addExtra (String key , Boolean value ) {
164
- Preconditions .checkArgument (! (null == key || null == value ), "Key/Value should not be null." );
164
+ Preconditions .checkArgument (!(null == key || null == value ), "Key/Value should not be null." );
165
165
if (null == booleanExtrasBuilder ) {
166
166
booleanExtrasBuilder = new HashMap <String , Boolean >();
167
167
}
168
168
booleanExtrasBuilder .put (key , value );
169
169
return this ;
170
170
}
171
-
171
+
172
172
public Builder addExtra (String key , JsonObject value ) {
173
- Preconditions .checkArgument (! (null == key || null == value ), "Key/Value should not be null." );
173
+ Preconditions .checkArgument (!(null == key || null == value ), "Key/Value should not be null." );
174
174
if (null == jsonExtrasBuilder ) {
175
- jsonExtrasBuilder = new HashMap <String , JsonObject >();
175
+ jsonExtrasBuilder = new HashMap <String , JsonObject >();
176
176
}
177
177
jsonExtrasBuilder .put (key , value );
178
178
return this ;
@@ -189,7 +189,7 @@ public Builder addCustom(Map<String, String> extras) {
189
189
}
190
190
191
191
public Builder addCustom (String key , Number value ) {
192
- Preconditions .checkArgument (! (null == key ), "Key should not be null." );
192
+ Preconditions .checkArgument (!(null == key ), "Key should not be null." );
193
193
if (customData == null ) {
194
194
customData = new LinkedHashMap <>();
195
195
}
@@ -198,7 +198,7 @@ public Builder addCustom(String key, Number value) {
198
198
}
199
199
200
200
public Builder addCustom (String key , String value ) {
201
- Preconditions .checkArgument (! (null == key ), "Key should not be null." );
201
+ Preconditions .checkArgument (!(null == key ), "Key should not be null." );
202
202
if (customData == null ) {
203
203
customData = new LinkedHashMap <>();
204
204
}
@@ -207,19 +207,19 @@ public Builder addCustom(String key, String value) {
207
207
}
208
208
209
209
public Builder addCustom (String key , Boolean value ) {
210
- Preconditions .checkArgument (! (null == key ), "Key should not be null." );
210
+ Preconditions .checkArgument (!(null == key ), "Key should not be null." );
211
211
if (customData == null ) {
212
212
customData = new LinkedHashMap <>();
213
213
}
214
214
customData .put (key , new JsonPrimitive (value ));
215
215
return this ;
216
216
}
217
-
217
+
218
218
public Message build () {
219
- Preconditions .checkArgument (! (null == msgContent ),
219
+ Preconditions .checkArgument (!(null == msgContent ),
220
220
"msgContent should be set" );
221
- return new Message (title , msgContent , contentType ,
222
- extrasBuilder , numberExtrasBuilder , booleanExtrasBuilder ,jsonExtrasBuilder , customData );
221
+ return new Message (title , msgContent , contentType ,
222
+ extrasBuilder , numberExtrasBuilder , booleanExtrasBuilder , jsonExtrasBuilder , customData );
223
223
}
224
224
}
225
225
}
0 commit comments