Worldwind public release 0.2
[worldwind-tracker.git] / gov / nasa / worldwind / TrackPointIteratorImpl.java
blobfd1a254cb48423633b3df79fe79ac763869c933f
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind;
9 import java.util.*;
11 /**
12 * @author tag
13 * @version $Id$
15 public class TrackPointIteratorImpl implements TrackPointIterator
17 private java.util.List<Track> tracksList;
18 private java.util.Iterator<Track> tracks;
19 private java.util.Iterator<TrackSegment> segments;
20 private java.util.Iterator<TrackPoint> positions;
22 public TrackPointIteratorImpl(java.util.List<Track> tracksList)
24 this.tracksList = tracksList;
25 this.reset();
28 public TrackPointIteratorImpl reset()
30 if (this.tracksList == null)
32 String msg = WorldWind.retrieveErrMsg("nullValue.TracksIsNull");
33 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
34 throw new IllegalArgumentException(msg);
37 this.tracks = this.tracksList.iterator();
38 this.segments = null;
39 this.positions = null;
40 this.loadNextPositions();
42 return this;
45 public boolean hasNext()
47 if (this.positions != null && this.positions.hasNext())
48 return true;
50 this.loadNextPositions();
52 return (this.positions != null && this.positions.hasNext());
55 private void loadNextPositions()
57 if (this.segments != null && this.segments.hasNext())
59 TrackSegment segment = this.segments.next();
60 this.positions = segment.getPoints().iterator();
61 return;
64 if (this.tracks.hasNext())
66 Track track = this.tracks.next();
67 this.segments = track.getSegments().iterator();
68 this.loadNextPositions();
72 public TrackPoint next()
74 if (!this.hasNext())
76 String msg = WorldWind.retrieveErrMsg("iterator.NoMoreTrackPoints");
77 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
78 throw new NoSuchElementException(msg);
81 return this.positions.next();
84 public void remove()
86 String msg = WorldWind.retrieveErrMsg("iterator.RemoveNotSupported");
87 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
88 throw new UnsupportedOperationException(msg);
91 public int getNumPoints()
93 int numPoints;
94 for (numPoints = 0; this.hasNext(); this.next())
95 ++numPoints;
97 return numPoints;