import java.util.ArrayList; import java.util.List; /** *

* This class represents the data points for a given storm track. * 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 * @version 1a4 */ public class StormTrack { /** The list of points describing a storm track */ List list; public StormTrack() { super(); list = new ArrayList(); } public void addSample(LatLng sample) { list.add(sample); } /** Create a Javascript array by iterating through each point in the storm track. * The string must be surrounded with square brackets to form a valid * Javascript array.
*
* For example:
*
* [ new GLatLng(10.8, -35.5), new GLatLng(25.6, -67.0), new GLatLng(29.2, -91.3) ] *

* @return A String suitable for use with Javascript */ public String toString() { String string = new String(); string += "["; for(LatLng point : list) { string += " new GLatLng(_point_),"; 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 StormTrack object StormTrack track = new StormTrack(); // Add a few test data points from Andrew 1992 track.addSample(new LatLng(10.8, -35.5)); track.addSample(new LatLng(25.6, -67.0)); track.addSample(new LatLng(29.2, -91.3)); // Test the toString() method System.out.println(track); } }