1   /* Copyright 2002-2024 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  
18  package org.orekit.files.ccsds.ndm.tdm;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.orekit.files.ccsds.section.CommentsContainer;
24  import org.orekit.files.ccsds.section.Data;
25  import org.orekit.time.AbsoluteDate;
26  
27  /** The Observations Block class contain metadata and the list of observation data lines.<p>
28   * The reason for which the observations have been separated into blocks is that the different
29   * data blocks in a TDM file usually refers to different types of observations.<p>
30   * An observation block is associated with a TDM metadata object and contains a list of observations.<p>
31   * At this level, an observation is not an Orekit object, it is a custom object containing:<p>
32   *  - a keyword, the type of the observation;<p>
33   *  - a timetag, the date of the observation;<p>
34   *  - a measurement, the value of the observation.
35   * @author Maxime Journot
36   */
37  public class ObservationsBlock extends CommentsContainer implements Data {
38  
39      /** Current observation epoch. */
40      private AbsoluteDate currentObservationEpoch;
41  
42      /** List of observations data lines. */
43      private List<Observation> observations;
44  
45      /** ObservationsBlock constructor. */
46      public ObservationsBlock() {
47          observations = new ArrayList<>();
48      }
49  
50      /** Add the epoch of current observation.
51       * @param epoch current observation epoch
52       * @return alwaus return {@code true}
53       */
54      boolean addObservationEpoch(final AbsoluteDate epoch) {
55          refuseFurtherComments();
56          currentObservationEpoch = epoch;
57          return true;
58      }
59  
60      /** Get current observation epoch if set.
61       * @return current observation epoch, or null if not set
62       */
63      AbsoluteDate getCurrentObservationEpoch() {
64          return currentObservationEpoch;
65      }
66  
67      /** Add the value of current observation.
68       * @param type type of the observation
69       * @param measurement measurement of the observation
70       */
71      void addObservationValue(final ObservationType type, final double measurement) {
72          addObservation(type, currentObservationEpoch, measurement);
73          currentObservationEpoch = null;
74      }
75  
76      /** Get the list of Observations data lines.
77       * @return a reference to the internal list of Observations data lines
78       */
79      public List<Observation> getObservations() {
80          return this.observations;
81      }
82  
83      /** Set the list of Observations Data Lines.
84       * @param observations the list of Observations Data Lines to set
85       */
86      public void setObservations(final List<Observation> observations) {
87          refuseFurtherComments();
88          this.observations = new ArrayList<>(observations);
89      }
90  
91      /** Adds an observation data line.
92       * @param observation the observation to add to the list
93       */
94      public void addObservation(final Observation observation) {
95          refuseFurtherComments();
96          this.observations.add(observation);
97      }
98  
99      /** Adds an observation data line.
100      * @param type type of the observation
101      * @param epoch the timetag
102      * @param measurement the measurement
103      */
104     public void addObservation(final ObservationType type,
105                                final AbsoluteDate epoch,
106                                final double measurement) {
107         this.addObservation(new Observation(type, epoch, measurement));
108     }
109 
110 }