Simple Parallel & smart sequential commit before refresh.

package Homework6;

/**
* Grant Hughes & Amrita Mohan
* CSE 332 14AU
*/
import java.util.*;

/**
* Simple and Sequential implementation of computing population size of
all the
* census groups within a given range.
*
* @author Amrita
*
*/
public class SimpleSequential extends QueryCalculator {
private Rectangle query;

public SimpleSequential(CensusData input, Pair<Integer, Integer> xy) {
super(input, xy);
query = new Rectangle(0, 0, 0, 0);
}

// Find four corners of the U.S. rectangle
@Override
public void preprocess() {
findCorners();
}

//Helper method to find corners of US area in terms of lat/long.
@Override
protected void findCorners() {
// find min/max longitude&latitude
for (int i = 0; i < input.data_size; i++) {
corners.left = Math.min(input.data[i].longitude, corners.left); //
minLat
corners.bottom = Math.min(input.data[i].latitude, corners.bottom); //
minLong
corners.right = Math.max(input.data[i].longitude, corners.right); //
maxLat
corners.top = Math.max(input.data[i].latitude, corners.top); // maxlong
}
}

// Determine total population size within query rectangle
@Override
public void queryCompute(int w, int s, int e, int n) {
float cellWidth = Math.abs(corners.right - corners.left) / x;
float cellLength = Math.abs(corners.top - corners.bottom) / y;

query.left = corners.left + cellWidth * (w - 1);
query.right = corners.left + cellWidth * (e);

query.bottom = corners.bottom + cellLength * (s - 1);
query.top = corners.bottom + cellLength * (n);

System.out.println("Query:   " + query.toString());
System.out.println("Corners: " + corners.toString());
System.out.println("CW " + cellWidth + " CL "+cellLength);

queryHelper();
}

// Helper method to do actually computation on given query rectangle.
private void queryHelper() {

int population = 0;
int totalPop = 0;

for (int i = 0; i < input.data_size; i++) {
// compute position in grid and determine whether in query rectangle
CensusGroup curr = input.data[i];
if (((curr.longitude >= query.left) && (curr.longitude <= query.right))
&& ((curr.latitude >= query.bottom) && (curr.latitude <= query.top))) {
population += curr.population;
}
totalPop += curr.population;
}

// print out results
System.out.println("population of rectangle: " + population);
System.out.printf("percent of total population: %.2f",
((population * 100.00 / totalPop)));
System.out.println();
}
}