ContextBinding.java

  1. /* Copyright 2002-2023 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.utils;

  18. import java.util.function.BooleanSupplier;
  19. import java.util.function.DoubleSupplier;
  20. import java.util.function.Supplier;

  21. import org.orekit.data.DataContext;
  22. import org.orekit.files.ccsds.definitions.TimeSystem;
  23. import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.utils.IERSConventions;

  26. /** Context for parsing/writing Navigation Data Message.
  27.  * <p>
  28.  * This class is a facade providing late binding access to data.
  29.  * Late binding is mainly useful at parse time as it allows some data to be set up
  30.  * during parsing itself. This is used for example to access {@link #getTimeSystem()
  31.  * time system} that is generally parsed from metadata block, and used later on
  32.  * within the same metadata block.
  33.  * </p>
  34.  * @author Luc Maisonobe
  35.  * @since 11.0
  36.  */
  37. public class ContextBinding {

  38.     /** Behavior adopted for units that have been parsed from a CCSDS message. */
  39.     private final Supplier<ParsedUnitsBehavior> behaviorSupplier;

  40.     /** Supplier for IERS conventions to use. */
  41.     private final Supplier<IERSConventions> conventionsSupplier;

  42.     /** Supplier for simple or accurate EOP interpolation indicator. */
  43.     private final  BooleanSupplier simpleEOPSupplier;

  44.     /** Supplier for data context. */
  45.     private final Supplier<DataContext> dataContextSupplier;

  46.     /** Supplier for reference date for mission elapsed time (MET), mission relative time (MRT),
  47.      * or spacecraft clock (SCLK) time systems. */
  48.     private final Supplier<AbsoluteDate> referenceDateSupplier;

  49.     /** Supplier for reference system for interpreting dates. */
  50.     private final Supplier<TimeSystem> timeSystemSupplier;

  51.     /** Supplier for clock count at reference date in spacecraft clock (SCLK) time system. */
  52.     private final DoubleSupplier clockCountSupplier;

  53.     /** Supplier for clock rate in spacecraft clock (SCLK) time system. */
  54.     private final DoubleSupplier clockRateSupplier;

  55.     /** Create a new context.
  56.      * @param conventionsSupplier supplier for IERS conventions to use
  57.      * @param simpleEOPSupplier supplier for simple or accurate EOP interpolation indicator
  58.      * @param dataContextSupplier supplier for data context to use
  59.      * @param behaviorSupplier supplier for behavior to adopt on unit
  60.      * @param referenceDateSupplier supplier for reference date for mission elapsed time (MET),
  61.      * mission relative time (MRT), or spacecraft clock (SCLK) time systems
  62.      * @param timeSystemSupplier supplier for reference system for interpreting dates
  63.      * @param clockCountSupplier supplier for clock count at reference date in spacecraft clock (SCLK) time system
  64.      * @param clockRateSupplier supplier for clock rate in spacecraft clock (SCLK) time system
  65.      */
  66.     public ContextBinding(final Supplier<IERSConventions>     conventionsSupplier,
  67.                           final BooleanSupplier               simpleEOPSupplier,
  68.                           final Supplier<DataContext>         dataContextSupplier,
  69.                           final Supplier<ParsedUnitsBehavior> behaviorSupplier,
  70.                           final Supplier<AbsoluteDate>        referenceDateSupplier,
  71.                           final Supplier<TimeSystem>          timeSystemSupplier,
  72.                           final DoubleSupplier                clockCountSupplier,
  73.                           final DoubleSupplier                clockRateSupplier) {
  74.         this.behaviorSupplier      = behaviorSupplier;
  75.         this.conventionsSupplier   = conventionsSupplier;
  76.         this.simpleEOPSupplier     = simpleEOPSupplier;
  77.         this.dataContextSupplier   = dataContextSupplier;
  78.         this.referenceDateSupplier = referenceDateSupplier;
  79.         this.timeSystemSupplier    = timeSystemSupplier;
  80.         this.clockCountSupplier    = clockCountSupplier;
  81.         this.clockRateSupplier     = clockRateSupplier;
  82.     }

  83.     /** Get the behavior to adopt for handling parsed units.
  84.      * @return behavior to adopt for handling parsed units
  85.      */
  86.     public ParsedUnitsBehavior getParsedUnitsBehavior() {
  87.         return behaviorSupplier.get();
  88.     }

  89.     /** Get IERS conventions.
  90.      * @return IERS conventions to use while parsing
  91.      */
  92.     public IERSConventions getConventions() {
  93.         return conventionsSupplier.get();
  94.     }

  95.     /** Get EOP interpolation method.
  96.      * @return true if tidal effects are ignored when interpolating EOP
  97.      */
  98.     public boolean isSimpleEOP() {
  99.         return simpleEOPSupplier.getAsBoolean();
  100.     }

  101.     /** Get the data context used for getting frames, time scales, and celestial bodies.
  102.      * @return the data context.
  103.      */
  104.     public DataContext getDataContext() {
  105.         return dataContextSupplier.get();
  106.     }

  107.     /** Get initial date.
  108.      * @return reference date to use while parsing
  109.      */
  110.     public AbsoluteDate getReferenceDate() {
  111.         return referenceDateSupplier.get();
  112.     }

  113.     /** Get the time system.
  114.      * @return time system
  115.      */
  116.     public TimeSystem getTimeSystem() {
  117.         return timeSystemSupplier.get();
  118.     }

  119.     /** Get clock count.
  120.      * @return clock count at reference date
  121.      */
  122.     public double getClockCount() {
  123.         return clockCountSupplier.getAsDouble();
  124.     }

  125.     /** Get clock rate.
  126.      * @return clock rate (in clock ticks per SI second)
  127.      */
  128.     public double getClockRate() {
  129.         return clockRateSupplier.getAsDouble();
  130.     }

  131. }