Skip to content

Commit d22da43

Browse files
committed
Revert "Use empty collections in updates instead of nulls"
This reverts commit 7f622da
1 parent af9347a commit d22da43

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,28 +277,35 @@ 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<>());
284280
parseParameters(lines, (name, values) -> {
285281
switch (name) {
286282
case "round":
287283
message.setRound(Integer.parseInt(values.get(0)));
288284
break;
289285
case "bot":
286+
if (message.getBots() == null)
287+
message.setBots(new HashMap<>());
288+
if (message.getBotCoins() == null)
289+
message.setBotCoins(new HashMap<>());
290+
290291
Integer botId = Integer.parseInt(values.get(3));
291292
message.getBots().put(botId, new Point(
292293
Integer.parseInt(values.get(0)),
293294
Integer.parseInt(values.get(1))));
294295
message.getBotCoins().put(botId, Integer.parseInt(values.get(2)));
295296
break;
296297
case "block":
298+
if (message.getBlocks() == null)
299+
message.setBlocks(new HashSet<>());
300+
297301
message.getBlocks().add(new Point(
298302
Integer.parseInt(values.get(0)),
299303
Integer.parseInt(values.get(1))));
300304
break;
301305
case "coin":
306+
if (message.getCoins() == null)
307+
message.setCoins(new HashSet<>());
308+
302309
message.getCoins().add(new Point(
303310
Integer.parseInt(values.get(0)),
304311
Integer.parseInt(values.get(1))));

0 commit comments

Comments
 (0)