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.math.util;
019
020 import java.io.Serializable;
021
022 import org.apache.commons.math.Field;
023
024 /**
025 * Representation of real numbers with arbitrary precision field.
026 * <p>
027 * This class is a singleton.
028 * </p>
029 * @see BigReal
030 * @version $Revision: 811827 $ $Date: 2009-09-06 11:32:50 -0400 (Sun, 06 Sep 2009) $
031 * @since 2.0
032 */
033 public class BigRealField implements Field<BigReal>, Serializable {
034
035 /** Serializable version identifier */
036 private static final long serialVersionUID = 4756431066541037559L;
037
038 /** Private constructor for the singleton.
039 */
040 private BigRealField() {
041 }
042
043 /** Get the unique instance.
044 * @return the unique instance
045 */
046 public static BigRealField getInstance() {
047 return LazyHolder.INSTANCE;
048 }
049
050 /** {@inheritDoc} */
051 public BigReal getOne() {
052 return BigReal.ONE;
053 }
054
055 /** {@inheritDoc} */
056 public BigReal getZero() {
057 return BigReal.ZERO;
058 }
059
060 // CHECKSTYLE: stop HideUtilityClassConstructor
061 /** Holder for the instance.
062 * <p>We use here the Initialization On Demand Holder Idiom.</p>
063 */
064 private static class LazyHolder {
065 /** Cached field instance. */
066 private static final BigRealField INSTANCE = new BigRealField();
067 }
068 // CHECKSTYLE: resume HideUtilityClassConstructor
069
070 /** Handle deserialization of the singleton.
071 * @return the singleton instance
072 */
073 private Object readResolve() {
074 // return the singleton instance
075 return LazyHolder.INSTANCE;
076 }
077
078 }