From e89bbb8ee9dd1dd1f19fb33f1f9291c6ae5f43db Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 23 Nov 2016 17:34:25 +0500 Subject: Implement attributes helpers --- src/org/traccar/model/Extensible.java | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/org/traccar/model') diff --git a/src/org/traccar/model/Extensible.java b/src/org/traccar/model/Extensible.java index efe60fb75..b8c83bb21 100644 --- a/src/org/traccar/model/Extensible.java +++ b/src/org/traccar/model/Extensible.java @@ -68,4 +68,44 @@ public class Extensible { } } + public String getString(String key) { + if (attributes.containsKey(key)) { + return (String) attributes.get(key); + } else { + return null; + } + } + + public double getDouble(String key) { + if (attributes.containsKey(key)) { + return ((Number) attributes.get(key)).doubleValue(); + } else { + return 0.0; + } + } + + public boolean getBoolean(String key) { + if (attributes.containsKey(key)) { + return Boolean.parseBoolean(attributes.get(key).toString()); + } else { + return false; + } + } + + public int getInteger(String key) { + if (attributes.containsKey(key)) { + return ((Number) attributes.get(key)).intValue(); + } else { + return 0; + } + } + + public long getLong(String key) { + if (attributes.containsKey(key)) { + return ((Number) attributes.get(key)).longValue(); + } else { + return 0; + } + } + } -- cgit v1.2.3