1   /* Copyright 2002-2021 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.adm.apm;
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 Maneuver APM maneuver} entries.
26   * @author Bryan Cazabonne
27   * @author Luc Maisonobe
28   * @since 11.0
29   */
30  public enum ManeuverKey {
31  
32      /** Comment entry. */
33      COMMENT((token, context, container) ->
34              token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),
35  
36      /** Epoch start entry. */
37      MAN_EPOCH_START((token, context, container) -> token.processAsDate(container::setEpochStart, context)),
38  
39      /** Duration entry. */
40      MAN_DURATION((token, context, container) -> token.processAsDouble(Unit.SECOND, context.getParsedUnitsBehavior(),
41                                                                        container::setDuration)),
42  
43      /** Reference frame entry. */
44      MAN_REF_FRAME((token, context, container) -> token.processAsUppercaseString(container::setRefFrameString)),
45  
46      /** First torque vector component entry. */
47      MAN_TOR_1((token, context, container) -> token.processAsIndexedDouble(0, Units.N_M, context.getParsedUnitsBehavior(),
48                                                                            container::setTorque)),
49  
50      /** Second torque vector component entry. */
51      MAN_TOR_2((token, context, container) -> token.processAsIndexedDouble(1, Units.N_M, context.getParsedUnitsBehavior(),
52                                                                            container::setTorque)),
53  
54      /** Third torque vector component entry. */
55      MAN_TOR_3((token, context, container) -> token.processAsIndexedDouble(2, Units.N_M, context.getParsedUnitsBehavior(),
56                                                                            container::setTorque));
57  
58      /** Processing method. */
59      private final TokenProcessor processor;
60  
61      /** Simple constructor.
62       * @param processor processing method
63       */
64      ManeuverKey(final TokenProcessor processor) {
65          this.processor = processor;
66      }
67  
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      public boolean process(final ParseToken token, final ContextBinding context, final Maneuver container) {
75          return processor.process(token, context, container);
76      }
77  
78      /** Interface for processing one token. */
79      interface TokenProcessor {
80          /** Process one token.
81           * @param token token to process
82           * @param context context binding
83           * @param container container to fill
84           * @return true of token was accepted
85           */
86          boolean process(ParseToken token, ContextBinding context, Maneuver container);
87      }
88  
89  }