Token.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.utils.units;

  18. import org.hipparchus.fraction.Fraction;

  19. /** Unit token.
  20.  * @author Luc Maisonobe
  21.  * @since 11.0
  22.  */
  23. class Token {

  24.     /** String value. */
  25.     private final CharSequence subString;

  26.     /** Token type. */
  27.     private final TokenType type;

  28.     /** Integer value. */
  29.     private final int integer;

  30.     /** Fraction value. */
  31.     private final Fraction fraction;

  32.     /** Build a token.
  33.      * @param subString substring corresponding to the token
  34.      * @param type token type
  35.      * @param integer integer value
  36.      * @param fraction fraction value
  37.      */
  38.     Token(final CharSequence subString, final TokenType type, final int integer, final Fraction fraction) {
  39.         this.subString = subString;
  40.         this.type      = type;
  41.         this.integer   = integer;
  42.         this.fraction  = fraction;
  43.     }

  44.     /** Get the substring corresponding to the token.
  45.      * @return substring corresponding to the token
  46.      */
  47.     public CharSequence getSubString() {
  48.         return subString;
  49.     }

  50.     /** Get the token type.
  51.      * @return token type
  52.      */
  53.     public TokenType getType() {
  54.         return type;
  55.     }

  56.     /** Get the integer value (numerator in case of fraction).
  57.      * @return integer value
  58.      */
  59.     public int getInt() {
  60.         return integer;
  61.     }

  62.     /** Get the fraction value.
  63.      * @return fraction value
  64.      */
  65.     public Fraction getFraction() {
  66.         return fraction;
  67.     }

  68. }