From e672586628fa7f500d391bb2e4de4f399de89846 Mon Sep 17 00:00:00 2001 From: erik Date: Sat, 26 Sep 2009 11:59:23 +0000 Subject: [PATCH] --- .../org/wamblee/gps/track/FilteredTrack.java | 63 +++++++++++++++++++ .../org/wamblee/gps/track/TrackFilter.java | 18 ++++++ 2 files changed, 81 insertions(+) create mode 100644 trunk/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java create mode 100644 trunk/gps/src/main/java/org/wamblee/gps/track/TrackFilter.java diff --git a/trunk/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java b/trunk/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java new file mode 100644 index 00000000..ddcaa496 --- /dev/null +++ b/trunk/gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java @@ -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 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/trunk/gps/src/main/java/org/wamblee/gps/track/TrackFilter.java b/trunk/gps/src/main/java/org/wamblee/gps/track/TrackFilter.java new file mode 100644 index 00000000..e5e7bfe5 --- /dev/null +++ b/trunk/gps/src/main/java/org/wamblee/gps/track/TrackFilter.java @@ -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); +} -- 2.31.1