BigFractionField.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF 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.  *      https://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. /*
  18.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */

  21. package org.hipparchus.fraction;

  22. import java.io.Serializable;

  23. import org.hipparchus.Field;

  24. /**
  25.  * Representation of the fractional numbers  without any overflow field.
  26.  * <p>
  27.  * This class is a singleton.
  28.  * </p>
  29.  * @see Fraction
  30.  */
  31. public class BigFractionField implements Field<BigFraction>, Serializable  {

  32.     /** Serializable version identifier */
  33.     private static final long serialVersionUID = -1699294557189741703L;

  34.     /** Private constructor for the singleton.
  35.      */
  36.     private BigFractionField() {
  37.     }

  38.     /** Get the unique instance.
  39.      * @return the unique instance
  40.      */
  41.     public static BigFractionField getInstance() {
  42.         return LazyHolder.INSTANCE;
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     public BigFraction getOne() {
  47.         return BigFraction.ONE;
  48.     }

  49.     /** {@inheritDoc} */
  50.     @Override
  51.     public BigFraction getZero() {
  52.         return BigFraction.ZERO;
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public Class<BigFraction> getRuntimeClass() {
  57.         return BigFraction.class;
  58.     }

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     public boolean equals(final Object other) {
  62.         return this == other;
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public int hashCode() {
  67.         return 0x7666e832;
  68.     }

  69.     // CHECKSTYLE: stop HideUtilityClassConstructor
  70.     /** Holder for the instance.
  71.      * <p>We use here the Initialization On Demand Holder Idiom.</p>
  72.      */
  73.     private static class LazyHolder {
  74.         /** Cached field instance. */
  75.         private static final BigFractionField INSTANCE = new BigFractionField();
  76.     }
  77.     // CHECKSTYLE: resume HideUtilityClassConstructor

  78.     /** Handle deserialization of the singleton.
  79.      * @return the singleton instance
  80.      */
  81.     private Object readResolve() {
  82.         // return the singleton instance
  83.         return LazyHolder.INSTANCE;
  84.     }

  85. }