diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2012-07-08 09:42:07 +0400 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2012-07-08 09:42:07 +0400 |
commit | 4f1481208d60db88be5390f0584dc5e33fd83571 (patch) | |
tree | aa1764074b3f111cd3cf80447c167da2edae6053 /src/org | |
parent | a5dff88bb3ec84224240f6a40965234b58e9ad85 (diff) | |
download | traccar-server-4f1481208d60db88be5390f0584dc5e33fd83571.tar.gz traccar-server-4f1481208d60db88be5390f0584dc5e33fd83571.tar.bz2 traccar-server-4f1481208d60db88be5390f0584dc5e33fd83571.zip |
Use generics
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/Server.java | 4 | ||||
-rw-r--r-- | src/org/traccar/helper/NamedParameterStatement.java | 61 | ||||
-rw-r--r-- | src/org/traccar/model/DatabaseDataManager.java | 10 |
3 files changed, 37 insertions, 38 deletions
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<TrackerServer> serverList; private boolean loggerEnabled; public Server() { - serverList = new LinkedList(); + serverList = new LinkedList<TrackerServer>(); 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<String, List<Integer>> indexMap; /** * Query string @@ -46,7 +46,7 @@ public class NamedParameterStatement { */ public NamedParameterStatement(AdvancedConnection connection, String query) { - indexMap = new HashMap(); + indexMap = new HashMap<String, List<Integer>>(); 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<String, List<Integer>> 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<Integer> indexList = paramMap.get(name); if (indexList == null) { - indexList = new LinkedList(); + indexList = new LinkedList<Integer>(); 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<Integer> 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<Integer> 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<Integer> 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<Integer> 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<Integer> 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<Integer> 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<Device> getDevices() throws SQLException { - List<Device> deviceList = new LinkedList(); + List<Device> deviceList = new LinkedList<Device>(); queryGetDevices.prepare(); ResultSet result = queryGetDevices.executeQuery(); @@ -165,21 +165,21 @@ public class DatabaseDataManager implements DataManager { /** * Devices cache */ - private Map devices; + private Map<String, Device> 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<String, Device>(); 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<Position> getPositions(Long deviceId) throws SQLException { - List<Position> positionList = new LinkedList(); + List<Position> positionList = new LinkedList<Position>(); queryGetPositions.prepare(); queryGetPositions.setLong("device_id", deviceId); |