View Javadoc
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  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.fraction;
24  
25  import java.io.Serializable;
26  
27  import org.hipparchus.Field;
28  
29  /**
30   * Representation of the fractional numbers field.
31   * <p>
32   * This class is a singleton.
33   * </p>
34   * @see Fraction
35   */
36  public class FractionField implements Field<Fraction>, Serializable  {
37  
38      /** Serializable version identifier */
39      private static final long serialVersionUID = -1257768487499119313L;
40  
41      /** Private constructor for the singleton.
42       */
43      private FractionField() {
44      }
45  
46      /** Get the unique instance.
47       * @return the unique instance
48       */
49      public static FractionField getInstance() {
50          return LazyHolder.INSTANCE;
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public Fraction getOne() {
56          return Fraction.ONE;
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public Fraction getZero() {
62          return Fraction.ZERO;
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public Class<Fraction> getRuntimeClass() {
68          return Fraction.class;
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public boolean equals(final Object other) {
74          return this == other;
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public int hashCode() {
80          return 0xac885ac5;
81      }
82  
83      // CHECKSTYLE: stop HideUtilityClassConstructor
84      /** Holder for the instance.
85       * <p>We use here the Initialization On Demand Holder Idiom.</p>
86       */
87      private static class LazyHolder {
88          /** Cached field instance. */
89          private static final FractionField INSTANCE = new FractionField();
90      }
91      // CHECKSTYLE: resume HideUtilityClassConstructor
92  
93      /** Handle deserialization of the singleton.
94       * @return the singleton instance
95       */
96      private Object readResolve() {
97          // return the singleton instance
98          return LazyHolder.INSTANCE;
99      }
100 
101 }