consistently use getInternalRawFixes() to encapsulate fixes field;

this will allow us to have specialized WindTracks for estimations that virtualize the fixes
This commit is contained in:
Axel Uhl committed 2011-12-23 11:17:49 +01:00
1 parent 6e158de3de
commit 64a6f6533a
1 file changed
+15 -19
@@ -1,6 +1,5 @@
package com.sap.sailing.domain.tracking.impl; package com.sap.sailing.domain.tracking.impl;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.NavigableSet; import java.util.NavigableSet;
@@ -48,7 +47,7 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
/** /**
* @return the smoothened fixes; this implementation simply delegates to {@link #getFixes()} because for only * @return the smoothened fixes; this implementation simply delegates to {@link #getFixes()} because for only
* {@link Timed} fixes we can't know how to smoothen anything. Subclasses that constrain the * {@link Timed} fixes we can't know how to remove outliers. Subclasses that constrain the
* <code>FixType</code> may provide smoothening implementations. * <code>FixType</code> may provide smoothening implementations.
*/ */
protected NavigableSet<FixType> getInternalFixes() { protected NavigableSet<FixType> getInternalFixes() {
@@ -59,20 +58,19 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
/** /**
* Iterates the fixes with outliers getting skipped, in the order of their time points. * Iterates the fixes with outliers getting skipped, in the order of their time points.
* Relies on {@link #getInternalFixes()} to smoothen the track. * Relies on {@link #getInternalFixes()} to void the track view from outliers.
*/ */
@Override @Override
public Iterable<FixType> getFixes() { public NavigableSet<FixType> getFixes() {
return (Iterable<FixType>) Collections.unmodifiableSet(getInternalFixes()); return new UnmodifiableNavigableSet<FixType>(getInternalFixes());
} }
/** /**
* Iterates over the raw sequence of fixes, all potential outliers included * Iterates over the raw sequence of fixes, all potential outliers included
*/ */
@SuppressWarnings("unchecked")
@Override @Override
public NavigableSet<FixType> getRawFixes() { public NavigableSet<FixType> getRawFixes() {
return (NavigableSet<FixType>) new UnmodifiableNavigableSet<Timed>(fixes); return new UnmodifiableNavigableSet<FixType>(getInternalRawFixes());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -84,13 +82,13 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public FixType getLastRawFixAtOrBefore(TimePoint timePoint) { public FixType getLastRawFixAtOrBefore(TimePoint timePoint) {
return (FixType) fixes.floor(new DummyTimed(timePoint)); return (FixType) getInternalRawFixes().floor((FixType) new DummyTimed(timePoint));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public FixType getFirstRawFixAtOrAfter(TimePoint timePoint) { public FixType getFirstRawFixAtOrAfter(TimePoint timePoint) {
return (FixType) fixes.ceiling(new DummyTimed(timePoint)); return (FixType) getInternalRawFixes().ceiling((FixType) new DummyTimed(timePoint));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -102,7 +100,7 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public FixType getLastRawFixBefore(TimePoint timePoint) { public FixType getLastRawFixBefore(TimePoint timePoint) {
return (FixType) fixes.lower(new DummyTimed(timePoint)); return (FixType) getInternalRawFixes().lower((FixType) new DummyTimed(timePoint));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -114,26 +112,24 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public FixType getFirstRawFixAfter(TimePoint timePoint) { public FixType getFirstRawFixAfter(TimePoint timePoint) {
return (FixType) fixes.higher(new DummyTimed(timePoint)); return (FixType) getInternalRawFixes().higher((FixType) new DummyTimed(timePoint));
} }
@SuppressWarnings("unchecked")
@Override @Override
public FixType getFirstRawFix() { public FixType getFirstRawFix() {
if (fixes.isEmpty()) { if (getInternalFixes().isEmpty()) {
return null; return null;
} else { } else {
return (FixType) fixes.first(); return (FixType) getInternalFixes().first();
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public FixType getLastRawFix() { public FixType getLastRawFix() {
if (fixes.isEmpty()) { if (getInternalRawFixes().isEmpty()) {
return null; return null;
} else { } else {
return (FixType) fixes.last(); return (FixType) getInternalRawFixes().last();
} }
} }
@@ -148,8 +144,8 @@ public abstract class TrackImpl<FixType extends Timed> implements Track<FixType>
@Override @Override
public Iterator<FixType> getRawFixesIterator(TimePoint startingAt, boolean inclusive) { public Iterator<FixType> getRawFixesIterator(TimePoint startingAt, boolean inclusive) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Iterator<FixType> result = (Iterator<FixType>) fixes.tailSet( Iterator<FixType> result = (Iterator<FixType>) getInternalRawFixes().tailSet(
new DummyTimed(startingAt), inclusive).iterator(); (FixType) new DummyTimed(startingAt), inclusive).iterator();
return result; return result;
} }