StateVectorKey.java

  1. /* Copyright 2002-2022 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.ndm.cdm;

  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. import org.orekit.utils.units.Unit;

  23. /** Keys for {@link StateVector CDM state vector} entries.
  24.  * @author Melina Vanel
  25.  * @since 11.2
  26.  */
  27. public enum StateVectorKey {

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

  31.     /** Object Position Vector X component. */
  32.     X((token, context, container) -> token.processAsDouble(Unit.KILOMETRE, context.getParsedUnitsBehavior(),
  33.                                                              container::setX)),
  34.     /** Object Position Vector Y component. */
  35.     Y((token, context, container) -> token.processAsDouble(Unit.KILOMETRE, context.getParsedUnitsBehavior(),
  36.                                                              container::setY)),
  37.     /** Object Position Vector Z component. */
  38.     Z((token, context, container) -> token.processAsDouble(Unit.KILOMETRE, context.getParsedUnitsBehavior(),
  39.                                                              container::setZ)),
  40.     /** Object Velocity Vector X component. */
  41.     X_DOT((token, context, container) -> token.processAsDouble(Units.KM_PER_S, context.getParsedUnitsBehavior(),
  42.                                                              container::setXdot)),
  43.     /** Object Velocity Vector Y component. */
  44.     Y_DOT((token, context, container) -> token.processAsDouble(Units.KM_PER_S, context.getParsedUnitsBehavior(),
  45.                                                              container::setYdot)),
  46.     /** Object Velocity Vector Z component. */
  47.     Z_DOT((token, context, container) -> token.processAsDouble(Units.KM_PER_S, context.getParsedUnitsBehavior(),
  48.                                                              container::setZdot));

  49.     /** Processing method. */
  50.     private final TokenProcessor processor;

  51.     /** Simple constructor.
  52.      * @param processor processing method
  53.      */
  54.     StateVectorKey(final TokenProcessor processor) {
  55.         this.processor = processor;
  56.     }

  57.     /** Process one token.
  58.      * @param token token to process
  59.      * @param context context binding
  60.      * @param container container to fill
  61.      * @return true of token was accepted
  62.      */
  63.     public boolean process(final ParseToken token, final ContextBinding context, final StateVector container) {
  64.         return processor.process(token, context, container);
  65.     }

  66.     /** Interface for processing one token. */
  67.     interface TokenProcessor {
  68.         /** Process one token.
  69.          * @param token token to process
  70.          * @param context context binding
  71.          * @param container container to fill
  72.          * @return true of token was accepted
  73.          */
  74.         boolean process(ParseToken token, ContextBinding context, StateVector container);
  75.     }

  76. }