1   /* Copyright 2002-2025 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.odm;
18  
19  import org.orekit.files.ccsds.definitions.Units;
20  import org.orekit.files.ccsds.utils.ContextBinding;
21  import org.orekit.files.ccsds.utils.lexical.ParseToken;
22  import org.orekit.files.ccsds.utils.lexical.TokenType;
23  import org.orekit.utils.units.Unit;
24  
25  
26  /** Keys for {@link StateVector ODM state vector container} entries.
27   * @author Luc Maisonobe
28   * @since 11.0
29   */
30  public enum StateVectorKey {
31  
32      /** Comment entry. */
33      COMMENT((token, context, container) ->
34              token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),
35  
36      /** Epoch of state vector and optional Keplerian elements. */
37      EPOCH((token, context, container) -> token.processAsDate(container::setEpoch, context)),
38  
39      /** Position vector X-component. */
40      X((token, context, container) -> token.processAsIndexedDouble(0, Unit.KILOMETRE, context.getParsedUnitsBehavior(),
41                                                                    container::setP)),
42  
43      /** Position vector Y-component. */
44      Y((token, context, container) -> token.processAsIndexedDouble(1, Unit.KILOMETRE, context.getParsedUnitsBehavior(),
45                                                                    container::setP)),
46  
47      /** Position vector Z-component. */
48      Z((token, context, container) -> token.processAsIndexedDouble(2, Unit.KILOMETRE, context.getParsedUnitsBehavior(),
49                                                                    container::setP)),
50  
51      /** Velocity vector X-component. */
52      X_DOT((token, context, container) -> token.processAsIndexedDouble(0, Units.KM_PER_S, context.getParsedUnitsBehavior(),
53                                                                        container::setV)),
54  
55      /** Velocity vector Y-component. */
56      Y_DOT((token, context, container) -> token.processAsIndexedDouble(1, Units.KM_PER_S, context.getParsedUnitsBehavior(),
57                                                                        container::setV)),
58  
59      /** Velocity vector Z-component. */
60      Z_DOT((token, context, container) -> token.processAsIndexedDouble(2, Units.KM_PER_S, context.getParsedUnitsBehavior(),
61                                                                        container::setV)),
62  
63      /** Acceleration vector X-component. */
64      X_DDOT((token, context, container) -> token.processAsIndexedDouble(0, Units.KM_PER_S2, context.getParsedUnitsBehavior(),
65                                                                         container::setA)),
66  
67      /** Acceleration vector Y-component. */
68      Y_DDOT((token, context, container) -> token.processAsIndexedDouble(1, Units.KM_PER_S2, context.getParsedUnitsBehavior(),
69                                                                         container::setA)),
70  
71      /** Acceleration vector Z-component. */
72      Z_DDOT((token, context, container) -> token.processAsIndexedDouble(2, Units.KM_PER_S2, context.getParsedUnitsBehavior(),
73                                                                         container::setA));
74  
75      /** Processing method. */
76      private final transient TokenProcessor processor;
77  
78      /** Simple constructor.
79       * @param processor processing method
80       */
81      StateVectorKey(final TokenProcessor processor) {
82          this.processor = processor;
83      }
84  
85      /** Process one token.
86       * @param token token to process
87       * @param context context binding
88       * @param container container to fill
89       * @return true of token was accepted
90       */
91      public boolean process(final ParseToken token, final ContextBinding context, final StateVector container) {
92          return processor.process(token, context, container);
93      }
94  
95      /** Interface for processing one token. */
96      interface TokenProcessor {
97          /** Process one token.
98           * @param token token to process
99           * @param context context binding
100          * @param container container to fill
101          * @return true of token was accepted
102          */
103         boolean process(ParseToken token, ContextBinding context, StateVector container);
104     }
105 
106 }