BigRealField.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.  *      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.apache.commons.math4.legacy.linear;

  18. import java.io.Serializable;

  19. import org.apache.commons.math4.legacy.core.Field;
  20. import org.apache.commons.math4.legacy.core.FieldElement;

  21. /**
  22.  * Representation of real numbers with arbitrary precision field.
  23.  * <p>
  24.  * This class is a singleton.
  25.  * </p>
  26.  * @see BigReal
  27.  * @since 2.0
  28.  */
  29. public final class BigRealField implements Field<BigReal>, Serializable  {

  30.     /** Serializable version identifier. */
  31.     private static final long serialVersionUID = 4756431066541037559L;

  32.     /** Private constructor for the singleton.
  33.      */
  34.     private BigRealField() {
  35.     }

  36.     /** Get the unique instance.
  37.      * @return the unique instance
  38.      */
  39.     public static BigRealField getInstance() {
  40.         return LazyHolder.INSTANCE;
  41.     }

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     public BigReal getOne() {
  45.         return BigReal.ONE;
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     public BigReal getZero() {
  50.         return BigReal.ZERO;
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public Class<? extends FieldElement<BigReal>> getRuntimeClass() {
  55.         return BigReal.class;
  56.     }

  57.     // CHECKSTYLE: stop HideUtilityClassConstructor
  58.     /** Holder for the instance.
  59.      * <p>We use here the Initialization On Demand Holder Idiom.</p>
  60.      */
  61.     private static final class LazyHolder {
  62.         /** Cached field instance. */
  63.         private static final BigRealField INSTANCE = new BigRealField();
  64.     }
  65.     // CHECKSTYLE: resume HideUtilityClassConstructor

  66.     /** Handle deserialization of the singleton.
  67.      * @return the singleton instance
  68.      */
  69.     private Object readResolve() {
  70.         // return the singleton instance
  71.         return LazyHolder.INSTANCE;
  72.     }
  73. }