(no commit message)
authorErik Brakkee <erik@brakkee.org>
Sat, 26 Sep 2009 11:59:23 +0000 (11:59 +0000)
committerErik Brakkee <erik@brakkee.org>
Sat, 26 Sep 2009 11:59:23 +0000 (11:59 +0000)
gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java [new file with mode: 0644]
gps/src/main/java/org/wamblee/gps/track/TrackFilter.java [new file with mode: 0644]

diff --git a/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java b/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java
new file mode 100644 (file)
index 0000000..ddcaa49
--- /dev/null
@@ -0,0 +1,63 @@
+package org.wamblee.gps.track;
+
+import java.util.List;
+
+import org.wamblee.gps.geometry.Point;
+
+/**
+ * Filtered track provides a filtered view on a track. 
+ * Changes in the filter are also represented by the filtered track. 
+ */
+public class FilteredTrack implements Track {
+    
+    private TrackFilter _filter; 
+    private Track _originalTrack;
+    private Track _filteredTrack; 
+    private int _lastVersion; 
+    
+    public FilteredTrack(TrackFilter aFilter, Track aTrack) { 
+        _filter = aFilter; 
+        _originalTrack = aTrack;
+        _filteredTrack = _filter.filter(_originalTrack);
+        _lastVersion = aFilter.version();
+    }
+    
+    private Track getTrack() { 
+        if ( _lastVersion != _filter.version()) { 
+            _filteredTrack = _filter.filter(_originalTrack);
+            _lastVersion = _filter.version();
+        }
+        return _filteredTrack;
+    }
+    
+    @Override
+    public List<TrackSegment> getSegments() {
+        return getTrack().getSegments();
+    }
+
+    @Override
+    public String getDescription() {
+        return getTrack().getDescription();
+    }
+
+    @Override
+    public double getMaxCoordinate(int aI) {
+        return getTrack().getMaxCoordinate(aI);
+    }
+
+    @Override
+    public double getMinCoordinate(int aI) {
+        return getTrack().getMinCoordinate(aI);
+    }
+
+    @Override
+    public Point getPoint(int aIndex) {
+        return getTrack().getPoint(aIndex);
+    }
+
+    @Override
+    public int size() {
+        return getTrack().size();
+    }
+
+}
diff --git a/gps/src/main/java/org/wamblee/gps/track/TrackFilter.java b/gps/src/main/java/org/wamblee/gps/track/TrackFilter.java
new file mode 100644 (file)
index 0000000..e5e7bfe
--- /dev/null
@@ -0,0 +1,18 @@
+package org.wamblee.gps.track;
+
+public interface TrackFilter {
+
+    /**
+     * Version number of the track filter. If the version changes then the 
+     * filter has been modified.
+     * @return Version. 
+     */
+    int version(); 
+    
+    /**
+     * Filter the track. 
+     * @param aTrack Track to filter.
+     * @return Filtered track.
+     */
+    Track filter(Track aTrack);
+}