From c0316e4a968ea73002954118cafdd958f354370f Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Mon, 7 Jan 2019 22:24:53 +0200 Subject: added getInteger that can return null --- src/org/traccar/MainEventHandler.java | 2 +- src/org/traccar/model/ExtendedModel.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 3a8e36146..a3bbb8fd6 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -77,7 +77,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { if (!position.getValid()) { s.append(", invalid"); } - Object batteryLevel = position.getInteger(Position.KEY_BATTERY_LEVEL); + Object batteryLevel = position.getInteger(Position.KEY_BATTERY_LEVEL, null); if (batteryLevel != null) { s.append(", battery: ").append(batteryLevel).append('%'); } diff --git a/src/org/traccar/model/ExtendedModel.java b/src/org/traccar/model/ExtendedModel.java index 8353d0e66..8271e41cc 100644 --- a/src/org/traccar/model/ExtendedModel.java +++ b/src/org/traccar/model/ExtendedModel.java @@ -108,14 +108,18 @@ public class ExtendedModel extends BaseModel { } } - public int getInteger(String key) { + public Integer getInteger(String key, Integer defaultValue) { if (attributes.containsKey(key)) { return ((Number) attributes.get(key)).intValue(); } else { - return 0; + return defaultValue; } } + public int getInteger(String key) { + return getInteger(key, 0); + } + public long getLong(String key) { if (attributes.containsKey(key)) { return ((Number) attributes.get(key)).longValue(); -- cgit v1.2.3