aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/DeviceManager.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-09-07 15:31:28 +0500
committerAbyss777 <abyss@fox5.ru>2017-09-07 15:35:48 +0500
commitee28d68243892623df7f718d50cd3ea5791f35ee (patch)
treea3c474d75b2393149bd89a2a9b9580444ba00a61 /src/org/traccar/database/DeviceManager.java
parent9ebd2a934a5ca3a61863f839733bff321ba30296 (diff)
downloadtrackermap-server-ee28d68243892623df7f718d50cd3ea5791f35ee.tar.gz
trackermap-server-ee28d68243892623df7f718d50cd3ea5791f35ee.tar.bz2
trackermap-server-ee28d68243892623df7f718d50cd3ea5791f35ee.zip
Optimize values parsing
Diffstat (limited to 'src/org/traccar/database/DeviceManager.java')
-rw-r--r--src/org/traccar/database/DeviceManager.java22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 9bc221aa3..2157e738d 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -263,30 +263,42 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
public boolean lookupAttributeBoolean(
long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig) {
Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- return result != null ? Boolean.parseBoolean(result.toString()) : defaultValue;
+ if (result != null) {
+ return result instanceof String ? Boolean.parseBoolean((String) result) : (Boolean) result;
+ }
+ return defaultValue;
}
public String lookupAttributeString(
long deviceId, String attributeName, String defaultValue, boolean lookupConfig) {
Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- return result != null ? result.toString() : defaultValue;
+ return result != null ? (String) result : defaultValue;
}
public int lookupAttributeInteger(long deviceId, String attributeName, int defaultValue, boolean lookupConfig) {
Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- return result != null ? Integer.parseInt(result.toString()) : defaultValue;
+ if (result != null) {
+ return result instanceof String ? Integer.parseInt((String) result) : ((Number) result).intValue();
+ }
+ return defaultValue;
}
public long lookupAttributeLong(
long deviceId, String attributeName, long defaultValue, boolean lookupConfig) {
Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- return result != null ? Long.parseLong(result.toString()) : defaultValue;
+ if (result != null) {
+ return result instanceof String ? Long.parseLong((String) result) : ((Number) result).longValue();
+ }
+ return defaultValue;
}
public double lookupAttributeDouble(
long deviceId, String attributeName, double defaultValue, boolean lookupConfig) {
Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- return result != null ? Double.parseDouble(result.toString()) : defaultValue;
+ if (result != null) {
+ return result instanceof String ? Double.parseDouble((String) result) : ((Number) result).doubleValue();
+ }
+ return defaultValue;
}
private Object lookupAttribute(long deviceId, String attributeName, boolean lookupConfig) {