AbstractBuilder.java

  1. /* Copyright 2002-2022 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.     /** Data context. */
  37.     private final DataContext dataContext;

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

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

  42.     /**
  43.      * Complete constructor.
  44.      * @param conventions IERS Conventions
  45.      * @param dataContext used to retrieve frames, time scales, etc.
  46.      * @param missionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
  47.      * @param rangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
  48.      */
  49.     protected AbstractBuilder(final IERSConventions conventions, final DataContext dataContext,
  50.                               final AbsoluteDate missionReferenceDate,
  51.                               final RangeUnitsConverter rangeUnitsConverter) {
  52.         this.conventions          = conventions;
  53.         this.dataContext          = dataContext;
  54.         this.missionReferenceDate = missionReferenceDate;
  55.         this.rangeUnitsConverter  = rangeUnitsConverter;
  56.     }

  57.     /** Build an instance.
  58.      * @param newConventions IERS Conventions
  59.      * @param newDataContext used to retrieve frames, time scales, etc.
  60.      * @param newMissionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
  61.      * @param newRangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
  62.      * @return new instance
  63.      */
  64.     protected abstract T create(IERSConventions newConventions, DataContext newDataContext,
  65.                                 AbsoluteDate newMissionReferenceDate, RangeUnitsConverter newRangeUnitsConverter);

  66.     /** Set up IERS conventions.
  67.      * @param newConventions IERS Conventions
  68.      * @return a new builder with updated configuration (the instance is not changed)
  69.      */
  70.     public T withConventions(final IERSConventions newConventions) {
  71.         return create(newConventions, getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter());
  72.     }

  73.     /** Get the IERS conventions.
  74.      * @return IERS conventions
  75.      */
  76.     public IERSConventions getConventions() {
  77.         return conventions;
  78.     }

  79.     /** Set up data context used to retrieve frames, time scales, etc..
  80.      * @param newDataContext data context used to retrieve frames, time scales, etc.
  81.      * @return a new builder with updated configuration (the instance is not changed)
  82.      */
  83.     public T withDataContext(final DataContext newDataContext) {
  84.         return create(getConventions(), newDataContext, getMissionReferenceDate(), getRangeUnitsConverter());
  85.     }

  86.     /** Get the data context.
  87.      * @return data context used to retrieve frames, time scales, etc.
  88.      */
  89.     public DataContext getDataContext() {
  90.         return dataContext;
  91.     }

  92.     /** Set up mission reference date or Mission Elapsed Time or Mission Relative Time time systems.
  93.      * <p>
  94.      * The mission reference date is used only by {@link AemParser} and {@link ApmParser},
  95.      * and by {@link OpmParser}, {@link OmmParser} and {@link OemParser} up to version 2.0
  96.      * of ODM (starting with version 3.0 of ODM, both MET and MRT time system have been
  97.      * withdrawn from the standard).
  98.      * </p>
  99.      * @param newMissionReferenceDate mission reference date or Mission Elapsed Time or Mission Relative Time time systems
  100.      * @return a new builder with updated configuration (the instance is not changed)
  101.      */
  102.     public T withMissionReferenceDate(final AbsoluteDate newMissionReferenceDate) {
  103.         return create(getConventions(), getDataContext(), newMissionReferenceDate, getRangeUnitsConverter());
  104.     }

  105.     /** Get the mission reference date or Mission Elapsed Time or Mission Relative Time time systems.
  106.      * @return mission reference date
  107.      */
  108.     public AbsoluteDate getMissionReferenceDate() {
  109.         return missionReferenceDate;
  110.     }

  111.     /** Set up the converter for {@link RangeUnits#RU Range Units}.
  112.      * @param newRangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
  113.      * @return a new builder with updated configuration (the instance is not changed)
  114.      */
  115.     public T withRangeUnitsConverter(final RangeUnitsConverter newRangeUnitsConverter) {
  116.         return create(getConventions(), getDataContext(), getMissionReferenceDate(), newRangeUnitsConverter);
  117.     }

  118.     /** Get the converter for {@link RangeUnits#RU Range Units}.
  119.      * @return converter for {@link RangeUnits#RU Range Units}
  120.      */
  121.     public RangeUnitsConverter getRangeUnitsConverter() {
  122.         return rangeUnitsConverter;
  123.     }

  124. }