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.estimation.measurements.gnss;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.orekit.gnss.SatelliteSystem;
23  
24  /** Factory for {@link WindUp wind-up} modifiers.
25   * <p>
26   * The factory ensures the same instance is returned for all
27   * satellite/receiver pair, thus preserving phase continuity
28   * for successive measurements involving the same pair.
29   * </p>
30   * @author Luc Maisonobe
31   * @since 10.1
32   */
33  public class WindUpFactory {
34  
35      /** Modifiers cache. */
36      private final Map<SatelliteSystem, Map<Integer, Map<String, WindUp>>> modifiers;
37  
38      /** Simple constructor.
39       */
40      public WindUpFactory() {
41          this.modifiers = new HashMap<>();
42      }
43  
44      /** Get a modifier for a satellite/receiver pair.
45       * @param system system the satellite belongs to
46       * @param prnNumber PRN number
47       * @param receiverName name of the receiver
48       * @return modifier for the satellite/receiver pair
49       */
50      public WindUp getWindUp(final SatelliteSystem system, final int prnNumber, final String receiverName) {
51  
52          // select satellite system
53          Map<Integer, Map<String, WindUp>> systemModifiers = modifiers.get(system);
54          if (systemModifiers == null) {
55              // build a new map for this satellite system
56              systemModifiers = new HashMap<>();
57              modifiers.put(system, systemModifiers);
58          }
59  
60          // select satellite
61          Map<String, WindUp> satelliteModifiers = systemModifiers.get(prnNumber);
62          if (satelliteModifiers == null) {
63              // build a new map for this satellite
64              satelliteModifiers = new HashMap<>();
65              systemModifiers.put(prnNumber, satelliteModifiers);
66          }
67  
68          // select receiver
69          WindUp receiverModifier = satelliteModifiers.get(receiverName);
70          if (receiverModifier == null) {
71              // build a new wind-up modifier
72              receiverModifier = new WindUp();
73              satelliteModifiers.put(receiverName, receiverModifier);
74          }
75  
76          return receiverModifier;
77  
78      }
79  
80  }