Commit 8c3c2d83 authored by Luc Maisonobe's avatar Luc Maisonobe

Allow several TLE with same date in TLESeries.

Fixes issue #411.
parent d2cf7343
......@@ -20,6 +20,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
......@@ -27,9 +28,9 @@ import java.util.TreeSet;
import org.orekit.data.DataLoader;
import org.orekit.data.DataProvidersManager;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitInternalError;
import org.orekit.errors.OrekitMessages;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.ChronologicalComparator;
import org.orekit.time.TimeStamped;
import org.orekit.utils.PVCoordinates;
......@@ -125,7 +126,7 @@ public class TLESeries implements DataLoader {
filterLaunchNumber = -1;
filterLaunchPiece = null;
tles = new TreeSet<TimeStamped>(new ChronologicalComparator());
tles = new TreeSet<TimeStamped>(new TLEComparator());
previous = null;
next = null;
......@@ -418,4 +419,29 @@ public class TLESeries implements DataLoader {
return (TLE) tles.last();
}
/** Comparator allowing different TLEs at same date (see issue 411).
* @since 9.2
*/
private static class TLEComparator implements Comparator<TimeStamped> {
/** {@inheritDoc} */
@Override
public int compare(final TimeStamped timeStamped1, final TimeStamped timeStamped2) {
final int dateCompare = timeStamped1.getDate().compareTo(timeStamped2.getDate());
if (dateCompare == 0 && timeStamped1 instanceof TLE && timeStamped2 instanceof TLE) {
try {
final TLE tle1 = (TLE) timeStamped1;
final TLE tle2 = (TLE) timeStamped2;
final int line1Compare = tle1.getLine1().compareTo(tle2.getLine1());
return (line1Compare == 0) ?
tle1.getLine2().compareTo(tle2.getLine2()) :
line1Compare;
} catch (OrekitException oe) {
// this should never happen
throw new OrekitInternalError(oe);
}
}
return dateCompare;
}
}
}
......@@ -21,6 +21,10 @@
</properties>
<body>
<release version="9.2" date="TBD" description="TBD">
<action dev="luc" type="fix">
Allow several TLE with same date in TLESeries.
Fixes issue #411.
</action>
<action dev="luc" type="fix">
Fixed compilation problems with JDK 1.8
Fixes issue #462.
......
......@@ -247,6 +247,20 @@ public class TLESeriesTest {
Assert.assertEquals(tleFrame.getName(), FramesFactory.getFrame(Predefined.TEME).getName());
}
@Test
public void testIssue411() throws IOException, OrekitException {
TLESeries series = new TLESeries("^same-date-tle.txt$", false);
series.loadTLEData(-1);
TLE first = series.getFirst();
TLE last = series.getLast();
Assert.assertEquals(16908, first.getSatelliteNumber());
Assert.assertEquals(16908, last.getSatelliteNumber());
Assert.assertNotSame(first, last);
}
@Before
public void setUp() {
Utils.setDataRoot("regular-data:tle/tle-series");
......
1 16908U 86061A 08034.91387914 -.00000083 00000-0 10000-3 0 9998
2 16908 050.0095 254.1054 0011516 027.3846 332.7593 12.44459732645435
1 16908U 86061A 08034.91387914 -.00000083 +00000-0 +10000-3 0 9998
2 16908 050.0095 254.1054 0011516 027.3846 332.7593 12.44459732645435
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