From 36ab739edb1cd0323e9478739dd3ea93b444e3af Mon Sep 17 00:00:00 2001
From: Luc Maisonobe <luc@orekit.org>
Date: Tue, 22 Apr 2014 17:21:51 +0200
Subject: [PATCH] Replaced setGeneralContext with constructors.

---
 .../java/org/orekit/rugged/api/Rugged.java    | 45 +++++++++----------
 .../org/orekit/rugged/api/RuggedTest.java     | 39 ++++++++--------
 2 files changed, 38 insertions(+), 46 deletions(-)

diff --git a/src/main/java/org/orekit/rugged/api/Rugged.java b/src/main/java/org/orekit/rugged/api/Rugged.java
index ab77fe3e..b2600d02 100644
--- a/src/main/java/org/orekit/rugged/api/Rugged.java
+++ b/src/main/java/org/orekit/rugged/api/Rugged.java
@@ -56,35 +56,28 @@ import org.orekit.utils.PVCoordinatesProvider;
 public class Rugged {
 
     /** Reference date. */
-    private AbsoluteDate referenceDate;
+    private final AbsoluteDate referenceDate;
 
     /** Inertial frame. */
-    private Frame frame;
+    private final Frame frame;
 
     /** Reference ellipsoid. */
-    private ExtendedEllipsoid ellipsoid;
+    private final ExtendedEllipsoid ellipsoid;
 
     /** Converter between spacecraft and body. */
-    private SpacecraftToObservedBody scToBody;
+    private final SpacecraftToObservedBody scToBody;
 
     /** Sensors. */
     private final Map<String, Sensor> sensors;
 
     /** DEM intersection algorithm. */
-    private IntersectionAlgorithm algorithm;
+    private final IntersectionAlgorithm algorithm;
 
-    /** Simple constructor.
-     */
-    protected Rugged() {
-        sensors = new HashMap<String, Sensor>();
-    }
-
-    /** Set up general context.
+    /** Build a configured instance.
      * <p>
      * This method is the first one that must be called, otherwise the
      * other methods will fail due to uninitialized context.
      * </p>
-     * @param orekitDataDir top directory for Orekit data
      * @param referenceDate reference date from which all other dates are computed
      * @param algorithmID identifier of algorithm to use for Digital Elevation Model intersection
      * @param ellipsoidID identifier of reference ellipsoid
@@ -96,12 +89,11 @@ public class Rugged {
      * @param aInterpolationOrder order to use for attitude interpolation
      * @exception RuggedException if data needed for some frame cannot be loaded
      */
-    public  void setGeneralContext(final AbsoluteDate newReferenceDate,
-                                   final AlgorithmId algorithmID, final EllipsoidId ellipsoidID,
-                                   final InertialFrameId inertialFrameID,
-                                   final BodyRotatingFrameId bodyRotatingFrameID,
-                                   final List<Pair<AbsoluteDate, PVCoordinates>> positionsVelocities, final int pvInterpolationOrder,
-                                   final List<Pair<AbsoluteDate, Rotation>> quaternions, final int aInterpolationOrder)
+    public Rugged(final AbsoluteDate newReferenceDate,
+                  final AlgorithmId algorithmID, final EllipsoidId ellipsoidID,
+                  final InertialFrameId inertialFrameID, final BodyRotatingFrameId bodyRotatingFrameID,
+                  final List<Pair<AbsoluteDate, PVCoordinates>> positionsVelocities, final int pvInterpolationOrder,
+                  final List<Pair<AbsoluteDate, Rotation>> quaternions, final int aInterpolationOrder)
         throws RuggedException {
         try {
 
@@ -120,12 +112,14 @@ public class Rugged {
             // intersection algorithm
             algorithm = selectAlgorithm(algorithmID);
 
+            sensors = new HashMap<String, Sensor>();
+
         } catch (OrekitException oe) {
             throw new RuggedException(oe, oe.getSpecifier(), oe.getParts().clone());
         }
     }
 
-    /** Set up general context.
+    /** Build a configured instance.
      * <p>
      * This method is the first one that must be called, otherwise the
      * other methods will fail due to uninitialized context.
@@ -138,11 +132,10 @@ public class Rugged {
      * @param propagator global propagator
      * @exception RuggedException if data needed for some frame cannot be loaded
      */
-    public void setGeneralContext(final AbsoluteDate newReferenceDate,
-                                  final AlgorithmId algorithmID, final EllipsoidId ellipsoidID,
-                                  final InertialFrameId inertialFrameID,
-                                  final BodyRotatingFrameId bodyRotatingFrameID,
-                                  final Propagator propagator)
+    public Rugged(final AbsoluteDate newReferenceDate,
+                  final AlgorithmId algorithmID, final EllipsoidId ellipsoidID,
+                  final InertialFrameId inertialFrameID, final BodyRotatingFrameId bodyRotatingFrameID,
+                  final Propagator propagator)
         throws RuggedException {
         try {
 
@@ -160,6 +153,8 @@ public class Rugged {
             // intersection algorithm
             algorithm = selectAlgorithm(algorithmID);
 
+            sensors = new HashMap<String, Sensor>();
+
         } catch (OrekitException oe) {
             throw new RuggedException(oe, oe.getSpecifier(), oe.getParts().clone());
         }
diff --git a/src/test/java/org/orekit/rugged/api/RuggedTest.java b/src/test/java/org/orekit/rugged/api/RuggedTest.java
index 3132e1cb..279ce356 100644
--- a/src/test/java/org/orekit/rugged/api/RuggedTest.java
+++ b/src/test/java/org/orekit/rugged/api/RuggedTest.java
@@ -138,13 +138,12 @@ public class RuggedTest {
             createQ(t0,19.000, 0.522119033749, -0.395304129256,  0.577847874330,  0.487050504694),
             createQ(t0,20.000, 0.522421006719, -0.395049578765,  0.577574493570,  0.487257453954));
 
-        Rugged rugged = new Rugged();
-        rugged.setGeneralContext(t0,
-                                 AlgorithmId.DUVENHAGE,
-                                 EllipsoidId.WGS84,
-                                 InertialFrameId.EME2000,
-                                 BodyRotatingFrameId.ITRF,
-                                 pv, 8, q, 8);
+        Rugged rugged = new Rugged(t0,
+                                   AlgorithmId.DUVENHAGE,
+                                   EllipsoidId.WGS84,
+                                   InertialFrameId.EME2000,
+                                   BodyRotatingFrameId.ITRF,
+                                   pv, 8, q, 8);
 
         Assert.assertEquals(new AbsoluteDate("2012-01-01T00:00:00", TimeScalesFactory.getUTC()),
                             rugged.getReferenceDate());
@@ -162,13 +161,12 @@ public class RuggedTest {
         Orbit      orbit                                  = createOrbit(gravityField);
         Propagator propagator                             = createPropagator(earth, gravityField, orbit);
 
-        Rugged rugged = new Rugged();
-        rugged.setGeneralContext(propagator.getInitialState().getDate(),
-                                 AlgorithmId.DUVENHAGE,
-                                 EllipsoidId.WGS84,
-                                 InertialFrameId.EME2000,
-                                 BodyRotatingFrameId.ITRF,
-                                 propagator);
+        Rugged rugged = new Rugged(propagator.getInitialState().getDate(),
+                                   AlgorithmId.DUVENHAGE,
+                                   EllipsoidId.WGS84,
+                                   InertialFrameId.EME2000,
+                                   BodyRotatingFrameId.ITRF,
+                                   propagator);
 
         Assert.assertEquals(propagator.getInitialState().getDate(), rugged.getReferenceDate());
 
@@ -213,13 +211,12 @@ public class RuggedTest {
         propagator.propagate(crossing.shiftedBy(lineDatation.getDate(lastLine) + 1.0));
         Propagator ephemeris = propagator.getGeneratedEphemeris();
 
-        Rugged rugged = new Rugged();
-        rugged.setGeneralContext(crossing,
-                                 AlgorithmId.DUVENHAGE,
-                                 EllipsoidId.WGS84,
-                                 InertialFrameId.EME2000,
-                                 BodyRotatingFrameId.ITRF,
-                                 ephemeris);
+        Rugged rugged = new Rugged(crossing,
+                                   AlgorithmId.DUVENHAGE,
+                                   EllipsoidId.WGS84,
+                                   InertialFrameId.EME2000,
+                                   BodyRotatingFrameId.ITRF,
+                                   ephemeris);
         rugged.setUpTilesManagement(updater, 8);
 
         rugged.setLineSensor("line", los, lineDatation);
-- 
GitLab