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.cdm;
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 /** Keys for {@link StateVector CDM state vector} entries.
26 * @author Melina Vanel
27 * @since 11.2
28 */
29 public enum StateVectorKey {
30
31 /** Comment entry. */
32 COMMENT((token, context, container) ->
33 token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),
34
35 /** Object Position Vector X component. */
36 X((token, context, container) -> token.processAsDouble(Unit.KILOMETRE, context.getParsedUnitsBehavior(),
37 container::setX)),
38 /** Object Position Vector Y component. */
39 Y((token, context, container) -> token.processAsDouble(Unit.KILOMETRE, context.getParsedUnitsBehavior(),
40 container::setY)),
41 /** Object Position Vector Z component. */
42 Z((token, context, container) -> token.processAsDouble(Unit.KILOMETRE, context.getParsedUnitsBehavior(),
43 container::setZ)),
44 /** Object Velocity Vector X component. */
45 X_DOT((token, context, container) -> token.processAsDouble(Units.KM_PER_S, context.getParsedUnitsBehavior(),
46 container::setXdot)),
47 /** Object Velocity Vector Y component. */
48 Y_DOT((token, context, container) -> token.processAsDouble(Units.KM_PER_S, context.getParsedUnitsBehavior(),
49 container::setYdot)),
50 /** Object Velocity Vector Z component. */
51 Z_DOT((token, context, container) -> token.processAsDouble(Units.KM_PER_S, context.getParsedUnitsBehavior(),
52 container::setZdot));
53
54 /** Processing method. */
55 private final transient TokenProcessor processor;
56
57 /** Simple constructor.
58 * @param processor processing method
59 */
60 StateVectorKey(final TokenProcessor processor) {
61 this.processor = processor;
62 }
63
64 /** Process one token.
65 * @param token token to process
66 * @param context context binding
67 * @param container container to fill
68 * @return true of token was accepted
69 */
70 public boolean process(final ParseToken token, final ContextBinding context, final StateVector container) {
71 return processor.process(token, context, container);
72 }
73
74 /** Interface for processing one token. */
75 interface TokenProcessor {
76 /** Process one token.
77 * @param token token to process
78 * @param context context binding
79 * @param container container to fill
80 * @return true of token was accepted
81 */
82 boolean process(ParseToken token, ContextBinding context, StateVector container);
83 }
84
85 }