1   /* Copyright 2002-2026 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.gnss.metric.messages.rtcm.correction;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.orekit.gnss.SatelliteSystem;
26  import org.orekit.gnss.metric.messages.rtcm.RtcmMessage;
27  
28  /**
29   * The RTCM Correction Message types provide elements
30   * to calculate GNSS satellite corrections.
31   * Corrections are orbit and clock corrections.
32   *
33   * @author Bryan Cazabonne
34   * @since 12.0
35   * @param <H> type of the header
36   * @param <D> type of the data
37   *
38   */
39  public class RtcmCorrectionMessage<H extends RtcmCorrectionHeader, D extends RtcmCorrectionData> extends RtcmMessage<D> {
40  
41      /** Message header. */
42      private final H header;
43  
44      /** Satellite system. */
45      private final SatelliteSystem system;
46  
47      /**
48       * Constructor.
49       * @param system satellite system associated to the message
50       * @param typeCode message number
51       * @param header message header
52       * @param data message data
53       */
54      public RtcmCorrectionMessage(final int typeCode, final SatelliteSystem system,
55                                   final H header, final List<D> data) {
56          super(typeCode, data);
57          this.header = header;
58          this.system = system;
59      }
60  
61      /**
62       * Get the header.
63       * @return header
64       */
65      public H getHeader() {
66          return header;
67      }
68  
69      /**
70       * Get the satellite system associated to the message.
71       * @return the satellite system
72       */
73      public SatelliteSystem getSatelliteSystem() {
74          return system;
75      }
76  
77      /**
78       * Get the all data parsed in the RTCM correction message.
79       * <p>
80       * Key: satellite identifier (e.g. "G01")
81       * </p>
82       * @return the all data for the parsed message
83       */
84      public Map<String, List<D>> getDataMap() {
85  
86          // Initialize map
87          final Map<String, List<D>> data = new HashMap<>();
88  
89          // Loop on parsed data and fill map
90          for (final D currentData : getData()) {
91              final int satId = currentData.getSatelliteID();
92              final String idString = satId < 10 ? "0" + String.valueOf(satId) : String.valueOf(satId);
93              final String id = getSatelliteSystem().getKey() + idString;
94              data.putIfAbsent(id, new ArrayList<>());
95              data.get(id).add(currentData);
96          }
97  
98          // Return an unmodifiable map of the parsed data
99          return Collections.unmodifiableMap(data);
100 
101     }
102 
103 }