package org.greenstone.atlas.server;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.greenstone.atlas.client.Place;

public class ServerSideTests
{
	String _currentLine = null;
	ArrayList<String> _words = new ArrayList<String>();

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// GazetteerTrie trie = new
		// GazetteerTrie("/home/sam/Desktop/Research/Greenstone3-gate-svn2/web/GPNMS/dataen.txt");
		// PlacesToPoints();

		ServerSideTests sst = new ServerSideTests();
		sst.go();
	}

	public void go()
	{
		DatabaseFix();
		//PlacesToPoints();
		// ExperimentSetUp();
		//PrecisionExperiment();
		//GazetteerExperiment();
		//GazetteerTest();
		//ModPlaceNames();
		//analyseResults();
	}
	
	public void analyseResults()
	{
		try
		{
			BufferedReader in = new BufferedReader(new FileReader("/home/sjm84/Desktop/deleteMe.txt"));
			
			TreeMap<Double, ArrayList<Double[]>> scores = new TreeMap<Double, ArrayList<Double[]>>();
			
			Double[] currentConfig = null;
			
			String line = null;
			boolean score = false;
			while((line = in.readLine()) != null)
			{
				if(score)
				{
					String[] scanScores = line.split(" ");
					Double averageScore = Double.parseDouble(scanScores[5]);
					
					if(scores.containsKey(averageScore))
					{
						scores.get(averageScore).add(currentConfig);
					}
					else
					{
						ArrayList<Double[]> newList = new ArrayList<Double[]>();
						newList.add(currentConfig);
						scores.put(averageScore, newList);
					}
				}
				else
				{
					String[] configValues = line.split(" ");
					currentConfig = new Double[configValues.length];
					
					for(int i = 0; i < configValues.length; i++)
					{
						currentConfig[i] = Double.parseDouble(configValues[i]);
					}
				}
				
				score = !score;
			}
			
			BufferedWriter out = new BufferedWriter(new FileWriter("/home/sjm84/Desktop/SortedScores.txt"));
			
			for(Double d : scores.keySet())
			{
				out.write(d + " -> ");
				ArrayList<Double[]> current = scores.get(d);
				
				for(Double[] da : current)
				{
					for(int i = 0; i < da.length; i++)
					{
						out.write(da[i] + " ");
					}
					
					out.write(" - ");
				}
				out.write("\n");
			}
			
			in.close();
			out.close();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	public void ModPlaceNames()
	{
		try
		{
			BufferedReader in = new BufferedReader(new FileReader("/home/sjm84/Desktop/placenames.txt"));
			
			ArrayList<String> words = new ArrayList<String>();
			
			String line = null;
			while((line = in.readLine()) != null)
			{
				String[] w = line.split(" ");
				for(int i = 0; i < w.length; i++)
				{
					words.add(w[i]);
				}
			}
			
			BufferedWriter out = new BufferedWriter(new FileWriter("/home/sjm84/Desktop/placenames.txt"));
			
			for(int i = 0; i < words.size(); i++)
			{
				for(int j = 0; j < words.get(i).length(); j++)
				{
					if(words.get(i).charAt(j) > 127)
					{
						out.write(words.get(i) + "\n");
					}
				}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public void GazetteerExperiment()
	{
		showMemoryUsage();
	}
	
	public interface ObjectFactory
	{
		public Object makeObject();
	}

	public long calculateMemoryUsage()
	{
		ObjectFactory factory = new ObjectFactory()
		{
			public Object makeObject()
			{
				return new GazetteerTrieType5("/home/sam/Desktop/Research/Greenstone3-gate-svn2/web/GPNMS/dataen.txt");
			}
		};
		
		Object handle = factory.makeObject();
		long mem0 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
		long mem1 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
		handle = null;
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		mem0 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
		handle = factory.makeObject();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		System.gc();
		mem1 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
		return mem1 - mem0;
	}

	public void showMemoryUsage()
	{
		
		long mem = 0;
		for(int i = 0;i < 10; i++)
		{
			mem += calculateMemoryUsage();
		}
		System.out.println("Object takes " + (int)(mem/10) + " bytes");
	}

	public void ExperimentSetUp()
	{
		final JFrame frame = new JFrame("Experiment setup program");
		JList placeList = null;
		final ButtonGroup alts = new ButtonGroup();
		final ArrayList<JRadioButton> buttons = new ArrayList<JRadioButton>();
		final JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new GridLayout(30, 3));
		final HashMap<String, Place> choices = new HashMap<String, Place>();
		final ArrayList<Place> possibleChoices = new ArrayList<Place>();
		JButton enter = new JButton("GO");
		String filename = "/research/sjm84/Msc/GNSDocs/ireland.html";// "/home/sam/Desktop/Research/GNSDocs/canada.html";//

		try
		{
			PageScanner ps = new PageScanner("/research/sjm84/Msc/Downloads/");// new
			// PageScanner("/home/sam/Desktop/Research/");//

			BufferedReader file = new BufferedReader(new FileReader(filename));

			ArrayList<ArrayList<String>> lines = new ArrayList<ArrayList<String>>();
			String line = null;
			while ((line = file.readLine()) != null)
			{
				lines.add(MarkupService.findWords(line));
			}

			ps.examineTextWithoutGate(lines);
			final ArrayList<Place> filePlaces = ps.getPlaces();
			ArrayList<Place> seenPlaces = new ArrayList<Place>();
			for (Place p : filePlaces)
			{
				if (p.isDirectlyReferenced())
				{
					boolean found = false;
					for (int i = 0; i < seenPlaces.size(); i++)
					{
						if (p.getName().equals(seenPlaces.get(i).getName()))
						{
							found = true;
							break;
						}
					}
					if (!found)
					{
						seenPlaces.add(p);
					}
				}
			}

			String[] items = new String[seenPlaces.size()];
			for (int i = 0; i < seenPlaces.size(); i++)
			{
				items[i] = seenPlaces.get(i).getName();
				choices.put(seenPlaces.get(i).getName(), null);
			}

			placeList = new JList(items);

			placeList.addListSelectionListener(new ListSelectionListener()
			{
				int prevIndex = -1;

				public void valueChanged(ListSelectionEvent e)
				{
					ListModel model = ((JList) (e.getSource())).getModel();
					int index = ((JList) (e.getSource())).getSelectedIndex();
					final String s = (String) (model.getElementAt(index));
					if (index != prevIndex)
					{
						System.out.println("Value Changed!");
						for (JRadioButton button : buttons)
						{
							buttonPanel.remove(button);
							alts.remove(button);
						}

						buttons.clear();
						possibleChoices.clear();

						System.out.println("*Adding Button!");
						JRadioButton noneButton = new JRadioButton("*None*");
						alts.add(noneButton);
						buttons.add(noneButton);
						buttonPanel.add(noneButton);
						noneButton.addActionListener(new ActionListener()
						{
							public void actionPerformed(ActionEvent e)
							{
								choices.put(s, null);
							}
						});

						int count = 0;
						for (Place p : filePlaces)
						{
							if (p.getName().equals(s))
							{
								System.out.println("Adding Button!");
								possibleChoices.add(p);

								JRadioButton button = new JRadioButton(p.getName() + ", " + p.getParentPlaceName());
								alts.add(button);
								buttons.add(button);
								buttonPanel.add(button);
								button.addActionListener(new RadioActionListener(count++, possibleChoices, choices));
							}
						}

						buttonPanel.setSize(600, 150);
						buttonPanel.validate();
						frame.pack();
						frame.validate();
					}
					prevIndex = ((JList) (e.getSource())).getSelectedIndex();
				}
			});

			enter.addActionListener(new ButtonActionListener(choices));
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}

		JScrollPane sp = new JScrollPane(placeList);
		frame.setLayout(new BorderLayout());
		sp.setSize(600, 150);
		frame.add(sp, BorderLayout.WEST);
		buttonPanel.setSize(600, 150);
		frame.add(buttonPanel, BorderLayout.CENTER);
		enter.setSize(600, 100);
		frame.add(enter, BorderLayout.EAST);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(600, 400);
		frame.setVisible(true);
	}

	class RadioActionListener implements ActionListener
	{
		int _index = -1;
		ArrayList<Place> _possibleChoices = null;
		HashMap<String, Place> _choices = null;

		public RadioActionListener(int index, ArrayList<Place> possibleChoices, HashMap<String, Place> choices)
		{
			_index = index;
			_possibleChoices = possibleChoices;
			_choices = choices;
		}

		public void actionPerformed(ActionEvent e)
		{
			System.out.println("BUTTON CLICKED");
			_choices.put(_possibleChoices.get(_index).getName(), _possibleChoices.get(_index));
		}
	}

	class ButtonActionListener implements ActionListener
	{
		HashMap<String, Place> _choices = null;

		public ButtonActionListener(HashMap<String, Place> choices)
		{
			_choices = choices;
		}

		public void actionPerformed(ActionEvent e)
		{
			System.out.println("GO CLICKED");
			try
			{
				BufferedWriter out = new BufferedWriter(new FileWriter("/home/sjm84/Desktop/test.txt"));

				for (String s : _choices.keySet())
				{
					System.out.println(s + " == " + _choices.get(s));
					if (_choices.get(s) != null)
					{
						out.write("new Long(" + _choices.get(s).getId() + "), /* " + _choices.get(s).getName() + " */\n");
					}
				}
				out.close();
			}
			catch (Exception exception)
			{
				exception.printStackTrace();
			}
		}
	}

	public void PrecisionExperiment()
	{
		ArrayList<ScanConfiguration> configs = new ArrayList<ScanConfiguration>();
		HashMap<ScanConfiguration, ArrayList<int[]>> results = new HashMap<ScanConfiguration, ArrayList<int[]>>();

		for (int i = 0; i < 6; i++)
		{
			for (int j = 0; j < 6; j++)
			{
				for (int k = 0; k < 6; k++)
				{
					for(int l = 0; l < 6; l++)
					{		
						ScanConfiguration sc = new ScanConfiguration(0.2 * i, 0.2 * j, 0.2 * k, l);
						//ScanConfiguration sc = new ScanConfiguration(0, 0.8, 0.0, 1);
						configs.add(sc);
						results.put(sc, new ArrayList<int[]>());
						
						if(j == 0)
						{
							break;
						}
					}
				}
			}
		}

		try
		{
			PageScanner ps = new PageScanner("/research/sjm84/Msc/Downloads/");
			//PageScanner ps = new PageScanner("/home/sam/Desktop/Research/");

			String[] filenames = new String[] { "australia", "canada", "ireland", "southafrica", "washington" };
			for (int i = 0; i < filenames.length; i++)
			{
				BufferedReader file = new BufferedReader(new FileReader("/research/sjm84/Msc/GNSDocs/" + filenames[i] + ".html"));
				//BufferedReader file = new BufferedReader(new FileReader("/home/sam/Desktop/Research/GNSDocs/" + filenames[i] + ".html"));

				StringBuilder text = new StringBuilder();
				String line = null;
				while ((line = file.readLine()) != null)
				{
					text.append(line);
				}

				ScanResultSet correctResults = getCorrectScanResultSet(i);
				ArrayList<String> textPlaces = ps.getPlaceNames(text.toString());

				int count = 0;
				for (ScanConfiguration sc : configs)
				{
					count++;
					System.out.println(sc + " " + count);
					ps.setScoringParams(sc);
					ps.examineArrayOfStrings(textPlaces);
					ScanResultSet scanResult = new ScanResultSet(filenames[i], ps.getPlaces());
					//correctResults.updateScores(ps.getPlaces());
					int[] compareResults = correctResults.compareResults(scanResult);
					if(compareResults == null)
					{
						System.out.println("NULL?!?");
					}
					else
					{
						results.get(sc).add(compareResults);
					}
				}
			}

			BufferedWriter out = new BufferedWriter(new FileWriter("/home/sjm84/Desktop/deleteMe.txt"));
			//BufferedWriter out = new BufferedWriter(new FileWriter("/home/sam/Desktop/scanResults.txt"));

			for (ScanConfiguration sc : results.keySet())
			{
				out.write(sc.toString() + "\n");
				int correctCount = 0;
				int totalCount = 0;
				for (int[] i : results.get(sc))
				{
					out.write(((double)(i[0]))/((double)(i[1])) + " ");
					correctCount += i[0];
					totalCount += i[1];
				}

				out.write(((double)(correctCount)) / ((double)(totalCount)) + "\n");
			}
			out.close();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}

	public static void ListPopulate()
	{
		Statement database = null;

		try
		{
			Class.forName("org.postgresql.Driver");
			Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "sam", "password");

			database = c.createStatement();

			ResultSet places = database.executeQuery("SELECT placename, placetype FROM places WHERE population > -1");

			BufferedWriter countryList = new BufferedWriter(new FileWriter("/research/sjm84/Msc/Downloads/CountryList.lst"));
			BufferedWriter cityList = new BufferedWriter(new FileWriter("/research/sjm84/Msc/Downloads/CityList.lst"));

			while (places.next())
			{
				String pn = places.getString("placename");
				String pt = places.getString("placetype");

				if (pt.equals("country"))
				{
					countryList.write(pn + "\n");
				}
				else
				{
					cityList.write(pn + "\n");
				}
			}
			places.close();
			ResultSet alternatePlaces = database.executeQuery("SELECT * FROM alternatenames WHERE alternatename is not null");

			while (alternatePlaces.next())
			{
				cityList.write(alternatePlaces.getString("alternatename") + "\n");
			}
			alternatePlaces.close();

			cityList.close();
			countryList.close();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}

	public static void RPCTest()
	{
		try
		{
			String payload = "5|0|4|http://localhost:9090/greenstone3/interfaces/default/js/mapScripts/|FC39F395243F4B8A4145D4DCB673D89A|org.greenstone.client.findPlaceService|isGazetteerLoaded|1|2|3|4|0|";

			URL url = new URL("http://localhost:9090/gpnms/simplemaps/findPlace");
			HttpURLConnection con = (HttpURLConnection) url.openConnection();

			con.setUseCaches(false);
			con.setDoOutput(true);
			con.setDoInput(true);
			DataOutputStream dataOut = new DataOutputStream(con.getOutputStream());
			dataOut.write(payload.getBytes());
			dataOut.flush();
			dataOut.close();
			// DataInputStream in = new DataInputStream(con.getInputStream());
			System.out.println("Content = " + con.getInputStream());
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			System.out.println("Message = " + ex.getMessage());
		}
	}

	public void GazetteerTest()
	{
		//GazetteerTrieType4 gaz = new GazetteerTrieType4("/home/sam/Desktop/Research/Greenstone3-gate-svn2/web/GPNMS/dataen.txt");
		GazetteerTrieType5 gaz = new GazetteerTrieType5("/research/sjm84/Msc/Downloads/dataen.txt");
		initWords();
		int totalTime = 0;
		for (int i = 0; i < 100; i++)
		{
			Long time = System.currentTimeMillis();
			try
			{
				int count = 0;
				boolean done = false;
				while (!done)
				{
					StringBuilder currentWords = new StringBuilder();

					int length = 0;
					while (gaz.checkPlaceName(currentWords.toString()) != -1)
					{		
						String word = null;
						if(count + length < _words.size())
						{
							word = _words.get(count + length);
						}
						if (word == null)
						{
							totalTime += System.currentTimeMillis() - time;
							// _in.close();
							//System.out.println("DONE");
							done = true;
						}
						if(currentWords.length() == 0)
						{
							currentWords.append(word);
						}
						else
						{
							currentWords.append(" " + word);
						}
						length++;
					}
					currentWords = new StringBuilder();
					count++;
				}
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
		System.out.println("Total = " + totalTime / 100);
	}

	public void initWords()
	{
		try
		{
			BufferedReader in = new BufferedReader(new FileReader("/home/sjm84/Desktop/placenames.txt"));

			String line = null;
			while ((line = in.readLine()) != null)
			{	
				for (String word : line.split(" "))
				{
					_words.add(word);
					_words.add(word);
					_words.add(word);
				}
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		return;
	}


	public static void PlaceNameCheck()
	{
		GazetteerTrieType2 gazetteer = new GazetteerTrieType2("/research/sjm84/Msc/Downloads/dataen.txt");

		try
		{
			String inputLine = "";
			BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in));
			while ((inputLine = inputStream.readLine()) != "q")
			{
				if (gazetteer.checkPlaceName(inputLine) == 1)
				{
					System.out.println(inputLine + " is a place");
				}
				else
				{
					System.out.println(inputLine + " is not a place");
				}
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}

	public static void PlacesToPoints()
	{
		ArrayList<Float> latitudes = new ArrayList<Float>();
		ArrayList<Float> longitudes = new ArrayList<Float>();
		ArrayList<Long> ids = new ArrayList<Long>();

		Statement database = null;

		try
		{
			Class.forName("org.postgresql.Driver");
			Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "postgres", "admin");

			database = c.createStatement();

			ResultSet places = database.executeQuery("SELECT id, latitude, longitude FROM places WHERE latitude is not null");

			while (places.next())
			{
				latitudes.add(places.getFloat("latitude"));
				longitudes.add(places.getFloat("longitude"));
				ids.add(places.getLong("id"));
			}

			for (int i = 0; i < latitudes.size(); i++)
			{
				System.out.println("INSERT INTO placepoints (id, point) VALUES (" + ids.get(i) + ", GeomFromText('POINT(" + latitudes.get(i) + " " + longitudes.get(i) + ")'));");
				database.execute("INSERT INTO placepoints (id, point) VALUES (" + ids.get(i) + ", GeomFromText('POINT(" + latitudes.get(i) + " " + longitudes.get(i) + ")'));");
			}

			System.out.println("lat size = " + latitudes.size());
			System.out.println("lng size = " + longitudes.size());
			System.out.println("id size = " + ids.size());
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}

	public static void PopulateDatabase()
	{
		Statement database = null;
		try
		{
			Class.forName("org.postgresql.Driver");
			Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "postgres", "admin");

			database = c.createStatement();

			BufferedReader gazetteerFile = new BufferedReader(new FileReader("C:\\Users\\sjm84\\Desktop\\EclipseWorkspace\\ATLAS\\war\\dataen.txt"));

			String line = "";
			while ((line = gazetteerFile.readLine()) != null)
			{
				// The file is tab seperated so split it by tabs
				String[] columns = line.split("\t");

				String placeName = GazetteerHelper.getMainPlaceName(columns);
				if (placeName != null)
				{
					placeName = placeName.replaceAll("\'", "\\\\\'");
				}
				String countryName = GazetteerHelper.getCountryName(columns);
				if (countryName != null)
				{
					countryName = countryName.replaceAll("\'", "\\\\\'");
				}
				String regionName = GazetteerHelper.getRegionName(columns);
				if (regionName != null)
				{
					regionName = regionName.replaceAll("\'", "\\\\\'");
				}
				String subRegionName = GazetteerHelper.getSubRegionName(columns);
				if (subRegionName != null)
				{
					subRegionName = subRegionName.replaceAll("\'", "\\\\\'");
				}
				String placeType = GazetteerHelper.getPlaceType(columns);
				if (placeType != null)
				{
					placeType = placeType.replaceAll("\'", "\\\\\'");
				}
				Float latitude = GazetteerHelper.getLatitude(columns);
				Float longitude = GazetteerHelper.getLongitude(columns);
				int population = GazetteerHelper.getPopulation(columns);
				Integer id = GazetteerHelper.getID(columns);

				ArrayList<String> alternatePlaceNames = GazetteerHelper.getAlternativePlaceNames(columns);

				// Because counties do not contain the region information they
				// are not helpful, so ignore them
				if (placeName == null || id == null || placeType == null || placeType.equals("county") || placeType.equals("agglomeration"))
				{
					continue;
				}

				try
				{
					/*
					 * System.out.println("Inserting ---> \n" +
					 * "INSERT INTO places (id, placename, placetype, subregion, region, country, population, latitude, longitude) VALUES("
					 * + id + ", " + "\'" + placeName + "\'" + ", " + "\'" +
					 * placeType + "\'" + ", " + (subRegionName == null ? "null"
					 * : ("\'" + subRegionName + "\'")) + ", " + (regionName ==
					 * null ? "null" : ("\'" + regionName + "\'")) + ", " +
					 * (countryName == null ? "null" : ("\'" + countryName +
					 * "\'")) + ", " + population + ", " + latitude + ", " +
					 * longitude + ");");
					 */
					database.execute("INSERT INTO places (id, placename, placetype, subregion, region, country, population, latitude, longitude) VALUES(" + id + ", " + "\'" + placeName + "\'" + ", " + "\'" + placeType + "\'" + ", " + (subRegionName == null ? "null" : ("\'" + subRegionName + "\'")) + ", " + (regionName == null ? "null" : ("\'" + regionName + "\'")) + ", " + (countryName == null ? "null" : ("\'" + countryName + "\'")) + ", " + population + ", " + latitude + ", " + longitude + ");");

					if (alternatePlaceNames != null)
					{
						for (String altName : alternatePlaceNames)
						{
							if (altName != null)
							{
								altName = altName.replaceAll("\'", "\\\\\'");
								/*
								 * System.out.println("INSERT INTO alternatenames (alternatename, placeindex) VALUES("
								 * + "\'" + altName + "\', " + id + ");");
								 */
								database.execute("INSERT INTO alternatenames (alternatename, placeindex) VALUES(" + "\'" + altName + "\', " + id + ");");
							}
						}
					}
				}
				catch (Exception ex)
				{
					ex.printStackTrace();
				}
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}

	public static void DatabaseFix()
	{
		Statement database = null;

		try
		{
			Class.forName("org.postgresql.Driver");
			Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/GS3MapDB", "postgres", "admin");

			database = c.createStatement();

			ResultSet results = database.executeQuery("SELECT * FROM places WHERE population >= 0;");

			ArrayList<String> placeNameList = new ArrayList<String>();
			ArrayList<String> subRegionList = new ArrayList<String>();
			ArrayList<String> regionList = new ArrayList<String>();
			ArrayList<String> countryList = new ArrayList<String>();

			while (results.next())
			{
				placeNameList.add(results.getString("placename"));
				subRegionList.add(results.getString("subregion"));
				regionList.add(results.getString("region"));
				countryList.add(results.getString("country"));
			}

			int counter = 0;
			while (counter < placeNameList.size())
			{
				String placeName = placeNameList.get(counter);
				String subRegionName = subRegionList.get(counter);
				String regionName = regionList.get(counter);
				String countryName = countryList.get(counter);

				System.out.println("* " + counter++ + " " + placeName);

				if (subRegionName != null)
				{
					ResultSet subRegionResults = database.executeQuery("SELECT * FROM places WHERE " + "placename = \'" + subRegionName.replaceAll("\'", "\\\\\'") + "\' AND " + "region = \'" + regionName.replaceAll("\'", "\\\\\'") + "\' AND " + "country = \'" + countryName.replaceAll("\'", "\\\\\'") + "\';");

					int count = 0;
					while (subRegionResults.next())
					{
						count++;
					}

					if (count == 0)
					{
						System.out.println("Adding " + subRegionName.replaceAll("\'", "\\\\\'"));

						database.execute("INSERT INTO places (placename, placetype, subregion, region, country, population, latitude, longitude) VALUES(" + "\'" + subRegionName.replaceAll("\'", "\\\\\'") + "\', " + "\'region\', " + "null, " + "\'" + regionName.replaceAll("\'", "\\\\\'") + "\', " + "\'" + countryName.replaceAll("\'", "\\\\\'") + "\', " + "0, " + "null, " + "null);");
					}
				}

				if (regionName != null)
				{
					ResultSet regionResults = database.executeQuery("SELECT * FROM places WHERE " + "placename = \'" + regionName.replaceAll("\'", "\\\\\'") + "\' AND " + "country = \'" + countryName.replaceAll("\'", "\\\\\'") + "\';");

					int count = 0;
					while (regionResults.next())
					{
						count++;
					}

					if (count == 0)
					{
						System.out.println("Adding " + regionName.replaceAll("\'", "\\\\\'"));

						database.execute("INSERT INTO places (placename, placetype, subregion, region, country, population, latitude, longitude) VALUES(" + "\'" + regionName.replaceAll("\'", "\\\\\'") + "\', " + "\'region\', " + "null, " + "null, " + "\'" + countryName.replaceAll("\'", "\\\\\'") + "\', " + "0, " + "null, " + "null);");
					}
				}

				if (countryName != null)
				{
					ResultSet countryResults = database.executeQuery("SELECT * FROM places WHERE " + "placename = \'" + countryName.replaceAll("\'", "\\\\\'") + "\';");

					int count = 0;
					while (countryResults.next())
					{
						count++;
					}

					if (count == 0)
					{
						System.out.println("Adding " + countryName.replaceAll("\'", "\\\\\'"));

						database.execute("INSERT INTO places (placename, placetype, subregion, region, country, population, latitude, longitude) VALUES(" + "\'" + countryName.replaceAll("\'", "\\\\\'") + "\', " + "\'country\', " + "null, " + "null, " + "null, " + "0, " + "null, " + "null);");
					}
				}
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}

	public ScanResultSet getCorrectScanResultSet(int index)
	{
		ScanResultSet correctResultSet = null;

		if (index == 0)
		{
			correctResultSet = new ScanResultSet("australia", new Long[] { new Long(-24), /* Australia */
			new Long(196916913), /* Canberra */
			new Long(202101121), /* Sydney */
			new Long(-81), /* UK */
			new Long(-435), /* Tasmania */
			new Long(-101), /* Indonesia */
			new Long(-214), /* East_Timor */
			new Long(-170), /* PNG */
			new Long(-186), /* Solomon_Islands */
			new Long(-232), /* Vanuatu */
			new Long(-155), /* New_Caledonia */
			new Long(-165), /* New_Zealand */
			new Long(187916496), /* Melbourne */
			new Long(225177302), /* Brisbane */
			new Long(208973584), /* Perth */
			new Long(198283860), /* Adelaide */
			new Long(279283085), /* Darwin */
			new Long(-431), /* NSW */
			new Long(-430), /* ACT */
			new Long(301780683), /* Jakarta */
			new Long(-160), /* Netherlands */
			new Long(-1495), /* England */
			new Long(-434), /* South_Australia */
			new Long(-436), /* Victoria */
			new Long(-433), /* Queensland */
			new Long(-432), /* Northern_Territory */
			new Long(-437), /* WA */
			new Long(469532668), /* Gelibolu(Gallipoli) */
			new Long(-223), /* Christmas_Island */
			new Long(-3902), /* Cocos_Islands */
			new Long(-3900), /* Ashmore_and_Cartier */
			new Long(-3903), /* Coral_Sea_Islands */
			new Long(-157), /* Norfolk_Island */
			new Long(263120575), /* Cairns */
			new Long(-111), /* Japan */
			new Long(-152), /* Malaysia */
			new Long(-190), /* Singapore */
			new Long(-45), /* Canada */
			new Long(-188), /* Sudan */
			new Long(-105), /* Iraq */
			new Long(-161), /* Norway */
			new Long(-155), /* Kiribati */
			new Long(-163), /* Nauru */
			new Long(-217), /* Tuvalu */
			new Long(-54), /* China */
			new Long(-108), /* Italy */
			new Long(-231), /* Vietnam */
			new Long(222981344), /* Gold_Coast */
			new Long(205521175), /* Newcastle */
			new Long(196772922), /* Queanbeyan */
			new Long(200121087), /* Wollongong */
			new Long(230865256), /* Sunshine_Coast */
			new Long(169772729), /* Hobart */
			new Long(186728432), /* Geelong */
			new Long(254696678), /* Townsville */
			new Long(224817196), /* Toowoomba */
			new Long(174812713), /* Launceston */
			new Long(194216692), /* Albury */
			new Long(193964688), /* Wodonga */
			new Long(188816384), /* Ballarat */
			new Long(191696428), /* Bendigo */
			new Long(-126), /* Liechtenstein */
			new Long(-63), /* Denmark */
			new Long(-972), /* Aomen */
			new Long(-32), /* Bulgaria */
			new Long(-79), /* France */
			new Long(-140), /* Mali */
			new Long(-189), /* Sweden */
			new Long(-131), /* Luxembourg */
			new Long(510353874), /* Oxford */
			new Long(511974013), /* Cambridge */
			// new Long(509489990), /* London */
			new Long(-75), /* Fiji */
			new Long(-77), /* Micronesia */
			new Long(-138), /* Marshall Islands */
			new Long(-178), /* Palau */
			new Long(-234), /* Samoa */
			new Long(-213), /* Tonga */
			new Long(-232), /* Vanuatu */
			new Long(-169), /* French Polynesia */
			new Long(-155), /* New Caledonia */
			new Long(-233), /* Wallis and Futuna */
			new Long(-51), /* Cook Islands */
			new Long(-164), /* Niue */
			new Long(-210), /* Tokelau */
			new Long(-3912), /* Pitcairn */
			new Long(-22), /* American Samoa */
			new Long(-94), /* Guam */
			new Long(-3767), /* Hawaii */
			new Long(-143), /* Chile */
			new Long(-3907), /* Easter Island */
			new Long(-102), /* Ireland */
			new Long(-239), /* Isle of Man */
			new Long(-238), /* Jersey */
			new Long(-147), /* Malta */
			new Long(-14), /* Antigua and Barbuda */
			new Long(-40), /* Bahamas */
			new Long(-28), /* Barbados */
			new Long(-64), /* Dominica */
			new Long(-96), /* Guyana */
			new Long(-109), /* Jamaica */
			new Long(-117), /* Saint Kitts and Nevis */
			new Long(-227), /* Saint Vincent and The Grenadines */
			new Long(-216), /* Trinidad and Tobago */
			new Long(-44), /* Belize */
			new Long(-82), /* Grenada */
			new Long(-125), /* Saint Lucia */
			new Long(-37), /* Brunei */
			new Long(-185), /* Saudi Arabia */
			new Long(-203), /* Swaziland */
			new Long(-226), /* Vatican City */
			new Long(-11), /* Andorra */
			new Long(-33), /* Bahrain */
			new Long(-30), /* Belgium */
			new Long(-41), /* Bhutan */
			new Long(-114), /* Cambodia */
			new Long(-110), /* Jordan */
			new Long(-120), /* Kuwait */
			new Long(-129), /* Lesothol */
			new Long(-152), /* Malaysia */
			new Long(-135), /* Monaco */
			new Long(-134), /* Morocco */
			new Long(-166), /* Oman */
			new Long(-180), /* Qatar */
			new Long(-72), /* Spain */
			new Long(-208), /* Thailand */
			new Long(-12), /* United Arab Emirates */
			new Long(-85), /* Ghana */
			new Long(-1520), /* Ashanti */
			new Long(-2608), /* Johor */
			new Long(-2609), /* Kedah */
			new Long(-2610), /* Kelantan */
			new Long(-2614), /* Negeri Sembilan */
			new Long(-2615), /* Pahang */
			new Long(-2616), /* Perak */
			new Long(-2617), /* Perlis */
			new Long(-2621), /* Selangor */
			new Long(-2622), /* Terengganu */
			new Long(-158), /* Nigeria */
			new Long(350586393), /* Ibadan */
			new Long(-2677), /* Kano */
			new Long(-2691), /* Sokoto */
			new Long(-2682), /* Lagos */
			new Long(-221), /* Uganda */
			new Long(-265), /* Abu Dhabi */
			new Long(-267), /* Dubai */
			new Long(-270), /* Sharjah */
			new Long(-3891), /* Wallis and Futuna */
			new Long(-3895), /* Sigave */
			new Long(-246), /* Zambia */
			new Long(-245), /* South Africa */
			new Long(-29), /* Bangladesh */
			new Long(-42), /* Botswana */
			new Long(-53), /* Cameroon */
			new Long(-59), /* Cyprus */
			new Long(-88), /* Gambia */
			new Long(-104), /* India */
			new Long(-112), /* Kenya */
			new Long(-150), /* Malawi */
			new Long(-149), /* Maldives */
			new Long(-148), /* Mauritius */
			new Long(-153), /* Mozambique */
			new Long(-154), /* Namibia */
			new Long(-172), /* Pakistan */
			new Long(-187), /* Seychelles */
			new Long(-195), /* Sierra Leone */
			new Long(-127), /* Sri Lanka */
			new Long(-219), /* Tanzania */
			});
		}
		else if (index == 1)
		{
			correctResultSet = new ScanResultSet("canada", new Long[] { new Long(-3795), /*
																						 * Rhode
																						 * Island
																						 */
			new Long(-433), /* Queensland */
			new Long(-159), /* Nicaragua */
			new Long(-13), /* Afghanistan */
			new Long(-3785), /* New Hampshire */
			new Long(-3774), /* Louisiana */
			new Long(-121), /* Cayman Islands */
			new Long(498353663), /* Victoria */
			new Long(-3780), /* Mississippi */
			new Long(-96), /* Guyana */
			new Long(-115), /* Kiribati */
			new Long(-123), /* Laos */
			new Long(-90), /* Guadeloupe */
			new Long(-201), /* El Salvador */
			new Long(-126), /* Liechtenstein */
			new Long(474823250), /* Rome */
			new Long(-174), /* Saint Pierre and Miquelon */
			new Long(-47), /* Central African Republic */
			new Long(-838), /* British Columbia */
			new Long(490475686), /* Charlottetown */
			new Long(487450810), /* Sherbrooke */
			new Long(511747334), /* Saskatoon */
			new Long(-218), /* Taiwan */
			new Long(-149), /* Maldives */
			new Long(-220), /* Ukraine */
			new Long(503576283), /* Winnipeg */
			new Long(-3765), /* Florida */
			new Long(-837), /* Alberta */
			new Long(-108), /* Italy */
			new Long(-136), /* Moldova */
			new Long(-3901), /* Christmas Island */
			new Long(-59), /* Cyprus */
			new Long(-233), /* Wallis and Futuna */
			new Long(480465950), /* Kitchener */
			new Long(-51), /* Cook Islands */
			new Long(-849), /* Yukon */
			new Long(-91), /* Equatorial Guinea */
			new Long(-6751), /* Paris */
			new Long(-98), /* Croatia */
			new Long(-848), /* Saskatchewan */
			new Long(476289697), /* Windsor */
			new Long(-435), /* Tasmania */
			new Long(-189), /* Sweden */
			new Long(-144), /* Martinique */
			new Long(-204), /* Turks and Caicos Islands */
			new Long(-2614), /* Negeri Sembilan */
			new Long(-844), /* Nunavut */
			new Long(-168), /* Peru */
			new Long(-88), /* Gambia */
			new Long(-3767), /* Hawaii */
			new Long(-187), /* Seychelles */
			new Long(-221), /* Uganda */
			new Long(-207), /* Togo */
			new Long(-188), /* Sudan */
			new Long(-40), /* Bahamas */
			new Long(-216), /* Trinidad and Tobago */
			new Long(-246), /* Zambia */
			new Long(-65), /* Dominican Republic */
			new Long(-48), /* Congo */
			new Long(-177), /* Portugal */
			new Long(-999), /* Hong Kong */
			new Long(484823639), /* Halifax */
			new Long(-75), /* Fiji Islands */
			new Long(-164), /* Niue */
			new Long(520998673), /* Athabasca */
			new Long(-234), /* Samoa */
			new Long(-215), /* Turkey */
			new Long(-3900), /* Ashmore and Cartier */
			new Long(472726708), /* New Haven */
			new Long(505627539), /* Regina */
			new Long(-205), /* Chad */
			new Long(-182), /* Romania */
			new Long(-84), /* French Guiana */
			new Long(-137), /* Madagascar */
			new Long(-116), /* Comoros */
			new Long(-185), /* Saudi Arabia */
			new Long(-102), /* Ireland */
			new Long(-1495), /* England */
			new Long(481150062), /* Toronto */
			new Long(-152), /* Malaysia */
			new Long(-25), /* Aruba */
			new Long(-245), /* South Africa */
			new Long(489826804), /* Victoriaville */
			new Long(-135), /* Monaco */
			new Long(-145), /* Mauritania */
			new Long(-3762), /* Connecticut */
			new Long(-2620), /* Sarawak */
			new Long(-840), /* New Brunswick */
			new Long(-20), /* Antarctica */
			new Long(-173), /* Poland */
			new Long(-3757), /* Alaska */
			new Long(-32), /* Bulgaria */
			new Long(-83), /* Georgia */
			new Long(-61), /* Germany */
			new Long(-161), /* Norway */
			new Long(-57), /* Cuba */
			new Long(-56), /* Costa Rica */
			new Long(-104), /* India */
			new Long(-594), /* Luxemburg */
			new Long(-197), /* Senegal */
			new Long(-3777), /* Massachusetts */
			new Long(-2621), /* Selangor */
			new Long(-3776), /* Maryland */
			new Long(-154), /* Namibia */
			new Long(-846), /* Prince Edward Island */
			new Long(-845), /* Ontario */
			new Long(-125), /* Saint Lucia */
			new Long(-3788), /* New York */
			new Long(477873552), /* East Lansing */
			new Long(-3794), /* Pennsylvania */
			new Long(-3840), /* Grenadines */
			new Long(-217), /* Tuvalu */
			new Long(-72), /* Spain */
			new Long(-437), /* Western Australia */
			new Long(523014522), /* Slave Lake */
			new Long(-97), /* Honduras */
			new Long(-2612), /* Labuan */
			new Long(-76), /* Falkland Islands */
			new Long(-109), /* Jamaica */
			new Long(-2622), /* Terengganu */
			new Long(-42), /* Botswana */
			new Long(-171), /* Philippines */
			new Long(-134), /* Morocco */
			new Long(-99), /* Haiti */
			new Long(-79), /* France */
			new Long(-175), /* Puerto Rico */
			new Long(-2615), /* Pahang */
			new Long(-58), /* Cape Verde */
			new Long(-132), /* Latvia */
			new Long(-167), /* Panama */
			new Long(-34), /* Burundi */
			new Long(-2609), /* Kedah */
			new Long(504473703), /* Whistler */
			new Long(-227), /* Saint Vincent and The Grenadines */
			new Long(-151), /* Mexico */
			new Long(479746015), /* Hamilton */
			new Long(-138), /* Marshall Islands */
			new Long(-107), /* Iceland */
			new Long(-124), /* Lebanon */
			new Long(-129), /* Lesotho */
			new Long(-157), /* Norfolk Island */
			new Long(479134098), /* Niagara Falls */
			new Long(-229), /* British Virgin Islands */
			new Long(-192), /* Slovenia */
			new Long(-9192), /* Washington */
			new Long(-146), /* Montserrat */
			new Long(-31), /* Burkina Faso */
			new Long(-69), /* Egypt */
			new Long(501413687), /* Vancouver */
			new Long(-183), /* Russia */
			new Long(-165), /* New Zealand */
			new Long(-194), /* Slovakia */
			new Long(477765545), /* Lansing */
			new Long(-92), /* Greece */
			new Long(-208), /* Thailand */
			new Long(-213), /* Tonga */
			new Long(485470468), /* Iroquois */
			new Long(-77), /* Micronesia */
			new Long(-63), /* Denmark */
			new Long(-120), /* Kuwait */
			new Long(-226), /* Vatican City */
			new Long(-172), /* Pakistan */
			new Long(-3802), /* Virginia */
			new Long(-2616), /* Perak */
			new Long(-842), /* Northwest Territories */
			new Long(482014114), /* Oshawa */
			new Long(-53), /* Cameroon */
			new Long(-3778), /* Michigan */
			new Long(-3786), /* New Jersey */
			new Long(-247), /* Zimbabwe */
			new Long(-244), /* Serbia */
			new Long(-68), /* Estonia */
			new Long(488639613), /* Oxford */
			new Long(-186), /* Solomon Islands */
			new Long(-112), /* Kenya */
			new Long(-150), /* Malawi */
			new Long(-212), /* Tunisia */
			new Long(-54), /* China */
			new Long(-1520), /* Ashanti */
			new Long(523157692), /* Mackenzie */
			new Long(-3875), /* Saint Croix */
			new Long(-114), /* Cambodia */
			new Long(487882643), /* Montreal */
			new Long(-3789), /* North Carolina */
			new Long(-101), /* Indonesia */
			new Long(-2610), /* Kelantan */
			new Long(-52), /* Chile */
			new Long(-33), /* Bahrain */
			new Long(483490166), /* Peterborough */
			new Long(-176), /* Palestine */
			new Long(-166), /* Oman */
			new Long(-839), /* Manitoba */
			new Long(492022827), /* Donnacona */
			new Long(-156), /* Niger */
			new Long(-18), /* Netherlands Antilles */
			new Long(-3903), /* Coral Sea Islands */
			new Long(-60), /* Czech Republic */
			new Long(-843), /* Nova Scotia */
			new Long(-3753), /* Navassa Island */
			new Long(-847), /* Quebec */
			new Long(-841), /* Newfoundland and Labrador */
			new Long(-49), /* Switzerland */
			new Long(478701876), /* London */
			new Long(-3793), /* Oregon */
			new Long(516858646), /* Edmonton */
			new Long(-23), /* Austria */
			new Long(-1376), /* South Sandwich Islands */
			new Long(-100), /* Hungary */
			new Long(-36), /* Bermuda */
			new Long(-148), /* Mauritius */
			new Long(-21), /* Argentina */
			new Long(-210), /* Tokelau */
			new Long(511567873), /* Swan River */
			new Long(-111), /* Japan */
			new Long(-12), /* United Arab Emirates */
			new Long(-431), /* New South Wales */
			new Long(-3796), /* South Carolina */
			new Long(-127), /* Sri Lanka */
			new Long(-3902), /* Cocos Islands */
			new Long(-87), /* Greenland */
			new Long(-139), /* Macedonia */
			new Long(-110), /* Jordan */
			new Long(-3791), /* Ohio */
			new Long(507786594), /* Calgary */
			new Long(-117), /* Saint Kitts and Nevis */
			new Long(-184), /* Rwanda */
			new Long(-203), /* Swaziland */
			new Long(-238), /* Jersey */
			new Long(487522429), /* Ottawa */
			new Long(-434), /* South Australia */
			new Long(-180), /* Qatar */
			new Long(458717784), /* Stanford */
			new Long(-178), /* Palau */
			new Long(-41), /* Bhutan */
			new Long(-231), /* Vietnam */
			new Long(-24), /* Australia */
			new Long(-160), /* Netherlands */
			new Long(-86), /* Gibraltar */
			new Long(-3763), /* Delaware */
			new Long(-239), /* Isle of Man */
			new Long(-130), /* Lithuania */
			new Long(-199), /* Suriname */
			new Long(514267762), /* Hudson Bay */
			new Long(-82), /* Grenada */
			new Long(-190), /* Singapore */
			new Long(-95), /* Guinea-Bissau */
			});
		}
		else if (index == 2)
		{
			correctResultSet = new ScanResultSet("ireland", new Long[] { new Long(-1395), /* Asturias */
			new Long(512693027), /* Causeway */
			new Long(510137147), /* Kinsale */
			new Long(516005375), /* Dublin */
			new Long(515609332), /* Naas */
			new Long(-1496), /* Northern Ireland */
			new Long(518489358), /* Dundalk */
			new Long(474823250), /* Rome */
			new Long(512441352), /* Wexford */
			new Long(513737108), /* Shannon */
			// new Long(521009377), /* Antrim */
			new Long(514925071), /* Lisdoonvarna */
			new Long(-108), /* Italy */
			new Long(517121180), /* Roscommon */
			new Long(514097385), /* Arklow */
			new Long(519065365), /* Newry */
			new Long(-1497), /* Scotland */
			new Long(518561381), /* Carlingford */
			// new Long(519677333), /* Armagh */
			new Long(-1298), /* Galicia */
			new Long(514781395), /* Wicklow */
			new Long(522809335), /* Portrush */
			new Long(512477258), /* Carrick-on-Suir */
			new Long(-999), /* Hong Kong */
			new Long(517445219), /* Longford */
			new Long(-234), /* Samoa */
			new Long(514853389), /* Ashford */
			new Long(-102), /* Ireland */
			new Long(517625108), /* Knock */
			new Long(-1399), /* Barcelona */
			new Long(-1495), /* England */
			new Long(515825094), /* Galway */
			new Long(202101121), /* Sydney */
			new Long(512153287), /* Waterford */
			new Long(515393301), /* Kildare */
			new Long(-104), /* India */
			new Long(516725266), /* Mullingar */
			new Long(512981183), /* Tipperary */
			new Long(514745251), /* Castletown */
			new Long(510713170), /* Cobh */
			new Long(-1498), /* Wales */
			new Long(-3788), /* New York */
			new Long(519389141), /* Strandhill */
			new Long(517193331), /* Navan */
			new Long(-72), /* Spain */
			new Long(514241308), /* Carlow */
			new Long(520145171), /* Bundoran */
			new Long(513593274), /* Kilkenny */
			new Long(520793188), /* Donegal */
			new Long(519317303), /* Monaghan */
			new Long(478665434), /* Grand Rapids */
			new Long(519425152), /* Sligo */
			new Long(-81), /* United Kingdom */
			new Long(512045133), /* Buttevant */
			new Long(514601065), /* Lahinch */
			new Long(-79), /* France */
			new Long(-45), /* Canada */
			new Long(512513229), /* Clonmel */
			// new Long(520577407), /* Belfast */
			new Long(522017267), /* Londonderry */
			new Long(517409364), /* Drogheda */
			new Long(513017343), /* Enniscorthy */
			new Long(511037215), /* Youghal */
			new Long(-165), /* New Zealand */
			new Long(518237346), /* Louth */
			new Long(-3802), /* Virginia */
			new Long(527417729), /* Carnoustie */
			new Long(-3786), /* New Jersey */
			new Long(-247), /* Zimbabwe */
			new Long(516545775), /* Manchester */
			new Long(515897124), /* Athenry */
			new Long(510353874), /* Oxford */
			new Long(514061177), /* Silvermines */
			new Long(470674597), /* Hoboken */
			new Long(513089211), /* Cashel */
			new Long(520793432), /* Bangor */
			new Long(512657305), /* New Ross */
			new Long(509993050), /* Bantry */
			new Long(-101), /* Indonesia */
			new Long(513701217), /* Thurles */
			// new Long(520289394), /* Lisburn */
			new Long(511001143), /* Blarney */
			new Long(511684975), /* Dingle */
			new Long(-3139), /* Moscow */
			new Long(516797320), /* Trim */
			new Long(-6055), /* London */
			new Long(-6030), /* Cornwall */
			new Long(-111), /* Japan */
			// new Long(521477418), /* Larne */
			new Long(-87), /* Greenland */
			new Long(510929183), /* Midleton */
			new Long(510857153), /* Cork */
			new Long(-228), /* Venezuela */
			new Long(518417263), /* Cavan */
			new Long(513629137), /* Limerick */
			new Long(514349180), /* Nenagh */
			new Long(-24), /* Australia */
			new Long(-256907), /* Killarney */
			new Long(-239), /* Isle of Man */
			new Long(497323158), /* Munich */
			// new Long(522485331), /* Coleraine */
			});
		}
		else if (index == 3)
		{
			correctResultSet = new ScanResultSet("southafrica", new Long[] { new Long(-245), /*
																							 * South
																							 * Africa
																							 */
			new Long(231392822), /* Pretoria */
			new Long(219080623), /* Bloemfontein */
			new Long(201871846), /* Cape Town */
			new Long(229736804), /* Johannesburg */
			new Long(-81), /* United Kingdom */
			new Long(-154), /* Namibia */
			new Long(-42), /* Botswana */
			new Long(-153), /* Mozambique */
			new Long(-203), /* Swaziland */
			new Long(-129), /* Lesotho */
			new Long(-3991), /* KwaZulu Natal */
			new Long(-3988), /* Eastern Cape */
			new Long(-101), /* Indonesia */
			new Long(-137), /* Madagascar */
			new Long(-24), /* Australia */
			new Long(-101), /* Indonesia */
			new Long(-104), /* India */
			new Long(-3990), /* Gauteng */
			new Long(-3992), /* Limpopo */
			new Long(-3993), /* Mpumalanga */
			new Long(-3995), /* North West */
			new Long(-34), /* Burundi */
			new Long(-116), /* Comoros */
			new Long(-247), /* Zimbabwe */
			new Long(-3994), /* Northern Cape */
			new Long(-3989), /* Free State */
			new Long(-3996), /* Western Cape */
			new Long(205688739), /* Bhisho */
			new Long(217425039), /* Pietermaritzburg */
			new Long(238016945), /* Polokwane */
			new Long(232329098), /* Nelspruit */
			new Long(220520477), /* Kimberley */
			new Long(238016945), /* Polokwane */
			new Long(231032561), /* Mmabatho */
			new Long(-55), /* Colombia */
			new Long(-78614), /* Sutherland */
			new Long(221564123), /* Upington */
			new Long(203132219), /* Oudtshoorn */
			new Long(-39), /* Brazil */
			new Long(-54), /* China */
			new Long(-151), /* Mexico */
			new Long(201764559), /* Port Elizabeth */
			new Long(-133), /* Libya */
			new Long(216489099), /* Durban */
			new Long(-148), /* Mauritius */
			new Long(-150), /* Malawi */
			new Long(-61), /* Germany */
			new Long(-111), /* Japan */
			new Long(-72), /* Spain */
			new Long(201907886), /* Stellenbosch */
			new Long(202699896), /* Paarl */
			new Long(-79), /* France */
			new Long(445545558), /* Atlanta */
			new Long(-14), /* Antigua and Barbuda */
			new Long(-40), /* Bahamas */
			new Long(-28), /* Barbados */
			new Long(-64), /* Dominica */
			new Long(-96), /* Guyana */
			new Long(-109), /* Jamaica */
			new Long(-117), /* Saint Kitts and Nevis */
			new Long(-227), /* Saint Vincent and The Grenadines */
			new Long(-216), /* Trinidad and Tobago */
			new Long(-44), /* Belize */
			new Long(-82), /* Grenada */
			new Long(-125), /* Saint Lucia */
			new Long(-37), /* Brunei */
			new Long(-185), /* Saudi Arabia */
			new Long(-203), /* Swaziland */
			new Long(-33), /* Bahrain */
			new Long(-30), /* Belgium */
			new Long(-120), /* Kuwait */
			new Long(-129), /* Lesothol */
			new Long(-152), /* Malaysia */
			new Long(-134), /* Morocco */
			new Long(-166), /* Oman */
			new Long(-180), /* Qatar */
			new Long(-72), /* Spain */
			new Long(-208), /* Thailand */
			new Long(-12), /* United Arab Emirates */
			new Long(-85), /* Ghana */
			new Long(-158), /* Nigeria */
			new Long(-221), /* Uganda */
			new Long(-246), /* Zambia */
			});
		}
		else if (index == 4)
		{
			correctResultSet = new ScanResultSet("washington", new Long[] { new Long(-3795), /*
																							 * Rhode
																							 * Island
																							 */
			new Long(498317769), /* Mount Vernon */
			new Long(-3750), /* Johnston Atoll */
			new Long(-3785), /* New Hampshire */
			new Long(-3774), /* Louisiana */
			new Long(-3780), /* Mississippi */
			new Long(496193763), /* Edmonds */
			new Long(498605777), /* Sedro-Woolley */
			new Long(493781747), /* Lakewood */
			new Long(491729947), /* Yakima */
			new Long(492197704), /* Centralia */
			new Long(-838), /* British Columbia */
			new Long(495113796), /* Issaquah */
			new Long(493349711), /* Olympia */
			new Long(493205945), /* Ellensburg */
			new Long(-3797), /* South Dakota */
			new Long(494970242), /* Cheney */
			new Long(493961689), /* Shelton */
			new Long(-3765), /* Florida */
			new Long(-3756), /* Alabama */
			new Long(494321766), /* Federal Way */
			new Long(496661780), /* Everett */
			new Long(-3768), /* Idaho */
			new Long(-3748), /* Howland Island */
			new Long(495618259), /* Spokane */
			new Long(496049769), /* Mountlake Terrace */
			new Long(-849), /* Yukon */
			new Long(495257777), /* Mercer Island */
			new Long(489858166), /* Walla Walla */
			new Long(-3747), /* Baker Island */
			new Long(-3771), /* Iowa */
			new Long(-3790), /* North Dakota */
			new Long(-3770), /* Indiana */
			new Long(-3779), /* Minnesota */
			new Long(490362023), /* Prosser */
			new Long(-3767), /* Hawaii */
			new Long(-3782), /* Montana */
			new Long(495581748), /* Bainbridge Island */
			new Long(495618276), /* Spokane Valley */
			new Long(496229998), /* Chelan */
			new Long(490830295), /* Asotin */
			new Long(-3787), /* New Mexico */
			new Long(488957885), /* Klickitat */
			new Long(494717971), /* East Wenatchee */
			new Long(-3760), /* California */
			new Long(493205708), /* Tumwater */
			new Long(496949759), /* Langley */
			new Long(490326083), /* Kennewick */
			new Long(492809731), /* Rainier */
			new Long(497849738), /* Oak Harbor */
			new Long(-3755), /* Wake */
			new Long(494645769), /* Des Moines */
			new Long(496698102), /* Coulee Dam */
			new Long(495365784), /* Bellevue */
			new Long(498569737), /* Anacortes */
			new Long(496590100), /* Grand Coulee */
			new Long(490865595), /* Long Beach */
			new Long(490757999), /* Sunnyside */
			new Long(-3762), /* Connecticut */
			new Long(494537790), /* Covington */
			new Long(-3758), /* Arizona */
			new Long(-3757), /* Alaska */
			new Long(-3783), /* Nebraska */
			new Long(495653781), /* Kirkland */
			new Long(-3777), /* Massachusetts */
			new Long(494933780), /* Renton */
			new Long(-3776), /* Maryland */
			new Long(496193770), /* Lynnwood */
			new Long(-3801), /* Vermont */
			new Long(496553769), /* Mukilteo */
			new Long(-3788), /* New York */
			new Long(495185730), /* Bremerton */
			new Long(490650065), /* West Richland */
			new Long(494285779), /* Auburn */
			new Long(-3761), /* Colorado */
			new Long(-3794), /* Pennsylvania */
			new Long(491045974), /* Zillah */
			new Long(488813747), /* Battle Ground */
			new Long(-3784), /* Nevada */
			new Long(490506087), /* Pasco */
			new Long(494537796), /* Maple Valley */
			new Long(495905764), /* Shoreline */
			new Long(498786210), /* Colville */
			new Long(495941776), /* Kenmore */
			new Long(453969645), /* New Market */
			new Long(493853772), /* Puyallup */
			new Long(494933773), /* Tukwila */
			new Long(493133958), /* Kittitas */
			new Long(-3798), /* Tennessee */
			new Long(487949734), /* Portland */
			new Long(-151), /* Mexico */
			new Long(-45), /* Canada */
			new Long(-3775), /* Maine */
			new Long(494789770), /* SeaTac */
			new Long(495005821), /* North Bend */
			new Long(495293790), /* Sammamish */
			new Long(-3805), /* Wisconsin */
			new Long(-9192), /* Washington */
			new Long(496301780), /* Mill Creek */
			new Long(493925801), /* Enumclaw */
			new Long(490073711), /* Kelso */
			new Long(488273736), /* Vancouver */
			new Long(-183), /* Russia */
			new Long(495941780), /* Bothell */
			new Long(499469753), /* Bellingham */
			new Long(-3802), /* Virginia */
			new Long(497021785), /* Marysville */
			new Long(-3799), /* Texas */
			new Long(494105754), /* Tacoma */
			new Long(-3778), /* Michigan */
			new Long(-3786), /* New Jersey */
			new Long(-3759), /* Arkansas */
			new Long(493925906), /* Cle Elum */
			new Long(495149736), /* Port Orchard */
			new Long(493601742), /* Fort Lewis */
			new Long(494861765), /* Burien */
			new Long(493638071), /* Moses Lake */
			new Long(497525788), /* Arlington */
			new Long(496517791), /* Snohomish */
			new Long(493242286), /* Garfield */
			new Long(-8340), /* District of Columbia */
			new Long(-3749), /* Jarvis Island */
			new Long(-3789), /* North Carolina */
			new Long(497489654), /* Port Angeles */
			new Long(-101), /* Indonesia */
			new Long(490650071), /* Richland */
			new Long(495617789), /* Redmond */
			new Long(-3806), /* Wyoming */
			new Long(-3772), /* Kansas */
			new Long(498102042), /* Okanogan */
			new Long(-3753), /* Navassa Island */
			new Long(493133619), /* Aberdeen */
			new Long(-3781), /* Missouri */
			new Long(495905789), /* Woodinville */
			new Long(493997746), /* University Place */
			new Long(-3793), /* Oregon */
			new Long(-3769), /* Illinois */
			new Long(495365934), /* Leavenworth */
			new Long(494753968), /* Wenatchee */
			new Long(-3773), /* Kentucky */
			new Long(-3800), /* Utah */
			new Long(-3796), /* South Carolina */
			new Long(488093765), /* Washougal */
			new Long(494609776), /* Kent */
			new Long(495437765), /* Seattle */
			new Long(496301801), /* Monroe */
			new Long(-3791), /* Ohio */
			new Long(-3804), /* West Virginia */
			new Long(-3751), /* Kingman Reef */
			new Long(490145705), /* Longview */
			new Long(490506009), /* Grandview */
			new Long(492234284), /* Pullman */
			new Long(500225754), /* Lynden */
			new Long(493889783), /* Bonney Lake */
			new Long(495941771), /* Lake Forest Park */
			new Long(-3763), /* Delaware */
			new Long(488129758), /* Camas */
			new Long(493313719), /* Lacey */
			new Long(-3792), /* Oklahoma */
			});
		}
		return correctResultSet;
	}
}
