Skip to content

Commit 7f622da

Browse files
committed
Use empty collections in updates instead of nulls
1 parent 86f6938 commit 7f622da

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

common/src/main/java/ru/croccode/hypernull/message/Messages.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,35 +277,28 @@ public static List<String> formatUpdate(Update message) {
277277
public static Update parseUpdate(List<String> lines) {
278278
checkMessage(lines, "update");
279279
Update message = new Update();
280+
message.setBots(new HashMap<>());
281+
message.setBotCoins(new HashMap<>());
282+
message.setBlocks(new HashSet<>());
283+
message.setCoins(new HashSet<>());
280284
parseParameters(lines, (name, values) -> {
281285
switch (name) {
282286
case "round":
283287
message.setRound(Integer.parseInt(values.get(0)));
284288
break;
285289
case "bot":
286-
if (message.getBots() == null)
287-
message.setBots(new HashMap<>());
288-
if (message.getBotCoins() == null)
289-
message.setBotCoins(new HashMap<>());
290-
291290
Integer botId = Integer.parseInt(values.get(3));
292291
message.getBots().put(botId, new Point(
293292
Integer.parseInt(values.get(0)),
294293
Integer.parseInt(values.get(1))));
295294
message.getBotCoins().put(botId, Integer.parseInt(values.get(2)));
296295
break;
297296
case "block":
298-
if (message.getBlocks() == null)
299-
message.setBlocks(new HashSet<>());
300-
301297
message.getBlocks().add(new Point(
302298
Integer.parseInt(values.get(0)),
303299
Integer.parseInt(values.get(1))));
304300
break;
305301
case "coin":
306-
if (message.getCoins() == null)
307-
message.setCoins(new HashSet<>());
308-
309302
message.getCoins().add(new Point(
310303
Integer.parseInt(values.get(0)),
311304
Integer.parseInt(values.get(1))));

0 commit comments

Comments
 (0)