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; 18 19 import org.hipparchus.util.Precision; 20 import org.orekit.errors.OrekitException; 21 import org.orekit.errors.OrekitMessages; 22 import org.orekit.utils.units.Unit; 23 24 /** Behavior adopted for units that have been parsed from a CCSDS message. 25 * @author Luc Maisonobe 26 * @since 11.0 27 */ 28 public enum ParsedUnitsBehavior { 29 30 /** Ignore parsed units, just relying on CCSDS standard. 31 * <p> 32 * When this behavior is selected having a unit parsed as second 33 * when CCSDS mandates kilometer will be accepted. 34 * </p> 35 */ 36 IGNORE_PARSED { 37 /** {@inheritDoc} */ 38 @Override 39 public Unit select(final Unit message, final Unit standard) { 40 return standard; 41 } 42 }, 43 44 /** Allow compatible units, performing conversion. 45 * <p> 46 * When this behavior is selected having a unit parsed as second 47 * when CCSDS mandates kilometer will be refused, but having a unit 48 * parsed as meter will be accepted, with proper conversion performed. 49 * Missing units (i.e. units parsed as {@link Unit#NONE}) are considered 50 * to be standard. 51 * </p> 52 */ 53 CONVERT_COMPATIBLE { 54 /** {@inheritDoc} */ 55 @Override 56 public Unit select(final Unit message, final Unit standard) { 57 if (message == Unit.NONE) { 58 return standard; 59 } else if (message.sameDimension(standard)) { 60 return message; 61 } else { 62 throw new OrekitException(OrekitMessages.INCOMPATIBLE_UNITS, 63 message.getName(), standard.getName()); 64 } 65 } 66 }, 67 68 /** Enforce strict compliance with CCSDS standard. 69 * <p> 70 * When this behavior is selected having a unit parsed as second 71 * or as meter when CCSDS mandates kilometer will both be refused. 72 * Missing units (i.e. units parsed as {@link Unit#NONE}) are considered 73 * to be standard. 74 * </p> 75 */ 76 STRICT_COMPLIANCE { 77 /** {@inheritDoc} */ 78 @Override 79 public Unit select(final Unit message, final Unit standard) { 80 if (message == Unit.NONE || 81 Precision.equals(message.getScale(), standard.getScale(), 1) && 82 message.sameDimension(standard)) { 83 return standard; 84 } else { 85 throw new OrekitException(OrekitMessages.INCOMPATIBLE_UNITS, 86 message.getName(), standard.getName()); 87 } 88 } 89 }; 90 91 /** Select the unit to use for interpreting parsed value. 92 * @param message unit parsed in the CCSDS message 93 * @param standard unit mandated by the standard 94 * @return selected unit 95 */ 96 public abstract Unit select(Unit message, Unit standard); 97 98 }