InertiaKey.java

  1. /* Copyright 2002-2024 Luc Maisonobe
  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.adm.apm;

  18. import org.orekit.files.ccsds.definitions.Units;
  19. import org.orekit.files.ccsds.utils.ContextBinding;
  20. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  21. import org.orekit.files.ccsds.utils.lexical.TokenType;


  22. /** Keys for {@link Inertia inertia} entries.
  23.  * @author Luc Maisonobe
  24.  * @since 12.0
  25.  */
  26. public enum InertiaKey {

  27.     /** Comment entry. */
  28.     COMMENT((token, context, container) ->
  29.             token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),

  30.     /** Frame in which inertia is defined. */
  31.     INERTIA_REF_FRAME((token, context, container) -> token.processAsFrame(container::setFrame, context, false, false, true)),

  32.     /** Moment of inertia about X-axis (ADM V1 only). */
  33.     I11((token, context, container) -> token.processAsDoublyIndexedDouble(0, 0, Units.KG_M2, context.getParsedUnitsBehavior(),
  34.                                                                           container::setInertiaMatrixEntry)),

  35.     /** Moment of inertia about X-axis. */
  36.     IXX((token, context, container) -> token.processAsDoublyIndexedDouble(0, 0, Units.KG_M2, context.getParsedUnitsBehavior(),
  37.                                                                           container::setInertiaMatrixEntry)),

  38.     /** Moment of inertia about Y-axis (ADM V1 only). */
  39.     I22((token, context, container) -> token.processAsDoublyIndexedDouble(1, 1, Units.KG_M2, context.getParsedUnitsBehavior(),
  40.                                                                           container::setInertiaMatrixEntry)),

  41.     /** Moment of inertia about Y-axis. */
  42.     IYY((token, context, container) -> token.processAsDoublyIndexedDouble(1, 1, Units.KG_M2, context.getParsedUnitsBehavior(),
  43.                                                                           container::setInertiaMatrixEntry)),

  44.     /** Moment of inertia about Z-axis (ADM V1 only). */
  45.     I33((token, context, container) -> token.processAsDoublyIndexedDouble(2, 2, Units.KG_M2, context.getParsedUnitsBehavior(),
  46.                                                                           container::setInertiaMatrixEntry)),

  47.     /** Moment of inertia about Z-axis. */
  48.     IZZ((token, context, container) -> token.processAsDoublyIndexedDouble(2, 2, Units.KG_M2, context.getParsedUnitsBehavior(),
  49.                                                                           container::setInertiaMatrixEntry)),

  50.     /** Inertia cross product of the X and Y axes (ADM V1 only). */
  51.     I12((token, context, container) -> token.processAsDoublyIndexedDouble(0, 1, Units.KG_M2, context.getParsedUnitsBehavior(),
  52.                                                                           container::setInertiaMatrixEntry)),

  53.     /** Inertia cross product of the X and Y axes. */
  54.     IXY((token, context, container) -> token.processAsDoublyIndexedDouble(0, 1, Units.KG_M2, context.getParsedUnitsBehavior(),
  55.                                                                           container::setInertiaMatrixEntry)),

  56.     /** Inertia cross product of the X and Z axes (ADM V1 only). */
  57.     I13((token, context, container) -> token.processAsDoublyIndexedDouble(0, 2, Units.KG_M2, context.getParsedUnitsBehavior(),
  58.                                                                           container::setInertiaMatrixEntry)),

  59.     /** Inertia cross product of the X and Z axes. */
  60.     IXZ((token, context, container) -> token.processAsDoublyIndexedDouble(0, 2, Units.KG_M2, context.getParsedUnitsBehavior(),
  61.                                                                           container::setInertiaMatrixEntry)),

  62.     /** Inertia cross product of the Y and Z axes (ADM V1 only). */
  63.     I23((token, context, container) -> token.processAsDoublyIndexedDouble(1, 2, Units.KG_M2, context.getParsedUnitsBehavior(),
  64.                                                                           container::setInertiaMatrixEntry)),

  65.     /** Inertia cross product of the Y and Z axes. */
  66.     IYZ((token, context, container) -> token.processAsDoublyIndexedDouble(1, 2, Units.KG_M2, context.getParsedUnitsBehavior(),
  67.                                                                           container::setInertiaMatrixEntry));

  68.     /** Processing method. */
  69.     private final transient TokenProcessor processor;

  70.     /** Simple constructor.
  71.      * @param processor processing method
  72.      */
  73.     InertiaKey(final TokenProcessor processor) {
  74.         this.processor = processor;
  75.     }

  76.     /** Process an token.
  77.      * @param token token to process
  78.      * @param context context binding
  79.      * @param data data to fill
  80.      * @return true of token was accepted
  81.      */
  82.     public boolean process(final ParseToken token, final ContextBinding context, final Inertia data) {
  83.         return processor.process(token, context, data);
  84.     }

  85.     /** Interface for processing one token. */
  86.     interface TokenProcessor {
  87.         /** Process one token.
  88.          * @param token token to process
  89.          * @param context context binding
  90.          * @param data data to fill
  91.          * @return true of token was accepted
  92.          */
  93.         boolean process(ParseToken token, ContextBinding context, Inertia data);
  94.     }

  95. }