import java.util.ArrayList; import java.util.List; /** *
* This class represents the data points for a given set of contacts. * Specifically it is used to generate the Javascript code representing an array * of GLatLng objects for use with the Google Maps API. *
* @author Mark Woehrer; edited by Wayne Smith, 4/2009 * @version 1a5 */ public class ContactBook { /** The list of contacts */ List* @return A String suitable for use with Javascript */ public String toString() { String string = new String(); string += ""; for(LatLng point : listOfContacts) { string += " map.addOverlay(new GMarker(new GLatLng(_point_)));\n"; string = string.replaceAll("_point_", point.toString()); } string += " "; return string; } /** * This is the test method for the class. * @param args */ public static void main(String[] args) { // Create a new ContactBook object ContactBook contacts = new ContactBook(); // Add a few test data points from Andrew 1992 contacts.addContact(new LatLng(10.8, -35.5)); contacts.addContact(new LatLng(25.6, -67.0)); contacts.addContact(new LatLng(29.2, -91.3)); // Test the toString() method System.out.println(contacts); } }