1   /* Copyright 2002-2021 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  
19  import org.orekit.data.DataContext;
20  import org.orekit.files.ccsds.ndm.adm.aem.AemParser;
21  import org.orekit.files.ccsds.ndm.adm.apm.ApmParser;
22  import org.orekit.files.ccsds.ndm.odm.oem.OemParser;
23  import org.orekit.files.ccsds.ndm.odm.omm.OmmParser;
24  import org.orekit.files.ccsds.ndm.odm.opm.OpmParser;
25  import org.orekit.files.ccsds.ndm.tdm.RangeUnits;
26  import org.orekit.files.ccsds.ndm.tdm.RangeUnitsConverter;
27  import org.orekit.time.AbsoluteDate;
28  import org.orekit.utils.IERSConventions;
29  
30  /** Abstract builder for all {@link NdmConstituent CCSDS Message} files parsers/writers.
31   * @param <T> type of the builder
32   * @author Luc Maisonobe
33   * @since 11.0
34   */
35  public abstract class AbstractBuilder<T extends AbstractBuilder<T>> {
36  
37      /** IERS conventions used. */
38      private final IERSConventions conventions;
39  
40      /** Data context. */
41      private final DataContext dataContext;
42  
43      /** Reference date for Mission Elapsed Time or Mission Relative Time time systems. */
44      private final AbsoluteDate missionReferenceDate;
45  
46      /** Converter for {@link RangeUnits#RU Range Units}. */
47      private final RangeUnitsConverter rangeUnitsConverter;
48  
49      /**
50       * Complete constructor.
51       * @param conventions IERS Conventions
52       * @param dataContext used to retrieve frames, time scales, etc.
53       * @param missionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
54       * @param rangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
55       */
56      protected AbstractBuilder(final IERSConventions conventions, final DataContext dataContext,
57                                final AbsoluteDate missionReferenceDate,
58                                final RangeUnitsConverter rangeUnitsConverter) {
59          this.conventions          = conventions;
60          this.dataContext          = dataContext;
61          this.missionReferenceDate = missionReferenceDate;
62          this.rangeUnitsConverter  = rangeUnitsConverter;
63      }
64  
65      /** Build an instance.
66       * @param newConventions IERS Conventions
67       * @param newDataContext used to retrieve frames, time scales, etc.
68       * @param newMissionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
69       * @param newRangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
70       * @return new instance
71       */
72      protected abstract T create(IERSConventions newConventions, DataContext newDataContext,
73                                  AbsoluteDate newMissionReferenceDate, RangeUnitsConverter newRangeUnitsConverter);
74  
75      /** Set up IERS conventions.
76       * @param newConventions IERS Conventions
77       * @return a new builder with updated configuration (the instance is not changed)
78       */
79      public T withConventions(final IERSConventions newConventions) {
80          return create(newConventions, getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter());
81      }
82  
83      /** Get the IERS conventions.
84       * @return IERS conventions
85       */
86      public IERSConventions getConventions() {
87          return conventions;
88      }
89  
90      /** Set up data context used to retrieve frames, time scales, etc..
91       * @param newDataContext data context used to retrieve frames, time scales, etc.
92       * @return a new builder with updated configuration (the instance is not changed)
93       */
94      public T withDataContext(final DataContext newDataContext) {
95          return create(getConventions(), newDataContext, getMissionReferenceDate(), getRangeUnitsConverter());
96      }
97  
98      /** Get the data context.
99       * @return data context used to retrieve frames, time scales, etc.
100      */
101     public DataContext getDataContext() {
102         return dataContext;
103     }
104 
105     /** Set up mission reference date or Mission Elapsed Time or Mission Relative Time time systems.
106      * <p>
107      * The mission reference date is used only by {@link AemParser} and {@link ApmParser},
108      * and by {@link OpmParser}, {@link OmmParser} and {@link OemParser} up to version 2.0
109      * of ODM (starting with version 3.0 of ODM, both MET and MRT time system have been
110      * withdrawn from the standard).
111      * </p>
112      * @param newMissionReferenceDate mission reference date or Mission Elapsed Time or Mission Relative Time time systems
113      * @return a new builder with updated configuration (the instance is not changed)
114      */
115     public T withMissionReferenceDate(final AbsoluteDate newMissionReferenceDate) {
116         return create(getConventions(), getDataContext(), newMissionReferenceDate, getRangeUnitsConverter());
117     }
118 
119     /** Get the mission reference date or Mission Elapsed Time or Mission Relative Time time systems.
120      * @return mission reference date
121      */
122     public AbsoluteDate getMissionReferenceDate() {
123         return missionReferenceDate;
124     }
125 
126     /** Set up the converter for {@link RangeUnits#RU Range Units}.
127      * @param newRangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
128      * @return a new builder with updated configuration (the instance is not changed)
129      */
130     public T withRangeUnitsConverter(final RangeUnitsConverter newRangeUnitsConverter) {
131         return create(getConventions(), getDataContext(), getMissionReferenceDate(), newRangeUnitsConverter);
132     }
133 
134     /** Get the converter for {@link RangeUnits#RU Range Units}.
135      * @return converter for {@link RangeUnits#RU Range Units}
136      */
137     public RangeUnitsConverter getRangeUnitsConverter() {
138         return rangeUnitsConverter;
139     }
140 
141 }