From d22da438032cea77a9e24d47f005e2bd9fe52887 Mon Sep 17 00:00:00 2001 From: Evgeny Pisarenko Date: Wed, 15 Dec 2021 21:21:05 +0300 Subject: [PATCH] Revert "Use empty collections in updates instead of nulls" This reverts commit 7f622daf --- .../ru/croccode/hypernull/message/Messages.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/ru/croccode/hypernull/message/Messages.java b/common/src/main/java/ru/croccode/hypernull/message/Messages.java index 58b6806..e489fa9 100644 --- a/common/src/main/java/ru/croccode/hypernull/message/Messages.java +++ b/common/src/main/java/ru/croccode/hypernull/message/Messages.java @@ -277,16 +277,17 @@ public static List formatUpdate(Update message) { public static Update parseUpdate(List lines) { checkMessage(lines, "update"); Update message = new Update(); - message.setBots(new HashMap<>()); - message.setBotCoins(new HashMap<>()); - message.setBlocks(new HashSet<>()); - message.setCoins(new HashSet<>()); parseParameters(lines, (name, values) -> { switch (name) { case "round": message.setRound(Integer.parseInt(values.get(0))); break; case "bot": + if (message.getBots() == null) + message.setBots(new HashMap<>()); + if (message.getBotCoins() == null) + message.setBotCoins(new HashMap<>()); + Integer botId = Integer.parseInt(values.get(3)); message.getBots().put(botId, new Point( Integer.parseInt(values.get(0)), @@ -294,11 +295,17 @@ public static Update parseUpdate(List lines) { message.getBotCoins().put(botId, Integer.parseInt(values.get(2))); break; case "block": + if (message.getBlocks() == null) + message.setBlocks(new HashSet<>()); + message.getBlocks().add(new Point( Integer.parseInt(values.get(0)), Integer.parseInt(values.get(1)))); break; case "coin": + if (message.getCoins() == null) + message.setCoins(new HashSet<>()); + message.getCoins().add(new Point( Integer.parseInt(values.get(0)), Integer.parseInt(values.get(1))));