1 /*
2 * Licensed to the Hipparchus project 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 Hipparchus project 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 package org.hipparchus.analysis.differentiation;
18
19 import java.io.Serializable;
20
21 import org.hipparchus.Field;
22
23 /** Field for {@link UnivariateDerivative1} instances.
24 * <p>
25 * This class is a singleton.
26 * </p>
27 * @since 1.7
28 */
29 public class UnivariateDerivative1Field implements Field<UnivariateDerivative1>, Serializable {
30
31 /** Serializable version identifier. */
32 private static final long serialVersionUID = 20200519L;
33
34 /** Zero constant. */
35 private final UnivariateDerivative1 zero;
36
37 /** One constant. */
38 private final UnivariateDerivative1 one;
39
40 /** Associated factory for conversions to {@link DerivativeStructure}. */
41 private final DSFactory factory;
42
43 /** Private constructor for the singleton.
44 */
45 private UnivariateDerivative1Field() {
46 zero = new UnivariateDerivative1(0.0, 0.0);
47 one = new UnivariateDerivative1(1.0, 0.0);
48 factory = new DSFactory(1, 1);
49 }
50
51 /** Get the unique instance.
52 * @return the unique instance
53 */
54 public static UnivariateDerivative1Field getInstance() {
55 return LazyHolder.INSTANCE;
56 }
57
58 /** {@inheritDoc} */
59 @Override
60 public UnivariateDerivative1 getOne() {
61 return one;
62 }
63
64 /** {@inheritDoc} */
65 @Override
66 public UnivariateDerivative1 getZero() {
67 return zero;
68 }
69
70 /** Get the factory for converting to {@link DerivativeStructure}.
71 * <p>
72 * This factory is used only for conversions. {@code UnivariateDerivative1} by
73 * itself does not rely at all on {@link DSFactory}, {@link DSCompiler}
74 * or {@link DerivativeStructure} for its computation. For this reason,
75 * the factory here is hidden and this method is package private, so
76 * only {@link UnivariateDerivative1#toDerivativeStructure()} can call it on an
77 * existing {@link UnivariateDerivative1} instance
78 * </p>
79 * @return factory for conversions
80 */
81 DSFactory getConversionFactory() {
82 return factory;
83 }
84
85 /** {@inheritDoc} */
86 @Override
87 public Class<UnivariateDerivative1> getRuntimeClass() {
88 return UnivariateDerivative1.class;
89 }
90
91 /** {@inheritDoc} */
92 @Override
93 public boolean equals(final Object other) {
94 return this == other;
95 }
96
97 /** {@inheritDoc} */
98 @Override
99 public int hashCode() {
100 return 0xd5e174f7;
101 }
102
103 // CHECKSTYLE: stop HideUtilityClassConstructor
104 /** Holder for the instance.
105 * <p>We use here the Initialization On Demand Holder Idiom.</p>
106 */
107 private static class LazyHolder {
108 /** Cached field instance. */
109 private static final UnivariateDerivative1Field INSTANCE = new UnivariateDerivative1Field();
110 }
111 // CHECKSTYLE: resume HideUtilityClassConstructor
112
113 /** Handle deserialization of the singleton.
114 * @return the singleton instance
115 */
116 private Object readResolve() {
117 // return the singleton instance
118 return LazyHolder.INSTANCE;
119 }
120
121 }