001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.math3.util; 019 020 import java.io.Serializable; 021 022 import org.apache.commons.math3.Field; 023 import org.apache.commons.math3.FieldElement; 024 025 /** 026 * Representation of real numbers with arbitrary precision field. 027 * <p> 028 * This class is a singleton. 029 * </p> 030 * @see BigReal 031 * @version $Id: BigRealField.java 1416643 2012-12-03 19:37:14Z tn $ 032 * @since 2.0 033 */ 034 public class BigRealField implements Field<BigReal>, Serializable { 035 036 /** Serializable version identifier */ 037 private static final long serialVersionUID = 4756431066541037559L; 038 039 /** Private constructor for the singleton. 040 */ 041 private BigRealField() { 042 } 043 044 /** Get the unique instance. 045 * @return the unique instance 046 */ 047 public static BigRealField getInstance() { 048 return LazyHolder.INSTANCE; 049 } 050 051 /** {@inheritDoc} */ 052 public BigReal getOne() { 053 return BigReal.ONE; 054 } 055 056 /** {@inheritDoc} */ 057 public BigReal getZero() { 058 return BigReal.ZERO; 059 } 060 061 /** {@inheritDoc} */ 062 public Class<? extends FieldElement<BigReal>> getRuntimeClass() { 063 return BigReal.class; 064 } 065 066 // CHECKSTYLE: stop HideUtilityClassConstructor 067 /** Holder for the instance. 068 * <p>We use here the Initialization On Demand Holder Idiom.</p> 069 */ 070 private static class LazyHolder { 071 /** Cached field instance. */ 072 private static final BigRealField INSTANCE = new BigRealField(); 073 } 074 // CHECKSTYLE: resume HideUtilityClassConstructor 075 076 /** Handle deserialization of the singleton. 077 * @return the singleton instance 078 */ 079 private Object readResolve() { 080 // return the singleton instance 081 return LazyHolder.INSTANCE; 082 } 083 084 }