Commit 03e5b1b6 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Deprecate getTransitions in TimeSpanMap.

Fixes #884
parent aa0e7f6d
......@@ -383,7 +383,7 @@ public class AttitudesSequence implements AttitudeProvider {
// reset the transition parameters (this will be done once for each switch,
// despite doing it only once would have sufficient; its not really a problem)
forward = t.durationFrom(s0.getDate()) >= 0.0;
if (activated.getTransitions().size() > 1) {
if (activated.getTransitionsNumber() > 0) {
// remove transitions that will be overridden during upcoming propagation
if (forward) {
activated = activated.extractRange(AbsoluteDate.PAST_INFINITY, s0.getDate().shiftedBy(transitionTime));
......
......@@ -239,7 +239,7 @@ public class SinexLoader {
final Station station = getStation(parseString(line, 1, 4));
// check if it is the first eccentricity entry for this station
if (station.getEccentricitiesTimeSpanMap().getTransitions().size() == 1) {
if (station.getEccentricitiesTimeSpanMap().getTransitionsNumber() == 0) {
// we are parsing eccentricity data for a new station
firstEcc = true;
}
......
......@@ -118,7 +118,7 @@ public class Station {
*/
public AbsoluteDate getValidFrom() {
if (validFrom == null) {
validFrom = eccentricitiesTimeSpanMap.getTransitions().first().getDate();
validFrom = eccentricitiesTimeSpanMap.getFirstTransition().getDate();
}
return validFrom;
}
......@@ -137,7 +137,7 @@ public class Station {
*/
public AbsoluteDate getValidUntil() {
if (validUntil == null) {
validUntil = eccentricitiesTimeSpanMap.getTransitions().last().getDate();
validUntil = eccentricitiesTimeSpanMap.getLastTransition().getDate();
}
return validUntil;
}
......
......@@ -21,8 +21,8 @@ import java.util.List;
import java.util.NavigableSet;
import java.util.stream.Stream;
import org.hipparchus.Field;
import org.hipparchus.CalculusFieldElement;
import org.hipparchus.Field;
import org.hipparchus.analysis.differentiation.DerivativeStructure;
import org.hipparchus.analysis.differentiation.Gradient;
import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
......@@ -232,11 +232,21 @@ public class TimeSpanDragForce extends AbstractDragForceModel {
/** Get the {@link Transition}s of the drag sensitive time span map.
* @return the {@link Transition}s for the drag sensitive time span map
* @deprecated as of 11.1, replaced by {@link #getFirstSpan()}
*/
@Deprecated
public NavigableSet<Transition<DragSensitive>> getTransitions() {
return dragSensitiveTimeSpanMap.getTransitions();
}
/** Get the first {@link Span time span} of the drag sensitive time span map.
* @return the first {@link Span time span} of the drag sensitive time span map
* @since 11.1
*/
public Span<DragSensitive> getFirstSpan() {
return dragSensitiveTimeSpanMap.getFirstSpan();
}
/** {@inheritDoc} */
@Override
public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {
......@@ -362,25 +372,17 @@ public class TimeSpanDragForce extends AbstractDragForceModel {
// Get all transitions from the TimeSpanMap
final List<ParameterDriver> listParameterDrivers = new ArrayList<>();
final NavigableSet<Transition<DragSensitive>> dragSensitiveTransitions = getTransitions();
// Loop on the transitions
for (Transition<DragSensitive> transition : dragSensitiveTransitions) {
// Add all the "before" parameter drivers of each transition
for (ParameterDriver driver : transition.getBefore().getDragParametersDrivers()) {
// Loop on the spans
for (Span<DragSensitive> span = getFirstSpan(); span != null; span = span.next()) {
// Add all the parameter drivers of the span
for (ParameterDriver driver : span.getData().getDragParametersDrivers()) {
// Add the driver only if the name does not exist already
if (!findByName(listParameterDrivers, driver.getName())) {
listParameterDrivers.add(driver);
}
}
}
// Finally, add the "after" parameter drivers of the last transition
for (ParameterDriver driver : dragSensitiveTransitions.last().getAfter().getDragParametersDrivers()) {
// Adds only if the name does not exist already
if (!findByName(listParameterDrivers, driver.getName())) {
listParameterDrivers.add(driver);
}
}
// Return an array of parameter drivers with no duplicated name
return listParameterDrivers;
......
......@@ -221,11 +221,21 @@ public class TimeSpanParametricAcceleration extends AbstractForceModel {
/** Get the {@link Transition}s of the acceleration model time span map.
* @return the {@link Transition}s for the acceleration model time span map
* @deprecated as of 11.1, replace by {@link #getFirstSpan()}
*/
@Deprecated
public NavigableSet<Transition<AccelerationModel>> getTransitions() {
return accelerationModelTimeSpanMap.getTransitions();
}
/** Get the first {@link Span time span} of the acceleration model time span map.
* @return the first {@link Span time span} of the acceleration model time span map
* @since 11.1
*/
public Span<AccelerationModel> getFirstSpan() {
return accelerationModelTimeSpanMap.getFirstSpan();
}
/** {@inheritDoc} */
@Override
public boolean dependsOnPositionOnly() {
......@@ -321,12 +331,11 @@ public class TimeSpanParametricAcceleration extends AbstractForceModel {
// Get all transitions from the TimeSpanMap
final List<ParameterDriver> listParameterDrivers = new ArrayList<>();
final NavigableSet<Transition<AccelerationModel>> accelerationModelTransitions = getTransitions();
// Loop on the transitions
for (Transition<AccelerationModel> transition : accelerationModelTransitions) {
// Add all the "before" parameter drivers of each transition
for (ParameterDriver driver : transition.getBefore().getParametersDrivers()) {
// Loop on the spans
for (Span<AccelerationModel> span = getFirstSpan(); span != null; span = span.next()) {
// Add all the parameter drivers of the time span
for (ParameterDriver driver : span.getData().getParametersDrivers()) {
// Add the driver only if the name does not exist already
if (!findByName(listParameterDrivers, driver.getName())) {
listParameterDrivers.add(driver);
......@@ -334,14 +343,6 @@ public class TimeSpanParametricAcceleration extends AbstractForceModel {
}
}
// Finally, add the "after" parameter drivers of the last transition
for (ParameterDriver driver : accelerationModelTransitions.last().getAfter().getParametersDrivers()) {
// Adds only if the name does not exist already
if (!findByName(listParameterDrivers, driver.getName())) {
listParameterDrivers.add(driver);
}
}
// Return an array of parameter drivers with no duplicated name
return Collections.unmodifiableList(listParameterDrivers);
......
......@@ -133,7 +133,7 @@ public class AntexLoader {
satellitesAntennas.
stream().
filter(m -> {
final SatelliteAntenna first = m.getTransitions().first().getBefore();
final SatelliteAntenna first = m.getFirstSpan().getData();
return first.getSatelliteSystem() == satelliteSystem &&
first.getPrnNumber() == prnNumber;
}).findFirst();
......
......@@ -31,6 +31,7 @@ import org.orekit.time.TimeScale;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.ParameterDriver;
import org.orekit.utils.TimeSpanMap;
import org.orekit.utils.TimeSpanMap.Span;
import org.orekit.utils.TimeSpanMap.Transition;
/**
......@@ -89,25 +90,17 @@ public class TimeSpanEstimatedTroposphericModel implements DiscreteTroposphericM
// Get all transitions from the TimeSpanMap
final List<ParameterDriver> listTroposphericParameterDrivers = new ArrayList<>();
final NavigableSet<Transition<EstimatedTroposphericModel>> troposphericModelTransitions = getTransitions();
// Loop on the transitions
for (Transition<EstimatedTroposphericModel> transition : troposphericModelTransitions) {
// Add all the "before" parameter drivers of each transition
for (ParameterDriver tropoDriver : transition.getBefore().getParametersDrivers()) {
// Loop on the spans
for (Span<EstimatedTroposphericModel> span = getFirstSpan(); span != null; span = span.next()) {
// Add all the parameter drivers of each span
for (ParameterDriver tropoDriver : span.getData().getParametersDrivers()) {
// Add the driver only if the name does not exist already
if (!findByName(listTroposphericParameterDrivers, tropoDriver.getName())) {
listTroposphericParameterDrivers.add(tropoDriver);
}
}
}
// Finally, add the "after" parameter drivers of the last transition
for (ParameterDriver tropoDriver : troposphericModelTransitions.last().getAfter().getParametersDrivers()) {
// Adds only if the name does not exist already
if (!findByName(listTroposphericParameterDrivers, tropoDriver.getName())) {
listTroposphericParameterDrivers.add(tropoDriver);
}
}
// Return an array of parameter drivers with no duplicated name
return listTroposphericParameterDrivers;
......@@ -152,11 +145,21 @@ public class TimeSpanEstimatedTroposphericModel implements DiscreteTroposphericM
/** Get the {@link Transition}s of the tropospheric model time span map.
* @return the {@link Transition}s for the tropospheric model time span map
* @deprecated as of 11.1, replaced by {@link #getFirstSpan()}
*/
@Deprecated
public NavigableSet<Transition<EstimatedTroposphericModel>> getTransitions() {
return troposphericModelMap.getTransitions();
}
/** Get the first {@link Span time span} of the tropospheric model time span map.
* @return the first {@link Span time span} of the tropospheric model time span map
* @since 11.1
*/
public Span<EstimatedTroposphericModel> getFirstSpan() {
return troposphericModelMap.getFirstSpan();
}
/** Extract the proper parameter drivers' values from the array in input of the
* {@link #pathDelay(double, GeodeticPoint, double[], AbsoluteDate) pathDelay} method.
* Parameters are filtered given an input date.
......
......@@ -89,6 +89,14 @@ public class TimeSpanMap<T> {
}
/** Get the number of transitions.
* @return number of transitions
* @since 11.1
*/
public int getTransitionsNumber() {
return hasSingleDummyTransition() ? 0 : data.size();
}
/** Check if the map has a single dummy transition.
* @return true if the transition has a single dummy transition
* @since 11.1
......@@ -374,7 +382,10 @@ public class TimeSpanMap<T> {
/** Get an unmodifiable view of the sorted transitions.
* @return unmodifiable view of the sorted transitions
* @deprecated as of 11.1, replaced by {@link #getFirstSpan()}, {@link #getLastSpan()},
* {@link #getFirstTransition()}, {@link #getLastTransition()}, and {@link #getTransitionsNumber()}
*/
@Deprecated
public NavigableSet<Transition<T>> getTransitions() {
return Collections.unmodifiableNavigableSet(data);
}
......
......@@ -681,7 +681,7 @@ public class ClockFileParserTest {
final AbsoluteDate endDate2 = new AbsoluteDate(1994, 7, 14, 21, 59, 0.0, gps);
// Check number of time spans
Assert.assertEquals(1, referenceClocksMap.getTransitions().size());
Assert.assertEquals(1, referenceClocksMap.getTransitionsNumber());
// Get the two lists of reference clocks
final List<ReferenceClock> referenceClocks1 = referenceClocksMap.get(new AbsoluteDate(1994, 7, 14, 15, 0, 0.0, gps));
......
......@@ -40,6 +40,7 @@ public class TimeSpanMapTest {
Assert.assertSame(single, map.get(AbsoluteDate.JULIAN_EPOCH));
Assert.assertSame(single, map.get(AbsoluteDate.MODIFIED_JULIAN_EPOCH));
Assert.assertSame(single, map.get(AbsoluteDate.PAST_INFINITY));
Assert.assertEquals(0, map.getTransitionsNumber());
}
@Test
......@@ -93,7 +94,7 @@ public class TimeSpanMapTest {
@Deprecated
@Test
public void testDeprecated() {
public void testDeprecatedAddValid() {
final AbsoluteDate ref = AbsoluteDate.J2000_EPOCH;
TimeSpanMap<Integer> map = new TimeSpanMap<>(Integer.valueOf(0));
map.addValidAfter(Integer.valueOf(10), ref.shiftedBy(10.0));
......@@ -115,6 +116,15 @@ public class TimeSpanMapTest {
Assert.assertEquals(10, map.get(ref.shiftedBy(100.0)).intValue());
}
@Deprecated
@Test
public void testDeprecatedNavigableMap() {
TimeSpanMap<Integer> map = new TimeSpanMap<>(Integer.valueOf(0));
Assert.assertEquals(0, map.getTransitionsNumber());
Assert.assertEquals(1, map.getTransitions().size());
Assert.assertSame(AbsoluteDate.ARBITRARY_EPOCH, map.getTransitions().first().getDate());
}
@Test
public void testRandomAddNoErase() {
final AbsoluteDate ref = AbsoluteDate.J2000_EPOCH;
......@@ -139,6 +149,7 @@ public class TimeSpanMapTest {
final StringBuilder builder = new StringBuilder();
map.forEach(i -> builder.append(' ').append(i));
Assert.assertEquals(" 0 2 3 5 9 10", builder.toString());
Assert.assertEquals(5, map.getTransitionsNumber());
}
@Test
......@@ -169,6 +180,7 @@ public class TimeSpanMapTest {
final StringBuilder builder = new StringBuilder();
map.forEach(i -> builder.append(' ').append(i));
Assert.assertEquals(" 5 7", builder.toString());
Assert.assertEquals(3, map.getTransitionsNumber());
}
@Test
......@@ -181,7 +193,7 @@ public class TimeSpanMapTest {
map.addValidBefore(Integer.valueOf( 2), ref.shiftedBy( 3.0), false);
map.addValidBefore(Integer.valueOf( 5), ref.shiftedBy( 9.0), false);
TimeSpanMap<Integer> range = map.extractRange(AbsoluteDate.PAST_INFINITY, AbsoluteDate.FUTURE_INFINITY);
Assert.assertEquals(map.getTransitions().size(), range.getTransitions().size());
Assert.assertEquals(map.getTransitionsNumber(), range.getTransitionsNumber());
}
@Test
......@@ -194,7 +206,7 @@ public class TimeSpanMapTest {
map.addValidBefore(Integer.valueOf( 2), ref.shiftedBy( 3.0), false);
map.addValidBefore(Integer.valueOf( 5), ref.shiftedBy( 9.0), false);
TimeSpanMap<Integer> range = map.extractRange(ref.shiftedBy(6), ref.shiftedBy(8));
Assert.assertEquals(1, range.getTransitions().size());
Assert.assertEquals(0, range.getTransitionsNumber());
Assert.assertEquals(5, range.get(ref.shiftedBy(-10000)).intValue());
Assert.assertEquals(5, range.get(ref.shiftedBy(+10000)).intValue());
}
......@@ -209,7 +221,7 @@ public class TimeSpanMapTest {
map.addValidBefore(Integer.valueOf( 2), ref.shiftedBy( 3.0), false);
map.addValidBefore(Integer.valueOf( 5), ref.shiftedBy( 9.0), false);
TimeSpanMap<Integer> range = map.extractRange(AbsoluteDate.PAST_INFINITY, ref.shiftedBy(8));
Assert.assertEquals(3, range.getTransitions().size());
Assert.assertEquals(3, range.getTransitionsNumber());
Assert.assertEquals( 0, range.get(ref.shiftedBy( -1.0)).intValue());
Assert.assertEquals( 0, range.get(ref.shiftedBy( 1.9)).intValue());
Assert.assertEquals( 2, range.get(ref.shiftedBy( 2.1)).intValue());
......@@ -232,7 +244,7 @@ public class TimeSpanMapTest {
map.addValidBefore(Integer.valueOf( 2), ref.shiftedBy( 3.0), false);
map.addValidBefore(Integer.valueOf( 5), ref.shiftedBy( 9.0), false);
TimeSpanMap<Integer> range = map.extractRange(ref.shiftedBy(4), AbsoluteDate.FUTURE_INFINITY);
Assert.assertEquals(3, range.getTransitions().size());
Assert.assertEquals(3, range.getTransitionsNumber());
Assert.assertEquals( 3, range.get(ref.shiftedBy(-99.0)).intValue());
Assert.assertEquals( 3, range.get(ref.shiftedBy( 4.9)).intValue());
Assert.assertEquals( 5, range.get(ref.shiftedBy( 5.1)).intValue());
......@@ -253,7 +265,7 @@ public class TimeSpanMapTest {
map.addValidBefore(Integer.valueOf( 2), ref.shiftedBy( 3.0), false);
map.addValidBefore(Integer.valueOf( 5), ref.shiftedBy( 9.0), false);
TimeSpanMap<Integer> range = map.extractRange(ref.shiftedBy(4), ref.shiftedBy(8));
Assert.assertEquals(1, range.getTransitions().size());
Assert.assertEquals(1, range.getTransitionsNumber());
Assert.assertEquals( 3, range.get(ref.shiftedBy(-99.0)).intValue());
Assert.assertEquals( 3, range.get(ref.shiftedBy( 4.9)).intValue());
Assert.assertEquals( 5, range.get(ref.shiftedBy( 5.1)).intValue());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment