distanceMap = initDistanceMap(new ConcurrentHashMap<Double, TableEntry>(3600));
Thread coverageCalculatorThread = new Thread(new Runnable() {
public void run() {
List<Double> tmpList;
Position pos;
while (true) {
try {
coveragePerimeter = new ArrayList<Position>(3600);
coveragePerimeter.add(location);
calculateCoveragePerimiter();
tmpList = new ArrayList<Double>(3600);
// Add any non-null positions to the geo-position list so
// that they can later form the points for the coverage polygon
for (Double key : distanceMap.keySet()) {
if (distanceMap.get(key).getPosition() != null) {
tmpList.add(key);
}
}
// Sort the positions according to their appearance from 0 to 360 degrees
Collections.sort(tmpList);
for (Double key : tmpList) {
pos = new Position(distanceMap.get(key).getPosition().getLatitude(),
distanceMap.get(key).getPosition().getLongitude());
coveragePerimeter.add(pos);
}
pos = new Position(getLocation().getLatitude(),
getLocation().getLongitude());
coveragePerimeter.add(pos);
// Sleep two seconds
pos = null;