From 4f1481208d60db88be5390f0584dc5e33fd83571 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 8 Jul 2012 09:42:07 +0400 Subject: Use generics --- src/org/traccar/Server.java | 4 +- .../traccar/helper/NamedParameterStatement.java | 61 +++++++++++----------- src/org/traccar/model/DatabaseDataManager.java | 10 ++-- 3 files changed, 37 insertions(+), 38 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 7167f6080..5a6b298c7 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -50,12 +50,12 @@ public class Server { /** * Server list */ - private List serverList; + private List serverList; private boolean loggerEnabled; public Server() { - serverList = new LinkedList(); + serverList = new LinkedList(); loggerEnabled = false; } diff --git a/src/org/traccar/helper/NamedParameterStatement.java b/src/org/traccar/helper/NamedParameterStatement.java index e898af2d3..a4b1a12c6 100644 --- a/src/org/traccar/helper/NamedParameterStatement.java +++ b/src/org/traccar/helper/NamedParameterStatement.java @@ -29,7 +29,7 @@ public class NamedParameterStatement { /** * Index mapping */ - private final Map indexMap; + private final Map> indexMap; /** * Query string @@ -46,7 +46,7 @@ public class NamedParameterStatement { */ public NamedParameterStatement(AdvancedConnection connection, String query) { - indexMap = new HashMap(); + indexMap = new HashMap>(); parsedQuery = parse(query, indexMap); this.connection = connection; } @@ -54,7 +54,7 @@ public class NamedParameterStatement { /** * Parse query */ - static String parse(String query, Map paramMap) { + static String parse(String query, Map> paramMap) { int length = query.length(); StringBuilder parsedQuery = new StringBuilder(length); @@ -90,12 +90,12 @@ public class NamedParameterStatement { i += name.length(); // Add to list - List indexList = (List) paramMap.get(name); + List indexList = paramMap.get(name); if (indexList == null) { - indexList = new LinkedList(); + indexList = new LinkedList(); paramMap.put(name, indexList); } - indexList.add(new Integer(index)); + indexList.add(index); index++; } @@ -149,73 +149,72 @@ public class NamedParameterStatement { public void setInt(String name, Integer value) throws SQLException { - List indexList = (List) indexMap.get(name); - if (indexList != null) for (Object index: indexList) { + List indexList = indexMap.get(name); + if (indexList != null) for (Integer index: indexList) { if (value != null) { - statement.setInt((Integer) index, value); + statement.setInt(index, value); } else { - statement.setNull((Integer) index, Types.INTEGER); + statement.setNull(index, Types.INTEGER); } } } public void setLong(String name, Long value) throws SQLException { - List indexList = (List) indexMap.get(name); - if (indexList != null) for (Object index: indexList) { + List indexList = indexMap.get(name); + if (indexList != null) for (Integer index: indexList) { if (value != null) { - statement.setLong((Integer) index, value); + statement.setLong(index, value); } else { - statement.setNull((Integer) index, Types.INTEGER); + statement.setNull(index, Types.INTEGER); } } } public void setBoolean(String name, Boolean value) throws SQLException { - List indexList = (List) indexMap.get(name); - if (indexList != null) for (Object index: indexList) { + List indexList = indexMap.get(name); + if (indexList != null) for (Integer index: indexList) { if (value != null) { - statement.setBoolean((Integer) index, value); + statement.setBoolean(index, value); } else { - statement.setNull((Integer) index, Types.BOOLEAN); + statement.setNull(index, Types.BOOLEAN); } } } public void setDouble(String name, Double value) throws SQLException { - List indexList = (List) indexMap.get(name); - if (indexList != null) for (Object index: indexList) { + List indexList = indexMap.get(name); + if (indexList != null) for (Integer index: indexList) { if (value != null) { - statement.setDouble((Integer) index, value); + statement.setDouble(index, value); } else { - statement.setNull((Integer) index, Types.DOUBLE); + statement.setNull(index, Types.DOUBLE); } } } public void setTimestamp(String name, Date value) throws SQLException { - List indexList = (List) indexMap.get(name); - if (indexList != null) for (Object index: indexList) { + List indexList = indexMap.get(name); + if (indexList != null) for (Integer index: indexList) { if (value != null) { - statement.setTimestamp( - (Integer) index, new Timestamp(value.getTime())); + statement.setTimestamp(index, new Timestamp(value.getTime())); } else { - statement.setNull((Integer) index, Types.TIMESTAMP); + statement.setNull(index, Types.TIMESTAMP); } } } public void setString(String name, String value) throws SQLException { - List indexList = (List) indexMap.get(name); - if (indexList != null) for (Object index: indexList) { + List indexList = indexMap.get(name); + if (indexList != null) for (Integer index: indexList) { if (value != null) { - statement.setString((Integer) index, value); + statement.setString(index, value); } else { - statement.setNull((Integer) index, Types.VARCHAR); + statement.setNull(index, Types.VARCHAR); } } } diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java index f312c3dcd..384d87828 100644 --- a/src/org/traccar/model/DatabaseDataManager.java +++ b/src/org/traccar/model/DatabaseDataManager.java @@ -114,7 +114,7 @@ public class DatabaseDataManager implements DataManager { public synchronized List getDevices() throws SQLException { - List deviceList = new LinkedList(); + List deviceList = new LinkedList(); queryGetDevices.prepare(); ResultSet result = queryGetDevices.executeQuery(); @@ -165,21 +165,21 @@ public class DatabaseDataManager implements DataManager { /** * Devices cache */ - private Map devices; + private Map devices; private Calendar devicesLastUpdate; private Long devicesRefreshDelay; public Device getDeviceByImei(String imei) throws SQLException { if ((devices == null) || (Calendar.getInstance().getTimeInMillis() - devicesLastUpdate.getTimeInMillis() > devicesRefreshDelay)) { - devices = new HashMap(); + devices = new HashMap(); for (Device device: getDevices()) { devices.put(device.getImei(), device); } devicesLastUpdate = Calendar.getInstance(); } - return (Device) devices.get(imei); + return devices.get(imei); } public Device getDeviceByPhoneNumber(String phoneNumber) { @@ -194,7 +194,7 @@ public class DatabaseDataManager implements DataManager { public synchronized List getPositions(Long deviceId) throws SQLException { - List positionList = new LinkedList(); + List positionList = new LinkedList(); queryGetPositions.prepare(); queryGetPositions.setLong("device_id", deviceId); -- cgit v1.2.3