
package uk.co.wingpath.gpx;

import java.io.*;
import java.util.*;
import uk.co.wingpath.xml.*;

// A Track Segment holds a list of Track Points which are logically
// connected in order. To represent a single GPS track where GPS reception was
// lost, or the GPS receiver was turned off, start a new Track Segment for each
// continuous span of track data.

public class TrackSegment
    implements Xml.Savable, Xml.Loader
{
    private List<Waypoint> trkpt;

    public TrackSegment ()
    {
        trkpt = new ArrayList<Waypoint> ();
    }

	public void add (Waypoint wpt)
    {
        trkpt.add (wpt);
    }

    public List<Waypoint> getPoints ()
    {
        return trkpt;
    }

    public Xml.Loader startChild (String tag)
    {
        if (tag.equalsIgnoreCase ("trkpt"))
        {
            Waypoint l = new Waypoint ();
            trkpt.add (l);
            return l;
        }
        return null;
    }

    public void attribute (String attr, String value)
    {
    }

    public void end (String value)
    {
    }

    public void cleanup ()
    {
    }

    public void save (Xml.Saver saver)
        throws IOException
    {
        for (Waypoint w : trkpt)
            saver.saveValue ("trkpt", w);
    }
}

