1111
1212import cn .jiguang .common .utils .Preconditions ;
1313
14- public class Message implements PushModel {
14+ public class Message implements PushModel {
1515 private static final String TITLE = "title" ;
1616 private static final String MSG_CONTENT = "msg_content" ;
1717 private static final String CONTENT_TYPE = "content_type" ;
1818 private static final String EXTRAS = "extras" ;
19-
19+
2020 private final String title ;
2121 private final String msgContent ;
2222 private final String contentType ;
@@ -26,12 +26,12 @@ public class Message implements PushModel {
2626 private final Map <String , JsonObject > jsonExtras ;
2727 private final Map <String , JsonPrimitive > customData ;
2828
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 ) {
3535 this .title = title ;
3636 this .msgContent = msgContent ;
3737 this .contentType = contentType ;
@@ -41,15 +41,15 @@ private Message(String title, String msgContent, String contentType,
4141 this .jsonExtras = jsonExtras ;
4242 this .customData = customData ;
4343 }
44-
44+
4545 public static Builder newBuilder () {
4646 return new Builder ();
4747 }
48-
48+
4949 public static Message content (String msgContent ) {
5050 return new Builder ().setMsgContent (msgContent ).build ();
5151 }
52-
52+
5353 @ Override
5454 public JsonElement toJSON () {
5555 JsonObject json = new JsonObject ();
@@ -62,12 +62,12 @@ public JsonElement toJSON() {
6262 if (null != contentType ) {
6363 json .add (CONTENT_TYPE , new JsonPrimitive (contentType ));
6464 }
65-
65+
6666 JsonObject extrasObject = null ;
67- if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras ){
67+ if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras ) {
6868 extrasObject = new JsonObject ();
6969 }
70-
70+
7171 if (null != extras ) {
7272 for (String key : extras .keySet ()) {
7373 if (extras .get (key ) != null ) {
@@ -93,7 +93,7 @@ public JsonElement toJSON() {
9393 }
9494 }
9595
96- if (null != extras || null != numberExtras || null != booleanExtras ) {
96+ if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras ) {
9797 json .add (EXTRAS , extrasObject );
9898 }
9999
@@ -102,7 +102,7 @@ public JsonElement toJSON() {
102102 json .add (entry .getKey (), entry .getValue ());
103103 }
104104 }
105-
105+
106106 return json ;
107107 }
108108
@@ -115,33 +115,33 @@ public static class Builder {
115115 private Map <String , Boolean > booleanExtrasBuilder ;
116116 protected Map <String , JsonObject > jsonExtrasBuilder ;
117117 private Map <String , JsonPrimitive > customData ;
118-
118+
119119 public Builder setTitle (String title ) {
120120 this .title = title ;
121121 return this ;
122122 }
123-
123+
124124 public Builder setMsgContent (String msgContent ) {
125125 this .msgContent = msgContent ;
126126 return this ;
127127 }
128-
128+
129129 public Builder setContentType (String contentType ) {
130130 this .contentType = contentType ;
131131 return this ;
132132 }
133-
133+
134134 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." );
136136 if (null == extrasBuilder ) {
137137 extrasBuilder = new HashMap <String , String >();
138138 }
139139 extrasBuilder .put (key , value );
140140 return this ;
141141 }
142-
142+
143143 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." );
145145 if (null == extrasBuilder ) {
146146 extrasBuilder = new HashMap <String , String >();
147147 }
@@ -150,29 +150,29 @@ public Builder addExtras(Map<String, String> extras) {
150150 }
151151 return this ;
152152 }
153-
153+
154154 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." );
156156 if (null == numberExtrasBuilder ) {
157157 numberExtrasBuilder = new HashMap <String , Number >();
158158 }
159159 numberExtrasBuilder .put (key , value );
160160 return this ;
161161 }
162-
162+
163163 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." );
165165 if (null == booleanExtrasBuilder ) {
166166 booleanExtrasBuilder = new HashMap <String , Boolean >();
167167 }
168168 booleanExtrasBuilder .put (key , value );
169169 return this ;
170170 }
171-
171+
172172 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." );
174174 if (null == jsonExtrasBuilder ) {
175- jsonExtrasBuilder = new HashMap <String , JsonObject >();
175+ jsonExtrasBuilder = new HashMap <String , JsonObject >();
176176 }
177177 jsonExtrasBuilder .put (key , value );
178178 return this ;
@@ -189,7 +189,7 @@ public Builder addCustom(Map<String, String> extras) {
189189 }
190190
191191 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." );
193193 if (customData == null ) {
194194 customData = new LinkedHashMap <>();
195195 }
@@ -198,7 +198,7 @@ public Builder addCustom(String key, Number value) {
198198 }
199199
200200 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." );
202202 if (customData == null ) {
203203 customData = new LinkedHashMap <>();
204204 }
@@ -207,19 +207,19 @@ public Builder addCustom(String key, String value) {
207207 }
208208
209209 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." );
211211 if (customData == null ) {
212212 customData = new LinkedHashMap <>();
213213 }
214214 customData .put (key , new JsonPrimitive (value ));
215215 return this ;
216216 }
217-
217+
218218 public Message build () {
219- Preconditions .checkArgument (! (null == msgContent ),
219+ Preconditions .checkArgument (!(null == msgContent ),
220220 "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 );
223223 }
224224 }
225225}
0 commit comments