Commit 81679b3b authored by Luc Maisonobe's avatar Luc Maisonobe

Merge branch 'issue-411' into develop

parents 4e8e394a 8c3c2d83
......@@ -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.
......
......@@ -41,7 +41,7 @@ public class DataProvidersManagerTest {
DataProvidersManager.getInstance().clearProviders();
Assert.assertFalse(DataProvidersManager.getInstance().isSupported(new DirectoryCrawler(new File(getPath("regular-data")))));
Assert.assertTrue(DataProvidersManager.getInstance().feed(".*", crawler));
Assert.assertEquals(22, crawler.getCount());
Assert.assertEquals(18, crawler.getCount());
}
@Test
......@@ -53,13 +53,17 @@ public class DataProvidersManagerTest {
Assert.assertFalse(manager.isSupported(new DirectoryCrawler(new File(getPath("regular-data")))));
Assert.assertEquals(0, manager.getLoadedDataNames().size());
CountingLoader tleCounter = new CountingLoader(false);
Assert.assertTrue(manager.feed(".*\\.tle$", tleCounter));
Assert.assertEquals(4, tleCounter.getCount());
Assert.assertEquals(4, manager.getLoadedDataNames().size());
Assert.assertFalse(manager.feed(".*\\.tle$", tleCounter));
Assert.assertEquals(0, tleCounter.getCount());
Assert.assertEquals(0, manager.getLoadedDataNames().size());
CountingLoader txtCounter = new CountingLoader(false);
Assert.assertTrue(manager.feed(".*\\.txt$", txtCounter));
Assert.assertEquals(5, txtCounter.getCount());
Assert.assertEquals(5, manager.getLoadedDataNames().size());
CountingLoader de405Counter = new CountingLoader(false);
Assert.assertTrue(manager.feed(".*\\.405$", de405Counter));
Assert.assertEquals(4, de405Counter.getCount());
Assert.assertEquals(8, manager.getLoadedDataNames().size());
Assert.assertEquals(9, manager.getLoadedDataNames().size());
manager.clearLoadedDataNames();
Assert.assertEquals(0, manager.getLoadedDataNames().size());
}
......@@ -75,7 +79,7 @@ public class DataProvidersManagerTest {
} catch (OrekitException oe) {
// expected
}
Assert.assertEquals(22, crawler.getCount());
Assert.assertEquals(18, crawler.getCount());
}
@Test
......@@ -190,9 +194,9 @@ public class DataProvidersManagerTest {
DataProvidersManager.getInstance().addFilter(filter);
CountingLoader crawler = new CountingLoader(false);
Assert.assertTrue(DataProvidersManager.getInstance().feed(".*", crawler));
Assert.assertEquals(22, crawler.getCount());
Assert.assertEquals(22, filter.getFilteredCount());
Assert.assertEquals(22, filter.getOpenedCount());
Assert.assertEquals(18, crawler.getCount());
Assert.assertEquals(18, filter.getFilteredCount());
Assert.assertEquals(18, filter.getOpenedCount());
}
@Test
......@@ -203,8 +207,8 @@ public class DataProvidersManagerTest {
DataProvidersManager.getInstance().addFilter(filter);
CountingLoader crawler = new CountingLoader(false);
Assert.assertTrue(DataProvidersManager.getInstance().feed(".*", crawler));
Assert.assertEquals(22, crawler.getCount());
Assert.assertEquals(22 * layers, filter.getOpenedCount());
Assert.assertEquals(18, crawler.getCount());
Assert.assertEquals(18 * layers, filter.getOpenedCount());
}
private static class CountingLoader implements DataLoader {
......
......@@ -247,9 +247,23 @@ 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");
Utils.setDataRoot("regular-data:tle/tle-series");
}
}
\ No newline at end of file
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