AbstractBuilder.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.files.ccsds.ndm;

  18. import org.orekit.data.DataContext;
  19. import org.orekit.files.ccsds.ndm.adm.aem.AemParser;
  20. import org.orekit.files.ccsds.ndm.adm.apm.ApmParser;
  21. import org.orekit.files.ccsds.ndm.odm.oem.OemParser;
  22. import org.orekit.files.ccsds.ndm.odm.omm.OmmParser;
  23. import org.orekit.files.ccsds.ndm.odm.opm.OpmParser;
  24. import org.orekit.files.ccsds.ndm.tdm.RangeUnits;
  25. import org.orekit.files.ccsds.ndm.tdm.RangeUnitsConverter;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.utils.IERSConventions;

  28. /** Abstract builder for all {@link NdmConstituent CCSDS Message} files parsers/writers.
  29.  * @param <T> type of the builder
  30.  * @author Luc Maisonobe
  31.  * @since 11.0
  32.  */
  33. public abstract class AbstractBuilder<T extends AbstractBuilder<T>> {

  34.     /** IERS conventions used. */
  35.     private final IERSConventions conventions;

  36.     /** Central body equatorial radius.
  37.      * @since 12.0
  38.      */
  39.     private final double equatorialRadius;

  40.     /** Central body flattening.
  41.      * @since 12.0
  42.      */
  43.     private final double flattening;

  44.     /** Data context. */
  45.     private final DataContext dataContext;

  46.     /** Reference date for Mission Elapsed Time or Mission Relative Time time systems. */
  47.     private final AbsoluteDate missionReferenceDate;

  48.     /** Converter for {@link RangeUnits#RU Range Units}. */
  49.     private final RangeUnitsConverter rangeUnitsConverter;

  50.     /**
  51.      * Complete constructor.
  52.      * @param conventions IERS Conventions
  53.      * @param equatorialRadius central body equatorial radius
  54.      * @param flattening central body flattening
  55.      * @param dataContext used to retrieve frames, time scales, etc.
  56.      * @param missionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
  57.      * @param rangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
  58.      */
  59.     protected AbstractBuilder(final IERSConventions conventions,
  60.                               final double equatorialRadius, final double flattening,
  61.                               final DataContext dataContext,
  62.                               final AbsoluteDate missionReferenceDate,
  63.                               final RangeUnitsConverter rangeUnitsConverter) {
  64.         this.conventions          = conventions;
  65.         this.equatorialRadius     = equatorialRadius;
  66.         this.flattening           = flattening;
  67.         this.dataContext          = dataContext;
  68.         this.missionReferenceDate = missionReferenceDate;
  69.         this.rangeUnitsConverter  = rangeUnitsConverter;
  70.     }

  71.     /** Build an instance.
  72.      * @param newConventions IERS Conventions
  73.      * @param newEquatorialRadius central body equatorial radius
  74.      * @param newFlattening central body flattening
  75.      * @param newDataContext used to retrieve frames, time scales, etc.
  76.      * @param newMissionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
  77.      * @param newRangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
  78.      * @return new instance
  79.      */
  80.     protected abstract T create(IERSConventions newConventions, double newEquatorialRadius, double newFlattening,
  81.                                 DataContext newDataContext,
  82.                                 AbsoluteDate newMissionReferenceDate, RangeUnitsConverter newRangeUnitsConverter);

  83.     /** Set up IERS conventions.
  84.      * @param newConventions IERS Conventions
  85.      * @return a new builder with updated configuration (the instance is not changed)
  86.      */
  87.     public T withConventions(final IERSConventions newConventions) {
  88.         return create(newConventions, getEquatorialRadius(), getFlattening(), getDataContext(),
  89.                       getMissionReferenceDate(), getRangeUnitsConverter());
  90.     }

  91.     /** Get the IERS conventions.
  92.      * @return IERS conventions
  93.      */
  94.     public IERSConventions getConventions() {
  95.         return conventions;
  96.     }

  97.     /** Set up the central body equatorial radius.
  98.      * @param newEquatorialRadius central body equatorial radius
  99.      * @return a new builder with updated configuration (the instance is not changed)
  100.      */
  101.     public T withEquatorialRadius(final double newEquatorialRadius) {
  102.         return create(getConventions(), newEquatorialRadius, getFlattening(), getDataContext(),
  103.                       getMissionReferenceDate(), getRangeUnitsConverter());
  104.     }

  105.     /** Get the central body equatorial radius.
  106.      * @return central body equatorial radius
  107.      */
  108.     public double getEquatorialRadius() {
  109.         return equatorialRadius;
  110.     }

  111.     /** Set up the central body flattening.
  112.      * @param newFlattening central body flattening
  113.      * @return a new builder with updated configuration (the instance is not changed)
  114.      */
  115.     public T withFlattening(final double newFlattening) {
  116.         return create(getConventions(), getEquatorialRadius(), newFlattening, getDataContext(),
  117.                       getMissionReferenceDate(), getRangeUnitsConverter());
  118.     }

  119.     /** Get the central body flattening.
  120.      * @return central body flattening
  121.      */
  122.     public double getFlattening() {
  123.         return flattening;
  124.     }

  125.     /** Set up data context used to retrieve frames, time scales, etc..
  126.      * @param newDataContext data context used to retrieve frames, time scales, etc.
  127.      * @return a new builder with updated configuration (the instance is not changed)
  128.      */
  129.     public T withDataContext(final DataContext newDataContext) {
  130.         return create(getConventions(), getEquatorialRadius(), getFlattening(), newDataContext,
  131.                       getMissionReferenceDate(), getRangeUnitsConverter());
  132.     }

  133.     /** Get the data context.
  134.      * @return data context used to retrieve frames, time scales, etc.
  135.      */
  136.     public DataContext getDataContext() {
  137.         return dataContext;
  138.     }

  139.     /** Set up mission reference date or Mission Elapsed Time or Mission Relative Time time systems.
  140.      * <p>
  141.      * The mission reference date is used only by {@link AemParser} and {@link ApmParser},
  142.      * and by {@link OpmParser}, {@link OmmParser} and {@link OemParser} up to version 2.0
  143.      * of ODM (starting with version 3.0 of ODM, both MET and MRT time system have been
  144.      * withdrawn from the standard).
  145.      * </p>
  146.      * @param newMissionReferenceDate mission reference date or Mission Elapsed Time or Mission Relative Time time systems
  147.      * @return a new builder with updated configuration (the instance is not changed)
  148.      */
  149.     public T withMissionReferenceDate(final AbsoluteDate newMissionReferenceDate) {
  150.         return create(getConventions(), getEquatorialRadius(), getFlattening(), getDataContext(),
  151.                       newMissionReferenceDate, getRangeUnitsConverter());
  152.     }

  153.     /** Get the mission reference date or Mission Elapsed Time or Mission Relative Time time systems.
  154.      * @return mission reference date
  155.      */
  156.     public AbsoluteDate getMissionReferenceDate() {
  157.         return missionReferenceDate;
  158.     }

  159.     /** Set up the converter for {@link RangeUnits#RU Range Units}.
  160.      * @param newRangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
  161.      * @return a new builder with updated configuration (the instance is not changed)
  162.      */
  163.     public T withRangeUnitsConverter(final RangeUnitsConverter newRangeUnitsConverter) {
  164.         return create(getConventions(), getEquatorialRadius(), getFlattening(), getDataContext(),
  165.                       getMissionReferenceDate(), newRangeUnitsConverter);
  166.     }

  167.     /** Get the converter for {@link RangeUnits#RU Range Units}.
  168.      * @return converter for {@link RangeUnits#RU Range Units}
  169.      */
  170.     public RangeUnitsConverter getRangeUnitsConverter() {
  171.         return rangeUnitsConverter;
  172.     }

  173. }