@Override public void writeToOutput(DataOutput out) throws IOException { out.writeInt(this.tickId); out.writeInt(this.time); this.newPosition.writeToOutput(out); out.writeShort(this.records.length); for (LocationRecord record : this.records) { record.writeToOutput(out); } }
@Override public void parseFromInput(DataInput in) throws IOException { this.tickId = in.readInt(); this.time = in.readInt(); this.newPosition.parseFromInput(in); this.records = new LocationRecord[in.readShort()]; for (int i = 0; i < this.records.length; i++) { LocationRecord record = new LocationRecord(); record.parseFromInput(in); this.records[i] = record; } }
public AdjacentLocList getListFromDB(Connection conn) throws SQLException { AdjacentLocList list = new AdjacentLocList(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery( "SELECT IMSI,SiteId, Longitude,Latitude,ConnectTime FROM FilteredByCT_Data2" + " ORDER BY IMSI ASC, ConnectTime ASC"); rs.next(); LocationRecord record = new LocationRecord(rs); LocationRecord nextRecord; HashMap<AdjacentLocPair, int[]> pairs = new HashMap<AdjacentLocPair, int[]>(); long count = 0; while (rs.next()) { if (count % 1000000 == 0) { System.out.println(count); } count++; nextRecord = new LocationRecord(rs); if (nextRecord.getSiteId() == record.getSiteId()) continue; if (!nextRecord.getImsi().equals(record.getImsi())) { record = nextRecord; storePairs(pairs); pairs = new HashMap<AdjacentLocPair, int[]>(); continue; } Site site1 = list.getSite(record.getSiteId()); if (site1 == null) { site1 = list.addSite(record.getSiteId(), record.getLongitude(), record.getLatitude()); } Site site2 = list.getSite(nextRecord.getSiteId()); if (site2 == null) { site2 = list.addSite( nextRecord.getSiteId(), nextRecord.getLongitude(), nextRecord.getLatitude()); } int hour = record.getHour(); AdjacentLocPair pair = list.getAdjacentLocPair(site1, site2); if (!pairs.containsKey(pair)) { int[] arr = new int[24]; arr[hour] = 1; pairs.put(pair, arr); } else { pairs.get(pair)[hour] += 1; } record = nextRecord; } storePairs(pairs); return list; }