public static Map<BotLevel, Integer> deserializeBots(JSONObject botsArray) { if (botsArray == null) return null; Map<BotLevel, Integer> bots = new HashMap<BotLevel, Integer>(); for (BotLevel l : BotLevel.values()) { if (botsArray.has(l.name())) bots.put(l, botsArray.getInt(l.name())); } return bots; }
public static JSONObject serializeBots(Map<BotLevel, Integer> bots) { if (bots == null) return null; JSONObject botArray = new JSONObject(); for (BotLevel l : BotLevel.values()) { Integer n = bots.get(l); if (n != null && n != 0) botArray.put(l.name(), n.intValue()); } return botArray; }